diff --git a/src/c/encounter.c b/src/c/encounter.c index ea86bd0..326d498 100644 --- a/src/c/encounter.c +++ b/src/c/encounter.c @@ -28,10 +28,10 @@ bool playerAlive(int health) } } -int playerHeal(int health, int damage, int armor, Character* character) +int playerHeal(int health, int damage, Character* character) { int maxhealth = getCharacterMaxHealthPoints(character); - health = health - damage; + health = health + damage; if (health > maxhealth) { health = maxhealth; @@ -41,13 +41,12 @@ int playerHeal(int health, int damage, int armor, Character* character) int playerDamaged(int health, int damage, int armor, Character* character) { - int maxhealth = getCharacterMaxHealthPoints(character); - health = health - damage; - if (health > maxhealth) + int damagedealt = damage - armor; + if (damagedealt < 1) { - health = maxhealth; + damagedealt = 1; } - return health; + return health - damagedealt; } void enemyHeal(enemy *enemy, int healAmount) @@ -96,7 +95,7 @@ int fight(Character *character, enemy* enemy) enemyDamaged(enemy, getCharacterAttack(character)); break; case 'h': - playerH = playerHeal(getCharacterHealthPoints(character), -10, getCharacterArmor(character), character); + playerH = playerHeal(getCharacterHealthPoints(character), 10, character); setCharacterHealthPoints(character, playerH); break; case 'f': diff --git a/src/c/encounter.h b/src/c/encounter.h index 59b94f9..efc7e61 100644 --- a/src/c/encounter.h +++ b/src/c/encounter.h @@ -12,7 +12,7 @@ typedef struct enemy{ bool playerAlive(int health); -int playerHeals(int health, int damage, int armor, Character* character); +int playerHeal(int health, int damage, Character* character); int playerDamaged(int health, int damage, int armor, Character* character); void enemyHeal(enemy *enemy, int healAmount); void enemyDamaged(enemy* enemy, int damage); diff --git a/test/c/test_encounter.c b/test/c/test_encounter.c index e4229b8..a5f08cb 100644 --- a/test/c/test_encounter.c +++ b/test/c/test_encounter.c @@ -57,13 +57,13 @@ void test_playerIsDamaged(void) void test_playerIsNotOverhealed(void) { // arrange - int health = 100; + int health = 95; int armor = 0; - int heal = -10; + int heal = 10; int expectedHealth = 100; // act Character testChar = {10,10,10,health,100,1,0,100,10,armor,100}; - health = playerHeal(health, heal, armor, &testChar); + health = playerHeal(health, heal, &testChar); // assert TEST_ASSERT_EQUAL(expectedHealth, health); } @@ -369,7 +369,7 @@ void test_enemyChoosesHeal_ThenAttackWins(void) //arange int result; int enemyHealth = 6, enemyDamage = 10, enemyArmor = 5, enemyMaxHealth = 100; - int playerHealth = 10, playerDamage = 10, playerArmor = 5, playerMaxHealth = 10; + int playerHealth = 10, playerDamage = 10, playerArmor = 0, playerMaxHealth = 10; enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyMaxHealth}; //act Character testChar = {10,10,10,playerHealth,100,1,0,100,playerDamage,playerArmor,playerMaxHealth};