diff --git a/src/c/encounter.c b/src/c/encounter.c index bc6887f..955736e 100644 --- a/src/c/encounter.c +++ b/src/c/encounter.c @@ -62,3 +62,9 @@ int getEnemyArmor(enemy enemy){ return enemy.armor; } +int enemyDamaged(enemy enemy, int damage){ + int armor = getEnemyArmor(enemy); + int damagedealt = damage - armor; + enemy.health = enemy.health - damagedealt; + return enemy.health; +} \ No newline at end of file diff --git a/src/c/encounter.h b/src/c/encounter.h index 182aad3..d2b0fba 100644 --- a/src/c/encounter.h +++ b/src/c/encounter.h @@ -23,5 +23,7 @@ int getEnemyDamage(enemy enemy); void *setEnemyArmor(int *num, int damage); int getEnemyArmor(enemy enemy); +int enemyDamaged(enemy enemy, int damage); + #endif \ No newline at end of file diff --git a/test/c/test_encounter.c b/test/c/test_encounter.c index 2954ffa..8bef335 100644 --- a/test/c/test_encounter.c +++ b/test/c/test_encounter.c @@ -84,4 +84,21 @@ void test_get_setEnemyArmor(void){ result = getEnemyArmor(test); TEST_ASSERT_EQUAL(armor, result); } + +void test_PlayerAttacksEnemy_DoesDamage(void) +{ + //arrange + int playerDamage = 10; + int enemyHealth = 50; + int enemyArmor = 4; + //health - (damage - armor) + int expectedEnemyHealth = 44; + //act + enemy test = {enemyHealth, 4, enemyArmor}; + test.health = enemyDamaged(test, playerDamage); + //assert + TEST_ASSERT_EQUAL(expectedEnemyHealth, test.health); +} + + #endif // TEST