Browse Source

Added Map Function to Map Values

remotes/origin/encounter
János 2 years ago
parent
commit
4add252f45
  1. 5
      src/c/encounter.c
  2. 4
      src/c/encounter.h
  3. 12
      test/c/test_encounter.c

5
src/c/encounter.c

@ -112,6 +112,11 @@ int randomIntRange(int min, int 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/
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
// Getter/Setter Funktionen // Getter/Setter Funktionen
void setEnemyHealth(enemy* enemy, int newhealth) void setEnemyHealth(enemy* enemy, int newhealth)
{ {

4
src/c/encounter.h

@ -18,8 +18,8 @@ void enemyDamaged(enemy* enemy, int damage);
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);
//Funktionen die Mathematische Berechnungen durchführen
int map(int x, int in_min, int in_max, int out_min, int out_max);
int randomIntRange(int min, int max); int randomIntRange(int min, int max);
//Getter/Setter Funktionen //Getter/Setter Funktionen

12
test/c/test_encounter.c

@ -311,4 +311,16 @@ void test_roll_01()
TEST_ASSERT_EQUAL(expected, result); TEST_ASSERT_EQUAL(expected, result);
} }
void test_map10(){
int expected1 = 10, expected2 = 0, expected3 = 20;
int result;
result = map(50, 0, 100, 0, 20);
TEST_ASSERT_EQUAL(expected1, result);
result = map(0, 0, 100, 0, 20);
TEST_ASSERT_EQUAL(expected2, result);
result = map(100, 0, 100, 0, 20);
TEST_ASSERT_EQUAL(expected3, result);
}
#endif // TEST #endif // TEST
Loading…
Cancel
Save