diff --git a/src/c/player.c b/src/c/player.c index eea802d..f59881b 100644 --- a/src/c/player.c +++ b/src/c/player.c @@ -64,6 +64,13 @@ Player addMoneyToPlayer(Player actualPlayer, int money) return actualPlayer; } +Player removeMoneyFromPlayer(Player actualPlayer, int money) +{ + int newTotal = actualPlayer.wallet - money; + actualPlayer = setTotal(actualPlayer, newTotal); + return actualPlayer; +} + // show void showInventory(Player actualPlayer) { diff --git a/src/c/player.h b/src/c/player.h index 5569f6c..1283b70 100644 --- a/src/c/player.h +++ b/src/c/player.h @@ -18,6 +18,7 @@ Player removeItemFromInventory(int index, Player actualPlayer); //currency Player setTotal(Player actualPlayer, int value); Player addMoneyToPlayer(Player actualPlayer, int money); +Player removeMoneyFromPlayer(Player actualPlayer, int money); //show void showInventory(Player actualPlayer); diff --git a/test/c/test_player.c b/test/c/test_player.c index e3c708d..d0de9ef 100644 --- a/test/c/test_player.c +++ b/test/c/test_player.c @@ -79,6 +79,7 @@ void test_addMoneyToPlayer(void) // balance = 70 int valueToAdd = 20; int checkSum = actualPlayer.wallet + valueToAdd; + /* act */ // Die Funktion wird ausgeführt actualPlayer = addMoneyToPlayer(actualPlayer, valueToAdd); @@ -91,4 +92,26 @@ void test_addMoneyToPlayer(void) TEST_ASSERT_EQUAL_INT(checkSum, actualPlayer.wallet); } +void test_removeMoneyFromPlayer(void) +{ + /* arrange */ + // Hier die Werte eingeben/deklarieren + int valueToRemove = 20; + int checkSum = actualPlayer.wallet - valueToRemove; + + /* act */ + // Die Funktion wird ausgeführt + actualPlayer = removeMoneyFromPlayer(actualPlayer, valueToRemove); + + // OUTPUT + printf("%d$ has been removed from your balance. TOTAL: %d$", valueToRemove, actualPlayer.wallet); + + /* assert */ + // Vergleichen mit Inhalt von game.Map File + TEST_ASSERT_EQUAL_INT(checkSum, actualPlayer.wallet); +} + + + + #endif // TEST