![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Ah... Game Programming All In One... the code in that book has so many errors it's unbelievable. I just ditched it (waste of £40) and bought a decent book instead.
|
|
|
|
|
|
#12 |
|
Newbie
Join Date: Feb 2005
Posts: 25
Rep Power: 0
![]() |
What o_O?
|
|
|
|
|
|
#13 |
|
Newbie
Join Date: Feb 2005
Posts: 25
Rep Power: 0
![]() |
This is what happens when I do as you say:
D:\PROJEKTET\game\game\player.cpp(470) : error C2064: term does not evaluate to a function D:\PROJEKTET\game\game\player.cpp(473) : error C2064: term does not evaluate to a function D:\PROJEKTET\game\game\player.cpp(498) : error C2064: term does not evaluate to a function D:\PROJEKTET\game\game\player.cpp(501) : error C2064: term does not evaluate to a function D:\PROJEKTET\game\game\player.cpp(513) : error C2143: syntax error : missing ';' before ']' D:\PROJEKTET\game\game\player.cpp(530) : error C2143: syntax error : missing ';' before '}' D:\PROJEKTET\game\game\player.cpp(530) : error C2143: syntax error : missing ';' before '}' D:\PROJEKTET\game\game\player.cpp(530) : error C2143: syntax error : missing ';' before '}' And I can't see a single ";" that is missing anywhere... d:\projektet\game\game\player.h(19) : error C2061: syntax error : identifier 'monster' player.cpp and one of those beauties... |
|
|
|
|
|
#14 |
|
Newbie
Join Date: Jan 2005
Posts: 20
Rep Power: 0
![]() |
I have made some changes to the code (in red). It's now reduced to 1 error:
error C2061: syntax error : identifier 'monster' You need to add a function to Monster.h: int get_bonus_damage(); And Monster.cpp: int get_bonus_damage() { return bonus_damage; } #include <iostream>
#include "player.h"
#include <time.h>
#include "monster.h"
using namespace std;
#define COLOR_OFF 8
#define COLOR_RED 12
#define COLOR_YELLOW 14
#define COLOR_WHITE 15
#define COLOR_GREEN 10
#define COLOR_CYAN 11
HANDLE Color;
player::player()
{
this->strength = 0;
this->agility = 0;
this->constitution = 0;
this->gold = 0;
this->exp = 0;
this->armor = 0;
this->bonus_damage = 0;
this->item_bonus_damage = 0;
this->item_bonus_armor = 0;
this->item_bonus_max_health = 0;
this->health = 0;
this->max_health = 0;
}
player::~player()
{
}
void player::set_strength (unsigned int strength)
{
this->strength = strength;
this->update_stats();
}
void player::set_agility (unsigned int agility)
{
this->agility = agility;
this->update_stats();
}
void player::set_constitution (unsigned int constitution)
{
this->constitution = constitution;
this->update_stats();
}
void player::set_gold (unsigned int gold)
{
this->gold = gold;
}
void player::set_exp (unsigned int exp)
{
this->exp = exp;
}
void player::set_name (string name)
{
this->name = name;
}
void player::set_bonus_damage (int bonus_damage)
{
this->bonus_damage = bonus_damage;
}
void player::set_item_bonus_damage (int item_bonus_damage)
{
this->item_bonus_damage = item_bonus_damage;
}
void player::set_item_bonus_armor (int item_bonus_armor)
{
this->item_bonus_armor = item_bonus_armor;
}
void player::set_item_bonus_max_health (int item_bonus_max_health)
{
this->item_bonus_max_health = item_bonus_max_health;
}
void player::set_health (int health)
{
this->health = health;
}
unsigned int player::get_strength ()
{
return this->strength;
}
unsigned int player::get_agility ()
{
return this->agility;
}
unsigned int player::get_constitution ()
{
return this->constitution;
}
unsigned int player::get_gold ()
{
return this->gold;
}
unsigned int player::get_exp ()
{
return this->exp;
}
unsigned int player::get_armor ()
{
return this->armor;
}
unsigned int player::get_health ()
{
return this->health;
}
unsigned int player::get_bonus_damage ()
{
return this->bonus_damage;
}
unsigned int player::get_item_bonus_damage ()
{
return this->item_bonus_damage;
}
unsigned int player::get_item_bonus_armor ()
{
return this->item_bonus_armor;
}
unsigned int player::get_item_bonus_max_health ()
{
return this->item_bonus_max_health;
}
unsigned int player::get_max_health ()
{
return this->max_health;
}
string player::get_name ()
{
return this->name;
}
void player::set_stats (int base, int max_rnd, int points)
{
int c;
srand(time(NULL));
c = (rand() % max_rnd) + 1;
if(c > points)
c = points;
this->strength = base + c;
points = points - c;
c = (rand() % max_rnd) + 1;
if(c > points)
c = points;
this->agility = base + c;
points = points - c;
c = (rand() % max_rnd) + 1;
if(c > points)
c = points;
this->constitution = base + c;
points = points - c;
this->gold = 24 + ((rand() % 26) + 1);
this->update_stats();
this->health = this->max_health;
}
void player::text_dump ()
{
cout << endl;
cout << "Statistics:" << endl;
cout << "Strength = " << this->strength << endl;
cout << "Agility = " << this->agility << endl;
cout << "Constitution = " << this->constitution << endl;
cout << "Health = " << this->health << "/" << this->max_health << endl;
cout << "Armor = " << this->armor << endl;
cout << "Bonus damage = " << this->bonus_damage << endl;
cout << "Gold = " << this->gold << endl;
cout << "Experience = " << this->exp << endl;
}
void player::update_stats()
{
this->max_health = this->constitution * 3 + this->strength * 1 + this->item_bonus_max_health;
this->armor = this->agility / 8 + this->constitution / 12 + this->item_bonus_armor;
this->bonus_damage = this->strength / 8 + this->agility / 12 + this->item_bonus_damage;
}
int player::roll(int dice, int size)
{
srand(time(NULL));
int n = 0;
int i;
for(i = 0; i < dice; i++){
n = n + ((rand() % size) + 1);
}
return n;
}
void player::temple()
{
int pre_health = this->health;
cout << "\nWelcome my child, take a while and rest, and I'll take care of your scars." << endl;
Sleep(1000);
this->health = this->max_health;
int post_health = this->health;
int heal = post_health - pre_health;
cout << "\nYou have been healed by the Cleric for " << heal << " health!" << endl;
}
void player::shop()
{
string shop;
Color = GetStdHandle(STD_OUTPUT_HANDLE);
Sleep(1000);
cout << "\nYarrr, matey! Welcome to the Arena General Store." << endl;
cout << "Here you can purchase all the items you need for a wee price, have a look: " << endl;
for( ; ; ){
cout << endl;
cout << "\t(";
SetConsoleTextAttribute(Color, COLOR_YELLOW);
cout << "W";
SetConsoleTextAttribute(Color, COLOR_OFF);
cout << ")eapon Upgrade - 50 gold" << endl;
cout << "\t(";
SetConsoleTextAttribute(Color, COLOR_YELLOW);
cout << "A";
SetConsoleTextAttribute(Color, COLOR_OFF);
cout << ")rmor Upgrade - 50 gold" << endl;
cout << endl;
cout << "\tPotion: (";
SetConsoleTextAttribute(Color, COLOR_YELLOW);
cout << "E";
SetConsoleTextAttribute(Color, COLOR_OFF);
cout << ")ase Wounds [";
SetConsoleTextAttribute(Color, COLOR_YELLOW);
cout << "Max Health";
SetConsoleTextAttribute(Color, COLOR_OFF);
cout << "] - 35 gold" << endl;
cout << "\tPotion: (";
SetConsoleTextAttribute(Color, COLOR_YELLOW);
cout << "T";
SetConsoleTextAttribute(Color, COLOR_OFF);
cout << ")iger Balm [";
SetConsoleTextAttribute(Color, COLOR_YELLOW);
cout << "Agility";
SetConsoleTextAttribute(Color, COLOR_OFF);
cout << "] - 35 gold" << endl;
cout << "\tPotion: (";
SetConsoleTextAttribute(Color, COLOR_YELLOW);
cout << "M";
SetConsoleTextAttribute(Color, COLOR_OFF);
cout << ")uscle Stimulator [";
SetConsoleTextAttribute(Color, COLOR_YELLOW);
cout << "Strength";
SetConsoleTextAttribute(Color, COLOR_OFF);
cout << "] - 35 gold" << endl;
cout << "\tPotion: (";
SetConsoleTextAttribute(Color, COLOR_YELLOW);
cout << "H";
SetConsoleTextAttribute(Color, COLOR_OFF);
cout << ")arden Skin [";
SetConsoleTextAttribute(Color, COLOR_YELLOW);
cout << "Constitution";
SetConsoleTextAttribute(Color, COLOR_OFF);
cout << "] - 35 gold" << endl;
cout << endl;
SetConsoleTextAttribute(Color, COLOR_YELLOW);
cout << "\tYour gold: " << this->gold << endl;
SetConsoleTextAttribute(Color, COLOR_OFF);
cout << endl;
cout << "Enter the letter within the parenthesis' of the item of your desire to buy it." << endl;
cout << "Type 'leave' to exit the store." << endl;
cout << endl;
SetConsoleTextAttribute(Color, COLOR_RED);
cout << this->get_health() << "hp> ";
SetConsoleTextAttribute(Color, COLOR_WHITE);
cin >> shop;
SetConsoleTextAttribute(Color, COLOR_OFF);
if(shop == "A" || shop == "a"){
if(this->gold >= 50){
this->gold = this->gold - 50;
this->item_bonus_armor = this->item_bonus_armor + 1;
cout << "\nYou have purchased an Armor Upgrade for 50 gold!" << endl;
}
else{
cout << "\nYou don't have enough gold for that, matey!" << endl;
}
}
if(shop == "W" || shop == "w"){
if(this->gold >= 50){
this->gold = this->gold - 50;
this->item_bonus_damage = this->item_bonus_damage + 1;
cout << "\nYou have purchased a Weapon Upgrade for 50 gold!" << endl;
}
else{
cout << "\nYou don't have enough gold for that, matey!" << endl;
}
}
if(shop == "M" || shop == "m"){
if(this->gold >= 35){
this->gold = this->gold - 35;
this->strength = this->strength + 3;
cout << "\nYou have purchased a Muscle Stimulator for 35 gold!" << endl;
}
else{
cout << "\nYou don't have enough gold for that, matey!" << endl;
}
}
if(shop == "H" || shop == "h"){
if(this->gold >= 35){
this->gold = this->gold - 35;
this->constitution = this->constitution + 3;
cout << "\nYou have purchased a Potion: Harden Skin for 35 gold!" << endl;
}
else{
cout << "\nYou don't have enough gold for that, matey!" << endl;
}
}
if(shop == "T" || shop == "t"){
if(this->gold >= 35){
this->gold = this->gold - 35;
this->agility = this->agility + 2;
cout << "\nYou have purchased a Potion: Tiger Balm for 35 gold!" << endl;
}
else{
cout << "\nYou don't have enough gold for that, matey!" << endl;
}
}
if(shop == "E" || shop == "e"){
if(this->gold >= 35){
this->gold = this->gold - 35;
this->item_bonus_max_health = this->item_bonus_max_health + 15 ;
cout << "\nYou have purchased a Potion: Ease Wounds for 35 gold!" << endl;
}
else{
cout << "\nYou don't have enough gold for that, matey!" << endl;
}
}
if(shop == "leave" || shop == "Leave"){
break;
cout << endl;
}
this->update_stats();
}
}
int player::fight(monster *m)
{
int ph_chance;
int mh_chance;
int md_chance;
int pd_chance;
int p_damage;
int m_damage;
int roll;
int f_damage;
for( ; ; ){
Sleep(1000);
ph_chance = this->get_agility() * 3;
pd_chance = this->get_agility();
p_damage = this->roll(1, 6);
p_damage = p_damage + this->get_bonus_damage();
mh_chance = m->->get_agility() * 3;
md_chance = m->->get_agility();
m_damage = m->roll(1, 6);
m_damage = m_damage + m->->get_bonus_damage();
roll = m->roll(1, 100);
if(roll <= ph_chance){
roll = m->roll(1, 100);
if(roll <= md_chance){
cout << "The " << m->get_name() << " dodges your attack. " << endl;
}
else{
f_damage = p_damage - m->get_armor();
cout << "You hit the " << m->get_name() << " for " << f_damage << " damage." << endl;
m->set_health(m->get_health() - f_damage);
if(m->get_health() <= 0){
cout << "You have perished the " << m->get_name() << "." << endl;
cout << "You gain " << m->get_exp() << " experience points." << endl;
cout << "You gain " << m->get_gold() << " gold." << endl;
this->gold = this->gold + m->get_gold();
this->exp = this->exp + m->get_exp();
delete m;
return 1;
}
}
}
else {
cout << "You miss the " << m->get_name() << "." << endl;
}
roll = m->roll(1, 100);
if(roll <= mh_chance){
roll = m->roll(1, 100);
if(roll <= pd_chance){
cout << "You dodge the " << m->get_name() << "'s attack." << endl;
}
else{
f_damage = m_damage - this->get_armor();
cout << "The " << m->get_name() << " hits you for " << f_damage << " damage." << endl;
this->health = this->health - f_damage;
if(this->health <= 0){
cout << "You have been slain by the " << m->get_name() << "." << endl;
return 0;
// ]
}
}
}
else{
cout << "The " << m->get_name() << " misses you." << endl;
}
cout << "[" << this->name << " HP: " << this->health << "\t" << m->get_name() << " HP: " << m->get_health() << "]" << endl;
}
}
//} |
|
|
|
|
|
#15 |
|
Newbie
Join Date: Jan 2005
Posts: 20
Rep Power: 0
![]() |
Last compiler error: remove the #include "player.h" in monster.h
You also need to implement the set_health(int) and get_armor() functions in Monster.cpp |
|
|
|
|
|
#16 |
|
Newbie
Join Date: Feb 2005
Posts: 25
Rep Power: 0
![]() |
Fixed it earlier, programming running perfectly now...
Quite good to have a brother that's a prodigy at these things :p Took him <5 minutes to fix everything in the code, but I don't remember changing the item_bonus_damage thing. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|