From 457e8b5b3c0b945d06237fec069f033bef2d747b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1nos?= Date: Mon, 23 Jan 2023 13:55:30 +0100 Subject: [PATCH] Function to make Enemy Heal --- src/c/encounter.c | 11 ++++++++++- src/c/encounter.h | 1 + test/c/test_encounter.c | 13 +++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) 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