Browse Source

Healing is weighted, lesser health more heal

remotes/origin/encounter
János 2 years ago
parent
commit
184c41412a
  1. 5
      src/c/encounter.c
  2. 15
      test/c/test_encounter.c

5
src/c/encounter.c

@ -122,8 +122,9 @@ bool enemyChoosesHeal(enemy* enemy)
{ {
int currentHealth = getEnemyHealth(enemy); int currentHealth = getEnemyHealth(enemy);
int maxHealth = getEnemyMaxHealth(enemy); int maxHealth = getEnemyMaxHealth(enemy);
int healthd20 = map(currentHealth, 0, maxHealth, 0, 20);
return healthd20 <= 10;
int healthd20 = 20 - map(currentHealth, 0, maxHealth, 0, 20);
int rolld20 = randomIntRange(1, 20);
return (healthd20 + rolld20) >= 30;
} }
// Getter/Setter Funktionen // Getter/Setter Funktionen

15
test/c/test_encounter.c

@ -330,10 +330,25 @@ void test_enemyChoosesHeal(void)
int enemyHealth = 50, enemyDamage = 4, enemyArmor = 4, enemyMaxHealth = 100; int enemyHealth = 50, enemyDamage = 4, enemyArmor = 4, enemyMaxHealth = 100;
enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyMaxHealth}; enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyMaxHealth};
//act //act
randomInt_ExpectAndReturn(39); //39%20 = 19 , 19 + 1 = 20
result = enemyChoosesHeal(&test); result = enemyChoosesHeal(&test);
//assert //assert
TEST_ASSERT_TRUE(result); TEST_ASSERT_TRUE(result);
} }
void test_enemyDoesNotChoosesHeal(void)
{
//arange
bool result;
int enemyHealth = 50, enemyDamage = 4, enemyArmor = 4, enemyMaxHealth = 100;
enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyMaxHealth};
//act
randomInt_ExpectAndReturn(14); //14%20 = 14 , 14 + 1 = 15
result = enemyChoosesHeal(&test);
//assert
TEST_ASSERT_FALSE(result);
}
#endif // TEST #endif // TEST
Loading…
Cancel
Save