Browse Source

refactoring: Split play Heal/Damage

remotes/origin/encIntegration
János 2 years ago
parent
commit
b2c7caa08b
  1. 17
      src/c/encounter.c
  2. 3
      src/c/encounter.h
  3. 4
      test/c/test_encounter.c

17
src/c/encounter.c

@ -28,7 +28,18 @@ bool playerAlive(int health)
}
}
int playerHealth(int health, int damage, int armor, Character* character)
int playerHeal(int health, int damage, int armor, Character* character)
{
int maxhealth = getCharacterMaxHealthPoints(character);
health = health - damage;
if (health > maxhealth)
{
health = maxhealth;
}
return health;
}
int playerDamaged(int health, int damage, int armor, Character* character)
{
int maxhealth = getCharacterMaxHealthPoints(character);
health = health - damage;
@ -85,7 +96,7 @@ int fight(Character *character, enemy* enemy)
enemyDamaged(enemy, getCharacterAttack(character));
break;
case 'h':
playerH = playerHealth(getCharacterHealthPoints(character), -10, getCharacterArmor(character), character);
playerH = playerHeal(getCharacterHealthPoints(character), -10, getCharacterArmor(character), character);
setCharacterHealthPoints(character, playerH);
break;
case 'f':
@ -101,7 +112,7 @@ int fight(Character *character, enemy* enemy)
}
else
{
playerH = playerHealth(getCharacterHealthPoints(character), getEnemyDamage(enemy), getCharacterArmor(character), character);
playerH = playerDamaged(getCharacterHealthPoints(character), getEnemyDamage(enemy), getCharacterArmor(character), character);
setCharacterHealthPoints(character, playerH);
}
}

3
src/c/encounter.h

@ -12,7 +12,8 @@ typedef struct enemy{
bool playerAlive(int health);
int playerHealth(int health, int damage, int armor, Character* character);
int playerHeals(int health, int damage, int armor, Character* character);
int playerDamaged(int health, int damage, int armor, Character* character);
void enemyHeal(enemy *enemy, int healAmount);
void enemyDamaged(enemy* enemy, int damage);
bool enemyChoosesHeal(enemy* enemy);

4
test/c/test_encounter.c

@ -49,7 +49,7 @@ void test_playerIsDamaged(void)
int expectedHealth = 90;
// act
Character testChar = {10,10,10,health,100,1,0,100,damage,armor,100};
health = playerHealth(health, damage, armor, &testChar);
health = playerDamaged(health, damage, armor, &testChar);
// assert
TEST_ASSERT_EQUAL(expectedHealth, health);
}
@ -63,7 +63,7 @@ void test_playerIsNotOverhealed(void)
int expectedHealth = 100;
// act
Character testChar = {10,10,10,health,100,1,0,100,10,armor,100};
health = playerHealth(health, heal, armor, &testChar);
health = playerHeal(health, heal, armor, &testChar);
// assert
TEST_ASSERT_EQUAL(expectedHealth, health);
}

Loading…
Cancel
Save