shadowsilver
Programmer
I have taught myself C++ and have quite a bit of experience, but I am just now getting to understand classes. I am writing a simple two-player turn-based game
and have decided to use classes to make it easier. I have already made part of it, but I have a question about using member functions.
I plan on having it like this:
struct Player {
int Def, Att, Hp;
void UseSpec();
};
Player one,two;
One player, depending on what type they were would have a special attack they could use, and it would be defined like this:
void Player::FactionOneSpec()
{
Hp+=50;
}
So that I could call the FactionOneSpec for either player instead of having to write two different versions for each player, eg. if I did, to add 50 to one.Hp or two.Hp, depending on which player used the special.
But my question is how I could have it take away from the enemy's health AND add to your own health in the same function.
Like:
void Player::FactionOneSpec()
{
Hp += 50;
enemyHp -= 50;
}
How would I do that? I know the Hp would apply to the Player instance that called it, but how could I make the enemy's Hp be used too, and still be able to call with either Player? Or should I just put both player's info in one class?
Any suggestions would be extremely helpful. Please!
And by the way, I would search for this, I don't know what I should search for!
and have decided to use classes to make it easier. I have already made part of it, but I have a question about using member functions.
I plan on having it like this:
struct Player {
int Def, Att, Hp;
void UseSpec();
};
Player one,two;
One player, depending on what type they were would have a special attack they could use, and it would be defined like this:
void Player::FactionOneSpec()
{
Hp+=50;
}
So that I could call the FactionOneSpec for either player instead of having to write two different versions for each player, eg. if I did, to add 50 to one.Hp or two.Hp, depending on which player used the special.
But my question is how I could have it take away from the enemy's health AND add to your own health in the same function.
Like:
void Player::FactionOneSpec()
{
Hp += 50;
enemyHp -= 50;
}
How would I do that? I know the Hp would apply to the Player instance that called it, but how could I make the enemy's Hp be used too, and still be able to call with either Player? Or should I just put both player's info in one class?
Any suggestions would be extremely helpful. Please!
And by the way, I would search for this, I don't know what I should search for!