I know this may be simple and seem like a dumb question but how can I add health to my adventure and display it. The main problem I am having with it is my teacher wants it in a class. But my program keeps throwing back errors. Below is all I have I tried having cout in there so I could just call the class to display it but it gave me an error.
1 2 3 4 5 6 7 8
class Health
{
public:
int damage = 100;
int healthpoints = 500;
}
You'd want functions that interact with the health in some way. For example:
1 2 3 4
void ReduceHealth(int amount); // lowers health, possibly when damage is dealt
void IncreaseHealth(int amount): // increases health, possibly when healed
void DisplayHealth() // print the current health value
bool IsDead() // true if health is 0 or below
If you have a Health class, you can use it within other classes like Character and Enemy.
Consider excluding Damage from the Health class members. Conceptually speaking, Health is a representation of "aliveness." Damage can be an outside force that influences Health via a Health class function.
The suggestion by EtDecius is sound. The is dead is a function checks to see if health is below the minimum when ReduceeHealth() is called, but given most RPG systems it would be wise to have a function that checks that health is not above the maximum when IncreaseHealth() is called. This ensures that player's cannot continually use health potions or augment to get infinite health.
Sorry I didn't give my code since my project is extremely big at least to me. I forgot to put ask me if you want to put my code. I haven't yet got a chance to try the suggestions but I will soon hopefully it works out.