diff --git a/src/c/encounter.c b/src/c/encounter.c index ce999f5..ea86bd0 100644 --- a/src/c/encounter.c +++ b/src/c/encounter.c @@ -28,7 +28,18 @@ bool playerAlive(int health) } } -int playerHealth(int health, int damage, int armor, Character* character) +int playerHeal(int health, int damage, int armor, Character* character) +{ + int maxhealth = getCharacterMaxHealthPoints(character); + health = health - damage; + if (health > maxhealth) + { + health = maxhealth; + } + return health; +} + +int playerDamaged(int health, int damage, int armor, Character* character) { int maxhealth = getCharacterMaxHealthPoints(character); health = health - damage; @@ -85,7 +96,7 @@ int fight(Character *character, enemy* enemy) enemyDamaged(enemy, getCharacterAttack(character)); break; case 'h': - playerH = playerHealth(getCharacterHealthPoints(character), -10, getCharacterArmor(character), character); + playerH = playerHeal(getCharacterHealthPoints(character), -10, getCharacterArmor(character), character); setCharacterHealthPoints(character, playerH); break; case 'f': @@ -101,7 +112,7 @@ int fight(Character *character, enemy* enemy) } else { - playerH = playerHealth(getCharacterHealthPoints(character), getEnemyDamage(enemy), getCharacterArmor(character), character); + playerH = playerDamaged(getCharacterHealthPoints(character), getEnemyDamage(enemy), getCharacterArmor(character), character); setCharacterHealthPoints(character, playerH); } } diff --git a/src/c/encounter.h b/src/c/encounter.h index d0fd484..59b94f9 100644 --- a/src/c/encounter.h +++ b/src/c/encounter.h @@ -12,7 +12,8 @@ typedef struct enemy{ bool playerAlive(int health); -int playerHealth(int health, int damage, int armor, Character* character); +int playerHeals(int health, int damage, int armor, Character* character); +int playerDamaged(int health, int damage, int armor, Character* character); void enemyHeal(enemy *enemy, int healAmount); void enemyDamaged(enemy* enemy, int damage); bool enemyChoosesHeal(enemy* enemy); diff --git a/test/c/test_encounter.c b/test/c/test_encounter.c index 5ed7f3a..e4229b8 100644 --- a/test/c/test_encounter.c +++ b/test/c/test_encounter.c @@ -49,7 +49,7 @@ void test_playerIsDamaged(void) int expectedHealth = 90; // act Character testChar = {10,10,10,health,100,1,0,100,damage,armor,100}; - health = playerHealth(health, damage, armor, &testChar); + health = playerDamaged(health, damage, armor, &testChar); // assert TEST_ASSERT_EQUAL(expectedHealth, health); } @@ -63,7 +63,7 @@ void test_playerIsNotOverhealed(void) int expectedHealth = 100; // act Character testChar = {10,10,10,health,100,1,0,100,10,armor,100}; - health = playerHealth(health, heal, armor, &testChar); + health = playerHeal(health, heal, armor, &testChar); // assert TEST_ASSERT_EQUAL(expectedHealth, health); }