From a18fede745dc692dfbc504d4db44c87e91b02ff1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1nos?= Date: Wed, 25 Jan 2023 19:51:39 +0100 Subject: [PATCH] refactoring: moved useful functions to dif library --- src/c/encounter.c | 12 +----------- src/c/utils.c | 15 +++++++++++++++ src/c/utils.h | 7 +++++++ test/c/test_encounter.c | 1 + 4 files changed, 24 insertions(+), 11 deletions(-) create mode 100644 src/c/utils.c create mode 100644 src/c/utils.h 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)