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