Browse Source

added struct player & func addItemToInventory

remotes/origin/navigation
KRUGSON 2 years ago
parent
commit
2aea5ab079
  1. 17
      src/c/player.c
  2. 16
      src/c/player.h
  3. 33
      test/c/test_player.c

17
src/c/player.c

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

16
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

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