Created
November 9, 2023 10:57
-
-
Save kenpower/c62d54bce83f611b31d88b20d2818575 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Health{ | |
private: | |
int health; | |
Player& player; | |
public: | |
Health(Player& player) : player(player) {} | |
void change(int amount){ | |
health += amount; | |
if (health > 100) | |
{ | |
health = 100; | |
} | |
if (health < 0) | |
{ | |
health = 0; | |
} | |
if (health < 25) | |
player.speed = SLOW; | |
} | |
}; | |
//... | |
Health health; | |
void takePotion(int potionStrength) | |
{ | |
health.change(potionStrength); | |
} | |
void takeDamage(int damage) | |
{ | |
health.change(-potionStrength); | |
} | |
void fall() | |
{ | |
health.change(-5); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment