From 7780e81c619548f611e39267a83a4c5fa9725282 Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Thu, 26 Jan 2023 12:58:26 +0100 Subject: [PATCH] refactoring: changed playerDamaged Parameters and Unittest setup to resemble the changes --- src/c/encounter.c | 8 ++++---- src/c/encounter.h | 2 +- test/c/test_encounter.c | 10 ++++------ 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/c/encounter.c b/src/c/encounter.c index 8c820f7..a1d13b1 100644 --- a/src/c/encounter.c +++ b/src/c/encounter.c @@ -39,14 +39,14 @@ int playerHeal(Character* character, int amount) return getCharacterHealthPoints(character); } -int playerDamaged(int health, int damage, int armor, Character* character) +int playerDamaged(enemy* enemy, Character* character) { - int damagedealt = damage - armor; + int damagedealt = getEnemyDamage(enemy) - getCharacterArmor(character); if (damagedealt < 1) { damagedealt = 1; } - return health - damagedealt; + return getCharacterHealthPoints(character) - damagedealt; } void enemyHeal(enemy *enemy, int healAmount) @@ -111,7 +111,7 @@ int fight(Character *character, enemy* enemy) } else { - playerH = playerDamaged(getCharacterHealthPoints(character), getEnemyDamage(enemy), getCharacterArmor(character), character); + playerH = playerDamaged(enemy, character); setCharacterHealthPoints(character, playerH); } } diff --git a/src/c/encounter.h b/src/c/encounter.h index 4ae48ae..413ed6e 100644 --- a/src/c/encounter.h +++ b/src/c/encounter.h @@ -16,7 +16,7 @@ typedef struct enemy{ bool playerAlive(Character *character); int playerHeal(Character* character,int amount); -int playerDamaged(int health, int damage, int armor, Character* character); +int playerDamaged(enemy* enemy, Character* character); int rollInitiative (Character *character); void enemyHeal(enemy *enemy, int healAmount); void enemyDamaged(enemy* enemy, int damage); diff --git a/test/c/test_encounter.c b/test/c/test_encounter.c index 3c33f55..9e171a0 100644 --- a/test/c/test_encounter.c +++ b/test/c/test_encounter.c @@ -10,11 +10,14 @@ #include "utils.h" Character testcharacter; +enemy testenemy; void setUp(void) { testcharacter.dexterity = 5; testcharacter.healthPoints = 100; testcharacter.maxHealthPoints = 100; + + testenemy.damage = 10; } void teardown(void) @@ -47,15 +50,10 @@ void test_isPlayerAlive_healthLowerZero(void) void test_playerIsDamaged(void) { // arrange - int health = 100; - int damage = 10; - int armor = 0; int expectedHealth = 90; // act - Character testChar = {10,10,10,health,100,1,0,100,damage,armor,100}; - health = playerDamaged(health, damage, armor, &testChar); // assert - TEST_ASSERT_EQUAL(expectedHealth, health); + TEST_ASSERT_EQUAL(expectedHealth, playerDamaged(&testenemy, &testcharacter)); } void test_playerIsNotOverhealed(void)