diff --git a/src/c/encounter.c b/src/c/encounter.c index d3b14e6..2e9e547 100644 --- a/src/c/encounter.c +++ b/src/c/encounter.c @@ -112,11 +112,20 @@ int randomIntRange(int min, int max) } -int map(int x, int in_min, int in_max, int out_min, int out_max){ +int map(int x, int in_min, int in_max, int out_min, int out_max) +{ //vgl Arduino map() https://www.arduino.cc/reference/en/language/functions/math/map/ return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; } +bool enemyChoosesHeal(enemy* enemy) +{ + int currentHealth = getEnemyHealth(enemy); + int maxHealth = getEnemyMaxHealth(enemy); + int healthd20 = map(currentHealth, 0, maxHealth, 0, 20); + return healthd20 <= 10; +} + // Getter/Setter Funktionen void setEnemyHealth(enemy* enemy, int newhealth) { diff --git a/src/c/encounter.h b/src/c/encounter.h index e2070d5..312f35a 100644 --- a/src/c/encounter.h +++ b/src/c/encounter.h @@ -15,6 +15,7 @@ bool playerAlive(int health); int playerHealth(int health, int damage, int armor); void enemyHeal(enemy *enemy, int healAmount); void enemyDamaged(enemy* enemy, int damage); +bool enemyChoosesHeal(enemy* enemy); int switchTurns(int currentTurn); int fight(int playerH, int playerDamage, int playerArmor, int playerAttack, enemy* enemy); diff --git a/test/c/test_encounter.c b/test/c/test_encounter.c index 6e4a30d..c4246de 100644 --- a/test/c/test_encounter.c +++ b/test/c/test_encounter.c @@ -323,4 +323,17 @@ void test_map10(){ TEST_ASSERT_EQUAL(expected3, result); } +void test_enemyChoosesHeal(void) +{ + //arange + bool result; + int enemyHealth = 50, enemyDamage = 4, enemyArmor = 4, enemyMaxHealth = 100; + enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyMaxHealth}; + //act + result = enemyChoosesHeal(&test); + //assert + TEST_ASSERT_TRUE(result); + +} + #endif // TEST