From 8994bd77167ddc565971135ef78020f1959799dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1nos?= Date: Fri, 20 Jan 2023 22:24:45 +0100 Subject: [PATCH] Enemies can now heal --- src/c/encounter.c | 6 ++++++ src/c/encounter.h | 1 + test/c/test_encounter.c | 14 ++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/src/c/encounter.c b/src/c/encounter.c index d192259..cdd4c39 100644 --- a/src/c/encounter.c +++ b/src/c/encounter.c @@ -37,6 +37,12 @@ int playerHealth(int health, int damage, int armor) return health; } +void enemyHeal(enemy *enemy, int healAmount) +{ + int currentHealth = getEnemyHealth(enemy); + setEnemyHealth(enemy, currentHealth + healAmount); +} + void enemyDamaged(enemy *enemy, int damage) { int armor = getEnemyArmor(enemy); diff --git a/src/c/encounter.h b/src/c/encounter.h index 4005d70..e70d454 100644 --- a/src/c/encounter.h +++ b/src/c/encounter.h @@ -13,6 +13,7 @@ typedef struct enemy{ bool playerAlive(int health); int playerHealth(int health, int damage, int armor); +void enemyHeal(enemy *enemy, int healAmount); void enemyDamaged(enemy* enemy, int damage); 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 8284076..3cc2cc8 100644 --- a/test/c/test_encounter.c +++ b/test/c/test_encounter.c @@ -263,5 +263,19 @@ void test_randomIntRange(void) TEST_ASSERT_EQUAL_INT(expected, result); } +void test_enemyCanHeal(void) +{ + //arrange + int enemyHealth = 1, enemyDamage = 4, enemyArmor = 4, enemyMaxHealth = 5; + int healAmount= 10, expectedHealth = 11; + int result; + //act + enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyMaxHealth}; + enemyHeal(&test, healAmount); + result = getEnemyHealth(&test); + //assert + TEST_ASSERT_EQUAL(expectedHealth, result); +} + #endif // TEST