Browse Source

Changed Heal and Damage Functions

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

15
src/c/encounter.c

@ -28,10 +28,10 @@ bool playerAlive(int health)
} }
} }
int playerHeal(int health, int damage, int armor, Character* character)
int playerHeal(int health, int damage, Character* character)
{ {
int maxhealth = getCharacterMaxHealthPoints(character); int maxhealth = getCharacterMaxHealthPoints(character);
health = health - damage;
health = health + damage;
if (health > maxhealth) if (health > maxhealth)
{ {
health = maxhealth; health = maxhealth;
@ -41,13 +41,12 @@ int playerHeal(int health, int damage, int armor, Character* character)
int playerDamaged(int health, int damage, int armor, Character* character) int playerDamaged(int health, int damage, int armor, Character* character)
{ {
int maxhealth = getCharacterMaxHealthPoints(character);
health = health - damage;
if (health > maxhealth)
int damagedealt = damage - armor;
if (damagedealt < 1)
{ {
health = maxhealth;
damagedealt = 1;
} }
return health;
return health - damagedealt;
} }
void enemyHeal(enemy *enemy, int healAmount) void enemyHeal(enemy *enemy, int healAmount)
@ -96,7 +95,7 @@ int fight(Character *character, enemy* enemy)
enemyDamaged(enemy, getCharacterAttack(character)); enemyDamaged(enemy, getCharacterAttack(character));
break; break;
case 'h': case 'h':
playerH = playerHeal(getCharacterHealthPoints(character), -10, getCharacterArmor(character), character);
playerH = playerHeal(getCharacterHealthPoints(character), 10, character);
setCharacterHealthPoints(character, playerH); setCharacterHealthPoints(character, playerH);
break; break;
case 'f': case 'f':

2
src/c/encounter.h

@ -12,7 +12,7 @@ typedef struct enemy{
bool playerAlive(int health); bool playerAlive(int health);
int playerHeals(int health, int damage, int armor, Character* character);
int playerHeal(int health, int damage, Character* character);
int playerDamaged(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 enemyHeal(enemy *enemy, int healAmount);
void enemyDamaged(enemy* enemy, int damage); void enemyDamaged(enemy* enemy, int damage);

8
test/c/test_encounter.c

@ -57,13 +57,13 @@ void test_playerIsDamaged(void)
void test_playerIsNotOverhealed(void) void test_playerIsNotOverhealed(void)
{ {
// arrange // arrange
int health = 100;
int health = 95;
int armor = 0; int armor = 0;
int heal = -10;
int heal = 10;
int expectedHealth = 100; int expectedHealth = 100;
// act // act
Character testChar = {10,10,10,health,100,1,0,100,10,armor,100}; Character testChar = {10,10,10,health,100,1,0,100,10,armor,100};
health = playerHeal(health, heal, armor, &testChar);
health = playerHeal(health, heal, &testChar);
// assert // assert
TEST_ASSERT_EQUAL(expectedHealth, health); TEST_ASSERT_EQUAL(expectedHealth, health);
} }
@ -369,7 +369,7 @@ void test_enemyChoosesHeal_ThenAttackWins(void)
//arange //arange
int result; int result;
int enemyHealth = 6, enemyDamage = 10, enemyArmor = 5, enemyMaxHealth = 100; int enemyHealth = 6, enemyDamage = 10, enemyArmor = 5, enemyMaxHealth = 100;
int playerHealth = 10, playerDamage = 10, playerArmor = 5, playerMaxHealth = 10;
int playerHealth = 10, playerDamage = 10, playerArmor = 0, playerMaxHealth = 10;
enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyMaxHealth}; enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyMaxHealth};
//act //act
Character testChar = {10,10,10,playerHealth,100,1,0,100,playerDamage,playerArmor,playerMaxHealth}; Character testChar = {10,10,10,playerHealth,100,1,0,100,playerDamage,playerArmor,playerMaxHealth};

Loading…
Cancel
Save