diff --git a/src/c/encounter.c b/src/c/encounter.c index 326d498..54a5067 100644 --- a/src/c/encounter.c +++ b/src/c/encounter.c @@ -146,7 +146,15 @@ bool enemyChoosesHeal(enemy* enemy) int maxHealth = getEnemyMaxHealth(enemy); int healthd20 = 20 - map(currentHealth, 0, maxHealth, 0, 20); int rolld20 = randomIntRange(1, 20); - return (healthd20 + rolld20) >= 30; + if((healthd20 + rolld20) >= 30 && getEnemyHealPotions(enemy) > 0) + { + setEnemyHealPotions(enemy, getEnemyHealPotions(enemy) - 1); + return true; + } + else + { + return false; + } } // Getter/Setter Funktionen @@ -183,4 +191,14 @@ int getEnemyDamage(enemy* enemy) int getEnemyMaxHealth(enemy* enemy) { return enemy->maxHealth; +} + +int getEnemyHealPotions(enemy* enemy) +{ + return enemy->healPotions; +} + +void setEnemyHealPotions(enemy* enemy, int newPotions) +{ + enemy->healPotions = newPotions; } \ No newline at end of file diff --git a/src/c/encounter.h b/src/c/encounter.h index efc7e61..e5ca6d2 100644 --- a/src/c/encounter.h +++ b/src/c/encounter.h @@ -8,6 +8,7 @@ typedef struct enemy{ int damage; int armor; int maxHealth; + int healPotions; } enemy; @@ -38,4 +39,7 @@ int getEnemyHealth(enemy* enemy); int getEnemyArmor(enemy* enemy); int getEnemyDamage(enemy* enemy); +int getEnemyHealPotions(enemy* enemy); +void setEnemyHealPotions(enemy* enemy, int newPotions); + #endif \ No newline at end of file diff --git a/test/c/test_encounter.c b/test/c/test_encounter.c index a5f08cb..ecca7d9 100644 --- a/test/c/test_encounter.c +++ b/test/c/test_encounter.c @@ -341,7 +341,7 @@ void test_enemyChoosesHeal(void) //arange bool result; int enemyHealth = 50, enemyDamage = 4, enemyArmor = 4, enemyMaxHealth = 100; - enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyMaxHealth}; + enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyMaxHealth, 1}; //act randomInt_ExpectAndReturn(39); //39%20 = 19 , 19 + 1 = 20 result = enemyChoosesHeal(&test); @@ -370,7 +370,7 @@ void test_enemyChoosesHeal_ThenAttackWins(void) int result; int enemyHealth = 6, enemyDamage = 10, enemyArmor = 5, enemyMaxHealth = 100; int playerHealth = 10, playerDamage = 10, playerArmor = 0, playerMaxHealth = 10; - enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyMaxHealth}; + enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyMaxHealth,1 }; //act Character testChar = {10,10,10,playerHealth,100,1,0,100,playerDamage,playerArmor,playerMaxHealth}; playerInputChar_ExpectAndReturn('a'); @@ -383,4 +383,16 @@ void test_enemyChoosesHeal_ThenAttackWins(void) } +void test_enemyHealsNoPotion(void) +{ + int enemyHealth = 6, enemyDamage = 10, enemyArmor = 5, enemyMaxHealth = 100; + enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyMaxHealth, 0}; + + randomInt_ExpectAndReturn(39); //39%20 = 19 , 19 + 1 = 20 + bool result = enemyChoosesHeal(&test); + + TEST_ASSERT_FALSE(result); +} + + #endif // TEST