diff --git a/src/c/commands.c b/src/c/commands.c new file mode 100644 index 0000000..7b7eeff --- /dev/null +++ b/src/c/commands.c @@ -0,0 +1,30 @@ +#include +#include +#include +#include + +#include "map.h" + +char* getPossibleCommands(Room r, int playerPosition) +{ + char commands[][20] = {}; + + char *msg = malloc(sizeof(char) * (500)); + strcpy(msg, ""); //assign char (string) that no leading zero result + if (playerPosition > 0) + { + strcat(msg, "You can move south from here\n"); + } + + if (playerPosition < mapMax - 1) + { + strcat(msg, "You can move north from here\n"); + } + + if (r.shopAvailable == 1) + { + strcat(msg, "You can call 'shop' to buy items.\n"); + } + + return msg; +} diff --git a/src/c/commands.h b/src/c/commands.h new file mode 100644 index 0000000..22bc63d --- /dev/null +++ b/src/c/commands.h @@ -0,0 +1,8 @@ +#ifndef COMMANDS_H +#define COMMANDS_H + +#include "map.h" + +char* getPossibleCommands(Room r, int playerPosition); + +#endif // COMMANDS_H \ No newline at end of file diff --git a/test/c/test_commands.c b/test/c/test_commands.c new file mode 100644 index 0000000..aa20fa0 --- /dev/null +++ b/test/c/test_commands.c @@ -0,0 +1,37 @@ +#ifdef TEST + +#include "unity.h" +#include "commands.h" +#include "map.h" +#include "nav_helper.h" + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test_commands(void) +{ + /* arrange */ + // Hier die Werte eingeben/deklarieren + Room* mapData; + mapData = getMap("./src/content/game.map"); + int playerPosition = 3; //last player position in north - so you can only move to south + char* expectedString = "You can move south from here\n"; + + /* act */ + // Die Funktion wird ausgeführt + char* msg = getPossibleCommands(mapData[playerPosition], playerPosition); + + /* TEST AUSGABE zur Kontrolle */ + printf("%s", msg); + + /* assert */ + // Vergleichen mit Inhalt + TEST_ASSERT_EQUAL_STRING(expectedString, msg); +} + +#endif // TEST \ No newline at end of file