Browse Source

refactoring: moved useful functions to dif library

remotes/origin/encIntegration
János 2 years ago
parent
commit
a18fede745
  1. 12
      src/c/encounter.c
  2. 15
      src/c/utils.c
  3. 7
      src/c/utils.h
  4. 1
      test/c/test_encounter.c

12
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)
{

15
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;
}

7
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

1
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)

Loading…
Cancel
Save