diff --git a/src/c/encounter.c b/src/c/encounter.c index 0f96c8c..873d9f7 100644 --- a/src/c/encounter.c +++ b/src/c/encounter.c @@ -8,6 +8,7 @@ #include "playerinput.h" #include "helper.h" +#include "utils.h" /*Gegner mit AC, damagedealt = damage-AC, kann nicht kleiner 1 sein evtl. lair bonus der dem gegner ein wenig mehr/weniger damage erlaubt @@ -128,18 +129,7 @@ int fight(Character *character, enemy* enemy) } } -int randomIntRange(int min, int max) -{ - int value = randomInt(); - return (value % (max - min + 1)) + min; -} - -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; -} bool enemyChoosesHeal(enemy* enemy) { diff --git a/src/c/utils.c b/src/c/utils.c new file mode 100644 index 0000000..8686724 --- /dev/null +++ b/src/c/utils.c @@ -0,0 +1,15 @@ +#include "utils.h" +#include "helper.h" + +int randomIntRange(int min, int max) +{ + int value = randomInt(); + return (value % (max - min + 1)) + min; +} + + +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; +} \ No newline at end of file diff --git a/src/c/utils.h b/src/c/utils.h new file mode 100644 index 0000000..eed2e44 --- /dev/null +++ b/src/c/utils.h @@ -0,0 +1,7 @@ +#ifndef UTILS_H +#define UTILS_H + +int randomIntRange(int min, int max); +int map(int x, int in_min, int in_max, int out_min, int out_max); + +#endif \ No newline at end of file diff --git a/test/c/test_encounter.c b/test/c/test_encounter.c index ecca7d9..023d470 100644 --- a/test/c/test_encounter.c +++ b/test/c/test_encounter.c @@ -7,6 +7,7 @@ #include "mock_playerinput.h" #include "helper.h" #include "mock_helper.h" +#include "utils.h" void setUp(void)