Browse Source

Added a Function to apply Damage to the enemy

remotes/origin/encounter
János 2 years ago
parent
commit
5cf386590b
  1. 6
      src/c/encounter.c
  2. 2
      src/c/encounter.h
  3. 17
      test/c/test_encounter.c

6
src/c/encounter.c

@ -62,3 +62,9 @@ int getEnemyArmor(enemy enemy){
return enemy.armor; 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;
}

2
src/c/encounter.h

@ -23,5 +23,7 @@ int getEnemyDamage(enemy enemy);
void *setEnemyArmor(int *num, int damage); void *setEnemyArmor(int *num, int damage);
int getEnemyArmor(enemy enemy); int getEnemyArmor(enemy enemy);
int enemyDamaged(enemy enemy, int damage);
#endif #endif

17
test/c/test_encounter.c

@ -84,4 +84,21 @@ void test_get_setEnemyArmor(void){
result = getEnemyArmor(test); result = getEnemyArmor(test);
TEST_ASSERT_EQUAL(armor, result); 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 #endif // TEST
Loading…
Cancel
Save