Browse Source

refactoring: playerHealth() now uses Char Struct

remotes/origin/encIntegration
János 2 years ago
parent
commit
e633c8c6d3
  1. 8
      src/c/encounter.c
  2. 2
      src/c/encounter.h
  3. 6
      test/c/test_encounter.c

8
src/c/encounter.c

@ -28,9 +28,9 @@ bool playerAlive(int health)
}
}
int playerHealth(int health, int damage, int armor)
int playerHealth(int health, int damage, int armor, Character* character)
{
const int maxhealth = 100;
int maxhealth = getCharacterMaxHealthPoints(character);
health = health - damage;
if (health > maxhealth)
{
@ -87,7 +87,7 @@ int fight(Character *character, enemy* enemy)
enemyDamaged(enemy, playerDamage);
break;
case 'h':
playerH = playerHealth(playerH, -10, playerArmor);
playerH = playerHealth(playerH, -10, playerArmor, character);
break;
case 'f':
return 2;
@ -102,7 +102,7 @@ int fight(Character *character, enemy* enemy)
}
else
{
playerH = playerHealth(playerH, getEnemyDamage(enemy), playerArmor);
playerH = playerHealth(playerH, getEnemyDamage(enemy), playerArmor, character);
}
}
currentTurn = switchTurns(currentTurn);

2
src/c/encounter.h

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

6
test/c/test_encounter.c

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

Loading…
Cancel
Save