From e318727370cbcc99a84812dfe69f1ccc2c7643eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1nos?= Date: Fri, 13 Jan 2023 19:30:44 +0100 Subject: [PATCH] added a way to not apply negative damage/ only min --- src/c/encounter.c | 3 +++ test/c/test_encounter.c | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/c/encounter.c b/src/c/encounter.c index 955736e..fe37c67 100644 --- a/src/c/encounter.c +++ b/src/c/encounter.c @@ -65,6 +65,9 @@ int getEnemyArmor(enemy enemy){ int enemyDamaged(enemy enemy, int damage){ int armor = getEnemyArmor(enemy); int damagedealt = damage - armor; + if(damagedealt < 1){ + damagedealt = 1; + } enemy.health = enemy.health - damagedealt; return enemy.health; } \ No newline at end of file diff --git a/test/c/test_encounter.c b/test/c/test_encounter.c index 8bef335..1f501ae 100644 --- a/test/c/test_encounter.c +++ b/test/c/test_encounter.c @@ -100,5 +100,18 @@ void test_PlayerAttacksEnemy_DoesDamage(void) TEST_ASSERT_EQUAL(expectedEnemyHealth, test.health); } - +void test_PlayerAttacksEnemy_DoesMinDamage(void) +{ + //arrange + int playerDamage = 10; + int enemyHealth = 50; + int enemyArmor = 10; + //health - (damage - armor) + int expectedEnemyHealth = 49; + //act + enemy test = {enemyHealth, 4, enemyArmor}; + test.health = enemyDamaged(test, playerDamage); + //assert + TEST_ASSERT_EQUAL(expectedEnemyHealth, test.health); +} #endif // TEST