From 2aea5ab0797100aa88c22889dd965d42d95ed7c8 Mon Sep 17 00:00:00 2001 From: KRUGSON Date: Sun, 5 Feb 2023 03:40:58 +0100 Subject: [PATCH] added struct player & func addItemToInventory --- src/c/player.c | 17 +++++++++++++++++ src/c/player.h | 16 ++++++++++++++++ test/c/test_player.c | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 src/c/player.c create mode 100644 src/c/player.h create mode 100644 test/c/test_player.c diff --git a/src/c/player.c b/src/c/player.c new file mode 100644 index 0000000..c789fed --- /dev/null +++ b/src/c/player.c @@ -0,0 +1,17 @@ +#include +#include +#include +#include + +#include "player.h" + + +// PLAYER INVENTORY +Player addItemToInventory(Item *availableItems, int itemIndex, Player actualPlayer) +{ + int counter = actualPlayer.itemCounter; + actualPlayer.itemInventory[counter] = availableItems[itemIndex - 1]; // -1 to get right index (items begin - 1,2,3,4...) + actualPlayer.itemCounter += 1; + + return actualPlayer; +} \ No newline at end of file diff --git a/src/c/player.h b/src/c/player.h new file mode 100644 index 0000000..25a69be --- /dev/null +++ b/src/c/player.h @@ -0,0 +1,16 @@ +#ifndef PLAYER_H +#define PLAYER_H + +#include "items.h" + +typedef struct +{ + int id; + int itemCounter; + Item itemInventory[100]; + int wallet; +} Player; + +Player addItemToInventory(Item *availableItem, int itemIndex, Player actualPlayer); + +#endif \ No newline at end of file diff --git a/test/c/test_player.c b/test/c/test_player.c new file mode 100644 index 0000000..bbdb496 --- /dev/null +++ b/test/c/test_player.c @@ -0,0 +1,33 @@ +#ifdef TEST + +#include "unity.h" +#include "player.h" +#include "items.h" +#include "nav_helper.h" + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test_addItemToInventory(void) +{ + /* arrange */ + // Hier die Werte eingeben/deklarieren + int shopItemIndex = 1; + Player actualPlayer; + Item *availableItems = getItems("./src/content/items.map"); + + /* act */ + // Die Funktion wird ausgeführt + actualPlayer = addItemToInventory(availableItems, shopItemIndex, actualPlayer); + + /* assert */ + // Vergleichen mit Inhalt von game.Map File + TEST_ASSERT_EQUAL_INT(shopItemIndex, actualPlayer.itemInventory[0].id); +} + +#endif // TEST