Health variable.

Hi Guys.
So, I'm creating a game for college, and it's going.. alright.
I do not understand C++ in any shape or form, so please no criticism as I barely know what I am doing myself, but any help will me immensely appreciated :)
I have a mini fight scene, where players' HP is set to 500 and the enemies, 300. In this fight scene I have a random generator that generates the damage the player deals - the enemies' health points are decreased by this damage. When the enemies' HP are below 300, my enemy flee's.
When the next fight scene happens, the health points are at the number they were left on in the previous fight scene, but I want them to restart back to their original value. Can anyone shed some light on how to do this?

int Goodychoice;
cout << "To select the healing potion - press [1]" << endl;
cout << "To select the anti-stun potion - press [2]" << endl;
cin >> Goodychoice;

if (Goodychoice == 1)
{
cout << "You have selected the healing potion."<< endl;

cout << "\n\n\t\t\t The healing potion heals you by: " << (adventurer.Gethealthpoints()) << " points." << endl;
adventurer.Increase(adventurer.Gethealthpoints());

cout << "Your health is now: " << (adventurer.Gethealth()) << endl;
system("cls");

cout << "The healing potion appears to bring out the inner monster in you.\nYou hit damage of " << damage << " to Lady Pearce." << endl;

cout << "She seems taken back by your supreme strength, allowing you to attack her again.\nYou attack again, damaging " << damage << " to Lady Peace's HP." << endl;
fiend.Decrease(damage);
// Here, the program gets the new level of the fiend before outputting it to the screen.

cout << "Lady Pearce's health is now: " << fiend.GetLevel() << "\n\n" << endl;
system("pause");
}
Last edited on
I'd say that the solution is quite simple: Add a function like ResetHealth() where you set the health variable back to original value, and you call that function before any scene
IntelliSense: member "Players::Resethealth" (declared at line 29) is inaccessible
It still doesn't reset the health, grr :(
Show the code. The class Players and where you use Resethealth(). Note: a function call requires parentheses



Please use code tags: [code]Your code[/code]
See: http://www.cplusplus.com/articles/z13hAqkS/
[code]class Players
{
private:
string Name;
int health;
int damage;
int damage1;
int healthpoints;

public:
Players()
{
health = 500;
healthpoints = 100;
}
public:
void PlayerName(string Playername)
{
Name = Playername;
}

void Decrease(int Amount1)
{
health -= Amount1;
}

void Increase (int Amount1)
{
health += Amount1;
}

int Gethealth()
{
return health;
}

string GetName()
{
return Name;
}

int Gethealthpoints()
{

return healthpoints;
}

int Resethealth()
{

return health;
}


};

if (Goodychoice == 1)
{
adventurer.Resethealth();
cout << "You have selected the healing potion."<< endl;
cout << "\n\t\t\t The healing potion heals you by: " << (adventurer.Gethealthpoints()) << " points." << endl;
adventurer.Increase(adventurer.Gethealthpoints());
cout << "Your health is now: " << (adventurer.Gethealth()) << endl;
system("cls");
cout << "The healing potion appears to bring out the inner monster in you.\nYou hit damage of " << damage << " to Lady Pearce." << endl;
cout << "She seems taken back by your supreme strength, allowing you to attack her again.\nYou attack again, damaging " << damage << " to Lady Pearce's HP." << endl;
fiend.Decrease(damage);
// Here, the program gets the new level of the fiend before outputting it to the screen.
cout << "Lady Pearce's health is now: " << fiend.GetLevel() << "\n\n" << endl;
system("cls");

system("pause");
}
Well, change this:
1
2
3
4
5
int Resethealth()
{

return health;
}
to
1
2
3
4
5
void Resethealth()
{

return health = 500;
}
It still hasn't worked.
Don't worry.
Thanks though. :)
Maybe you want to reset healthpoints too?
Topic archived. No new replies allowed.