From e633c8c6d33d7129cc4f3a684e169bffc73204cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1nos?= Date: Wed, 25 Jan 2023 10:26:55 +0100 Subject: [PATCH] refactoring: playerHealth() now uses Char Struct --- src/c/encounter.c | 8 ++++---- src/c/encounter.h | 2 +- test/c/test_encounter.c | 6 ++++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/c/encounter.c b/src/c/encounter.c index 260885d..428273f 100644 --- a/src/c/encounter.c +++ b/src/c/encounter.c @@ -28,9 +28,9 @@ bool playerAlive(int health) } } -int playerHealth(int health, int damage, int armor) +int playerHealth(int health, int damage, int armor, Character* character) { - const int maxhealth = 100; + int maxhealth = getCharacterMaxHealthPoints(character); health = health - damage; if (health > maxhealth) { @@ -87,7 +87,7 @@ int fight(Character *character, enemy* enemy) enemyDamaged(enemy, playerDamage); break; case 'h': - playerH = playerHealth(playerH, -10, playerArmor); + playerH = playerHealth(playerH, -10, playerArmor, character); break; case 'f': return 2; @@ -102,7 +102,7 @@ int fight(Character *character, enemy* enemy) } else { - playerH = playerHealth(playerH, getEnemyDamage(enemy), playerArmor); + playerH = playerHealth(playerH, getEnemyDamage(enemy), playerArmor, character); } } currentTurn = switchTurns(currentTurn); diff --git a/src/c/encounter.h b/src/c/encounter.h index a6c01ac..d0fd484 100644 --- a/src/c/encounter.h +++ b/src/c/encounter.h @@ -12,7 +12,7 @@ typedef struct enemy{ bool playerAlive(int health); -int playerHealth(int health, int damage, int armor); +int playerHealth(int health, int damage, int armor, Character* character); void enemyHeal(enemy *enemy, int healAmount); void enemyDamaged(enemy* enemy, int damage); bool enemyChoosesHeal(enemy* enemy); diff --git a/test/c/test_encounter.c b/test/c/test_encounter.c index 2d205c0..5ed7f3a 100644 --- a/test/c/test_encounter.c +++ b/test/c/test_encounter.c @@ -48,7 +48,8 @@ void test_playerIsDamaged(void) int armor = 0; int expectedHealth = 90; // act - health = playerHealth(health, damage, armor); + Character testChar = {10,10,10,health,100,1,0,100,damage,armor,100}; + health = playerHealth(health, damage, armor, &testChar); // assert TEST_ASSERT_EQUAL(expectedHealth, health); } @@ -61,7 +62,8 @@ void test_playerIsNotOverhealed(void) int heal = -10; int expectedHealth = 100; // act - health = playerHealth(health, heal, armor); + Character testChar = {10,10,10,health,100,1,0,100,10,armor,100}; + health = playerHealth(health, heal, armor, &testChar); // assert TEST_ASSERT_EQUAL(expectedHealth, health); }