I am doing some coding in my spare time and trying to make a text based game because I have nothing better to do. I'm having trouble with creating a function in one class that modifies a variable in another class, I'm not 100% sure on how to declare the variable in the other class. I've tried making it a friend and rearranging things but I haven't been able to come up with a solution.
class Player {
private:
string Name;
string gender;
int str;
int spd;
public:
int health = 100; //can be upgraded later in the game
void Gameover() {
if (health == 0) {
cout << "Game over..." << endl;
}
}
void setName(string Pn) {
Name = Pn;
}
void setStr(int Str) {
str = Str;
}
void setGender(string G) {
gender = G;
}
void setSpd(int Spd) {
spd = Spd;
}
void healthupgrd(int health) {
health + 10;
}
};
class Demon { //basic enemy type
private:
string Name = "Demon";
string descr = "Deep black with red lines that creep up and down its back and thighs.";
int LAtkStr = 15; //light attack strength
int HAtkStr = 30; //heavy attack strength
int Player::health;
public:
void HAtk() { //Heavy attack
cout << "The Demon extends claws from its gnarled feet and lashes out in a vicious strike." << endl;
health - HAtkStr;
cout << "Health: " << health << endl;
}
void LAtk() { //Light attack
cout << "The Demon used its clawed fingers to slash your chest" << endl;
health - LAtkStr;
cout << "Health: " << health << endl;
}
};