Browse Source

added a way to not apply negative damage/ only min

remotes/origin/encounter
János 2 years ago
parent
commit
e318727370
  1. 3
      src/c/encounter.c
  2. 15
      test/c/test_encounter.c

3
src/c/encounter.c

@ -65,6 +65,9 @@ int getEnemyArmor(enemy enemy){
int enemyDamaged(enemy enemy, int damage){ int enemyDamaged(enemy enemy, int damage){
int armor = getEnemyArmor(enemy); int armor = getEnemyArmor(enemy);
int damagedealt = damage - armor; int damagedealt = damage - armor;
if(damagedealt < 1){
damagedealt = 1;
}
enemy.health = enemy.health - damagedealt; enemy.health = enemy.health - damagedealt;
return enemy.health; return enemy.health;
} }

15
test/c/test_encounter.c

@ -100,5 +100,18 @@ void test_PlayerAttacksEnemy_DoesDamage(void)
TEST_ASSERT_EQUAL(expectedEnemyHealth, test.health); 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 #endif // TEST
Loading…
Cancel
Save