diff --git a/src/c/player.c b/src/c/player.c index 83596a9..eea802d 100644 --- a/src/c/player.c +++ b/src/c/player.c @@ -5,10 +5,9 @@ #include "player.h" - // PLAYER INVENTORY -//add and remove +// add and remove Player addItemToInventory(Item *availableItems, int itemIndex, Player actualPlayer) { int counter = actualPlayer.itemCounter; @@ -51,14 +50,21 @@ Player removeItemFromInventory(int itemIndex, Player actualPlayer) return actualPlayer; } -//currency +// currency Player setTotal(Player actualPlayer, int value) { actualPlayer.wallet = value; return actualPlayer; } -//show +Player addMoneyToPlayer(Player actualPlayer, int money) +{ + int newTotal = money + actualPlayer.wallet; + actualPlayer = setTotal(actualPlayer, newTotal); + return actualPlayer; +} + +// show void showInventory(Player actualPlayer) { int inventoryItemCounter = actualPlayer.itemCounter; @@ -80,4 +86,3 @@ void showInventory(Player actualPlayer) printf("\n\n"); } - diff --git a/src/c/player.h b/src/c/player.h index e5191fa..5569f6c 100644 --- a/src/c/player.h +++ b/src/c/player.h @@ -17,6 +17,7 @@ Player removeItemFromInventory(int index, Player actualPlayer); //currency Player setTotal(Player actualPlayer, int value); +Player addMoneyToPlayer(Player actualPlayer, int money); //show void showInventory(Player actualPlayer); diff --git a/test/c/test_player.c b/test/c/test_player.c index 4763d43..e3c708d 100644 --- a/test/c/test_player.c +++ b/test/c/test_player.c @@ -72,4 +72,23 @@ void test_setTotal(void) TEST_ASSERT_NOT_EQUAL_UINT8(valueBefore, valueAfter); } +void test_addMoneyToPlayer(void) +{ + /* arrange */ + // Hier die Werte eingeben/deklarieren + // balance = 70 + int valueToAdd = 20; + int checkSum = actualPlayer.wallet + valueToAdd; + /* act */ + // Die Funktion wird ausgeführt + actualPlayer = addMoneyToPlayer(actualPlayer, valueToAdd); + + // OUTPUT + printf("%d$ has been added to your balance. TOTAL: %d$", valueToAdd, actualPlayer.wallet); + + /* assert */ + // Vergleichen mit Inhalt von game.Map File + TEST_ASSERT_EQUAL_INT(checkSum, actualPlayer.wallet); +} + #endif // TEST