I've been working on some class testing to get back into C++, so I was once again trying to do things in a game-like way.
I created the following code:
#include <iostream>
using namespace std;
//----------Class Player----------
class Player
{
protected:
int Health, Damage;
public:
Player() { set(100, 10); }
Player(int one, int two) { set(one, two); }
int getHealth() { return Health; }
int getDamage() { return Damage; }
void set(int newHealth, int newDamage) { Health = newHealth; Damage = newDamage; }
void Attack(Monster enemy);
};
//----------Class Monster----------
class Monster
{
protected:
int Health, Damage;
public:
Monster() { set(100, 10); }
Monster(int one, int two) { set(one, two); }
int getHealth() { return Health; }
int getDamage() { return Damage; }
void set(int newHealth, int newDamage) { Health = newHealth; Damage = newDamage; }
};
//----------Test Function Prototypes----------
void TestPlayerFunctionality();
void TestMonsterFunctionality();
void TestAttackFunction();
//----------Main Function----------
int main()
{
TestPlayerFunctionality();
TestMonsterFunctionality();
//TestAttackFunction();
system("pause");
return 0;
}
//----------Player Class Functions----------
void Attack(Monster enemy)
{
enemy.set(enemy.getHealth() - Damage, enemy.getDamage());
cout << "After you attack, the enemy's health is " << enemy.getHealth() << "\n";
}
//----------Test Functions----------
void TestPlayerFunctionality()
{
Player *you = new Player(120, 15);
cout << "Your health is " << you->getHealth() << "\n";
cout << "Your damage is " << you->getDamage() << "\n";
delete you;
}
void TestMonsterFunctionality()
{
Monster *baddy = new Monster(20, 3);
cout << "Monster's health is " << baddy->getHealth() << "\n";
cout << "Monster's damage is " << baddy->getDamage() << "\n";
delete baddy;
}
void TestAttackFunction()
{
Player *you = new Player(120, 20);
Monster *baddy = new Monster(100, 15);
you->Attack(baddy);
delete you;
delete baddy;
}
and just about everything works (although I commented out the TestAttackFunction() test to be worked on later.
Upon compiling the code I have there, I receive the following errors:
Line 16: "syntax error : identifier Monster"
Line 51: " 'Damage' : undeclared identifier"
Line 76: "Player::Attack function does not take 1 argument"
I've revisited the Monster class, and it seems to be fine to me.
The Damage variable IS obviously declared within either class (including the Player class which the function refers).
The Player::Attack function does indeed take one argument, this makes no sense.
I was using references, such as "void Attack(Monster const &enemy);" but doing so brought up even more, less understandable errors.
Can anyone figure out what's going on here, because it is totally eluding me.