Browse Source

enemy now needs potions to heal

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

20
src/c/encounter.c

@ -146,7 +146,15 @@ bool enemyChoosesHeal(enemy* enemy)
int maxHealth = getEnemyMaxHealth(enemy);
int healthd20 = 20 - map(currentHealth, 0, maxHealth, 0, 20);
int rolld20 = randomIntRange(1, 20);
return (healthd20 + rolld20) >= 30;
if((healthd20 + rolld20) >= 30 && getEnemyHealPotions(enemy) > 0)
{
setEnemyHealPotions(enemy, getEnemyHealPotions(enemy) - 1);
return true;
}
else
{
return false;
}
}
// Getter/Setter Funktionen
@ -183,4 +191,14 @@ int getEnemyDamage(enemy* enemy)
int getEnemyMaxHealth(enemy* enemy)
{
return enemy->maxHealth;
}
int getEnemyHealPotions(enemy* enemy)
{
return enemy->healPotions;
}
void setEnemyHealPotions(enemy* enemy, int newPotions)
{
enemy->healPotions = newPotions;
}

4
src/c/encounter.h

@ -8,6 +8,7 @@ typedef struct enemy{
int damage;
int armor;
int maxHealth;
int healPotions;
} enemy;
@ -38,4 +39,7 @@ int getEnemyHealth(enemy* enemy);
int getEnemyArmor(enemy* enemy);
int getEnemyDamage(enemy* enemy);
int getEnemyHealPotions(enemy* enemy);
void setEnemyHealPotions(enemy* enemy, int newPotions);
#endif

16
test/c/test_encounter.c

@ -341,7 +341,7 @@ void test_enemyChoosesHeal(void)
//arange
bool result;
int enemyHealth = 50, enemyDamage = 4, enemyArmor = 4, enemyMaxHealth = 100;
enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyMaxHealth};
enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyMaxHealth, 1};
//act
randomInt_ExpectAndReturn(39); //39%20 = 19 , 19 + 1 = 20
result = enemyChoosesHeal(&test);
@ -370,7 +370,7 @@ void test_enemyChoosesHeal_ThenAttackWins(void)
int result;
int enemyHealth = 6, enemyDamage = 10, enemyArmor = 5, enemyMaxHealth = 100;
int playerHealth = 10, playerDamage = 10, playerArmor = 0, playerMaxHealth = 10;
enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyMaxHealth};
enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyMaxHealth,1 };
//act
Character testChar = {10,10,10,playerHealth,100,1,0,100,playerDamage,playerArmor,playerMaxHealth};
playerInputChar_ExpectAndReturn('a');
@ -383,4 +383,16 @@ void test_enemyChoosesHeal_ThenAttackWins(void)
}
void test_enemyHealsNoPotion(void)
{
int enemyHealth = 6, enemyDamage = 10, enemyArmor = 5, enemyMaxHealth = 100;
enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyMaxHealth, 0};
randomInt_ExpectAndReturn(39); //39%20 = 19 , 19 + 1 = 20
bool result = enemyChoosesHeal(&test);
TEST_ASSERT_FALSE(result);
}
#endif // TEST
Loading…
Cancel
Save