diff --git a/src/c/player.c b/src/c/player.c index fea8f91..85602bf 100644 --- a/src/c/player.c +++ b/src/c/player.c @@ -89,6 +89,13 @@ Player buyItem(Item *availableItems, int itemIndex, Player actualPlayer) } } +Player sellItem(int itemIndex, Player actualPlayer) +{ + actualPlayer = addMoneyToPlayer(actualPlayer, actualPlayer.itemInventory[itemIndex].price / 2); + actualPlayer = removeItemFromInventory(itemIndex, actualPlayer); + printf("Item has been sold! Your balance is now: %d$\n", actualPlayer.wallet); + return actualPlayer; +} // show void showInventory(Player actualPlayer) diff --git a/src/c/player.h b/src/c/player.h index 411c2cf..4518f70 100644 --- a/src/c/player.h +++ b/src/c/player.h @@ -22,6 +22,7 @@ Player removeMoneyFromPlayer(Player actualPlayer, int money); //add and remove items with currency Player buyItem(Item *availableItems, int itemIndex, Player actualPlayer); +Player sellItem(int itemIndex, Player actualPlayer); //show void showInventory(Player actualPlayer); diff --git a/test/c/test_player.c b/test/c/test_player.c index 2bd5683..5e86752 100644 --- a/test/c/test_player.c +++ b/test/c/test_player.c @@ -129,5 +129,27 @@ void test_buyItem(void) } +void test_sellItem(void) +{ + /* arrange */ + // Hier die Werte eingeben/deklarieren + int buyItemID = 1; // prepare sell + actualPlayer = addItemToInventory(availableItems, buyItemID, actualPlayer); // prepare sell + + int itemToRemove = 0; // index to remove (we already bought it in function above) + + /* act */ + // Die Funktion wird ausgeführt + Item itemBeforeRemove = actualPlayer.itemInventory[0]; + actualPlayer = sellItem(itemToRemove, actualPlayer); // then remove + Item itemAfterRemove = actualPlayer.itemInventory[0]; + + // OUTPUT + //printf("sellItem | before: %d -> after: %d", itemBeforeRemove.id, itemAfterRemove.id); + + /* assert */ + // Vergleichen mit Inhalt von game.Map File + TEST_ASSERT_NOT_EQUAL_UINT8(itemBeforeRemove.id, itemAfterRemove.id); +} #endif // TEST