Browse Source

Function to make Enemy Heal

remotes/origin/encounter
János 2 years ago
parent
commit
457e8b5b3c
  1. 11
      src/c/encounter.c
  2. 1
      src/c/encounter.h
  3. 13
      test/c/test_encounter.c

11
src/c/encounter.c

@ -112,11 +112,20 @@ int randomIntRange(int min, int max)
} }
int map(int x, int in_min, int in_max, int out_min, int out_max){
int map(int x, int in_min, int in_max, int out_min, int out_max)
{
//vgl Arduino map() https://www.arduino.cc/reference/en/language/functions/math/map/ //vgl Arduino map() https://www.arduino.cc/reference/en/language/functions/math/map/
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
} }
bool enemyChoosesHeal(enemy* enemy)
{
int currentHealth = getEnemyHealth(enemy);
int maxHealth = getEnemyMaxHealth(enemy);
int healthd20 = map(currentHealth, 0, maxHealth, 0, 20);
return healthd20 <= 10;
}
// Getter/Setter Funktionen // Getter/Setter Funktionen
void setEnemyHealth(enemy* enemy, int newhealth) void setEnemyHealth(enemy* enemy, int newhealth)
{ {

1
src/c/encounter.h

@ -15,6 +15,7 @@ bool playerAlive(int health);
int playerHealth(int health, int damage, int armor); int playerHealth(int health, int damage, int armor);
void enemyHeal(enemy *enemy, int healAmount); void enemyHeal(enemy *enemy, int healAmount);
void enemyDamaged(enemy* enemy, int damage); void enemyDamaged(enemy* enemy, int damage);
bool enemyChoosesHeal(enemy* enemy);
int switchTurns(int currentTurn); int switchTurns(int currentTurn);
int fight(int playerH, int playerDamage, int playerArmor, int playerAttack, enemy* enemy); int fight(int playerH, int playerDamage, int playerArmor, int playerAttack, enemy* enemy);

13
test/c/test_encounter.c

@ -323,4 +323,17 @@ void test_map10(){
TEST_ASSERT_EQUAL(expected3, result); TEST_ASSERT_EQUAL(expected3, result);
} }
void test_enemyChoosesHeal(void)
{
//arange
bool result;
int enemyHealth = 50, enemyDamage = 4, enemyArmor = 4, enemyMaxHealth = 100;
enemy test = {enemyHealth, enemyDamage, enemyArmor, enemyMaxHealth};
//act
result = enemyChoosesHeal(&test);
//assert
TEST_ASSERT_TRUE(result);
}
#endif // TEST #endif // TEST
Loading…
Cancel
Save