Browse Source

Enemies can now heal

remotes/origin/encounter
János 2 years ago
parent
commit
8994bd7716
  1. 6
      src/c/encounter.c
  2. 1
      src/c/encounter.h
  3. 14
      test/c/test_encounter.c

6
src/c/encounter.c

@ -37,6 +37,12 @@ int playerHealth(int health, int damage, int armor)
return health;
}
void enemyHeal(enemy *enemy, int healAmount)
{
int currentHealth = getEnemyHealth(enemy);
setEnemyHealth(enemy, currentHealth + healAmount);
}
void enemyDamaged(enemy *enemy, int damage)
{
int armor = getEnemyArmor(enemy);

1
src/c/encounter.h

@ -13,6 +13,7 @@ typedef struct enemy{
bool playerAlive(int health);
int playerHealth(int health, int damage, int armor);
void enemyHeal(enemy *enemy, int healAmount);
void enemyDamaged(enemy* enemy, int damage);
int switchTurns(int currentTurn);
int fight(int playerH, int playerDamage, int playerArmor, int playerAttack, enemy* enemy);

14
test/c/test_encounter.c

@ -263,5 +263,19 @@ void test_randomIntRange(void)
TEST_ASSERT_EQUAL_INT(expected, result);
}
void test_enemyCanHeal(void)
{
//arrange
int enemyHealth = 1, enemyDamage = 4, enemyArmor = 4, enemyMaxHealth = 5;
int healAmount= 10, expectedHealth = 11;
int result;
//act
enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyMaxHealth};
enemyHeal(&test, healAmount);
result = getEnemyHealth(&test);
//assert
TEST_ASSERT_EQUAL(expectedHealth, result);
}
#endif // TEST
Loading…
Cancel
Save