Ok I fixed the potion bug with your suggestions (and I now understand why the bug was there)
I wrote that:
1 2 3 4 5
|
case '+': //Potion - adds 5 health
if ( Player.getHealth() +5 < Player.getMaxHealth() )
Player.newHealth(+5);
else
Player.setHealth( Player.getMaxHealth() );
|
By the way my
newHealth()
thing uses a signed short as a value, so you can also take away like
Player.newHealth(-5)
(in maths value +- 5, is the same as value - 5)
And I changed
Health
and
MaxHealth
to short instead of unsigned short (just to handle any possible errors)
... and finally
I wrote: |
---|
If the player's health is 5 or 0, suddenly maxhealth becomes 200 instead of 20.
|
doug4 wrote: |
---|
From the code you posted here, I don't know how you know this |
Ummm... maybe because I can see that on the screen, when the program is running? (the exact same code I posted, well... with the potion fix)
You have to compile the code for yourself, so you can see (or possibly, it's due to my computer?)
doug4 wrote: |
---|
I don't see where max health is being set |
It's set to 20 in the constructor.
I know that there's no code that affects maxhealth, so it still confuses me, must be a leak or something somewhere. And I changed the line where the health is displayed to
std::cout << "Health: " << Player.getHealth() << "/" << Player.getMaxHealth() << std::endl;
but that didn't help, maxhealth still becomes 200 when the player's health is 5 or 0.
So there's one more bug to go!