Browse Source

add commands (make it visible for user) with test

remotes/origin/navigation
KRUGSON 2 years ago
parent
commit
22fd94352f
  1. 30
      src/c/commands.c
  2. 8
      src/c/commands.h
  3. 37
      test/c/test_commands.c

30
src/c/commands.c

@ -0,0 +1,30 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#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;
}

8
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

37
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
Loading…
Cancel
Save