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");
}
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
[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");