|
|
@ -8,25 +8,25 @@ |
|
|
|
// PLAYER INVENTORY |
|
|
|
|
|
|
|
// add and remove |
|
|
|
Player addItemToInventory(Item *availableItems, int itemIndex, Player actualPlayer) |
|
|
|
Player addItemToInventory(Item *items, int itemIndex, Player player) |
|
|
|
{ |
|
|
|
int counter = actualPlayer.itemCounter; |
|
|
|
actualPlayer.itemInventory[counter] = availableItems[itemIndex - 1]; // -1 to get right index (items begin - 1,2,3,4...) |
|
|
|
actualPlayer.itemCounter += 1; |
|
|
|
int itemCounter = player.itemCounter; |
|
|
|
player.itemInventory[itemCounter] = items[itemIndex - 1]; // -1 to get right index (items begin - 1,2,3,4...) |
|
|
|
player.itemCounter += 1; |
|
|
|
|
|
|
|
return actualPlayer; |
|
|
|
return player; |
|
|
|
} |
|
|
|
|
|
|
|
Player removeItemFromInventory(int itemIndex, Player actualPlayer) |
|
|
|
Player removeItemFromInventory(int itemIndex, Player player) |
|
|
|
{ |
|
|
|
Item items[maxItems]; // actualPlayer.itemInventory |
|
|
|
Item items[maxItems]; // player.itemInventory |
|
|
|
int i, index = -1; |
|
|
|
|
|
|
|
for (i = 0; i < maxItems; i++) |
|
|
|
{ |
|
|
|
if (i == itemIndex) |
|
|
|
{ |
|
|
|
// printf("%d - '%s' has been removed from inventory.\n", actualPlayer.itemInventory[i].id, actualPlayer.itemInventory[i].itemName); |
|
|
|
// printf("%d - '%s' has been removed from inventory.\n", player.itemInventory[i].id, player.itemInventory[i].itemName); |
|
|
|
index = i; |
|
|
|
break; |
|
|
|
} |
|
|
@ -36,73 +36,73 @@ Player removeItemFromInventory(int itemIndex, Player actualPlayer) |
|
|
|
{ |
|
|
|
// shift all the element from index+1 by one position to the left |
|
|
|
for (i = index; i < maxItems - 1; i++) |
|
|
|
actualPlayer.itemInventory[i] = actualPlayer.itemInventory[i + 1]; |
|
|
|
player.itemInventory[i] = player.itemInventory[i + 1]; |
|
|
|
|
|
|
|
/*printf("New Array : "); |
|
|
|
for(i = 0; i < maxItems - 1; i++) |
|
|
|
printf("%d ",actualPlayer.itemInventory[i].id);*/ |
|
|
|
printf("%d ",player.itemInventory[i].id);*/ |
|
|
|
} |
|
|
|
else |
|
|
|
printf("Element Not Found\n"); |
|
|
|
|
|
|
|
actualPlayer.itemCounter = actualPlayer.itemCounter - 1; |
|
|
|
player.itemCounter = player.itemCounter - 1; |
|
|
|
|
|
|
|
return actualPlayer; |
|
|
|
return player; |
|
|
|
} |
|
|
|
|
|
|
|
// currency |
|
|
|
Player setTotal(Player actualPlayer, int value) |
|
|
|
Player setTotal(Player player, int value) |
|
|
|
{ |
|
|
|
actualPlayer.wallet = value; |
|
|
|
return actualPlayer; |
|
|
|
player.wallet = value; |
|
|
|
return player; |
|
|
|
} |
|
|
|
|
|
|
|
Player addMoneyToPlayer(Player actualPlayer, int money) |
|
|
|
Player addMoneyToPlayer(Player player, int moneyValue) |
|
|
|
{ |
|
|
|
int newTotal = money + actualPlayer.wallet; |
|
|
|
actualPlayer = setTotal(actualPlayer, newTotal); |
|
|
|
return actualPlayer; |
|
|
|
int newTotal = moneyValue + player.wallet; |
|
|
|
player = setTotal(player, newTotal); |
|
|
|
return player; |
|
|
|
} |
|
|
|
|
|
|
|
Player removeMoneyFromPlayer(Player actualPlayer, int money) |
|
|
|
Player removeMoneyFromPlayer(Player player, int moneyValue) |
|
|
|
{ |
|
|
|
int newTotal = actualPlayer.wallet - money; |
|
|
|
actualPlayer = setTotal(actualPlayer, newTotal); |
|
|
|
return actualPlayer; |
|
|
|
int newTotal = player.wallet - moneyValue; |
|
|
|
player = setTotal(player, newTotal); |
|
|
|
return player; |
|
|
|
} |
|
|
|
|
|
|
|
//add and remove items with currency |
|
|
|
Player buyItem(Item *availableItems, int itemIndex, Player actualPlayer) |
|
|
|
Player buyItem(Item *items, int itemIndex, Player player) |
|
|
|
{ |
|
|
|
int itemPrice = availableItems[itemIndex - 1].price; |
|
|
|
if (actualPlayer.wallet >= itemPrice) |
|
|
|
int itemPrice = items[itemIndex - 1].price; |
|
|
|
if (player.wallet >= itemPrice) |
|
|
|
{ |
|
|
|
actualPlayer = addItemToInventory(availableItems, itemIndex, actualPlayer); |
|
|
|
actualPlayer = removeMoneyFromPlayer(actualPlayer, itemPrice); |
|
|
|
printf("You bought item[%d] for %d$! \nYour balance is now: %d$\n", itemIndex, itemPrice, actualPlayer.wallet); |
|
|
|
return actualPlayer; |
|
|
|
player = addItemToInventory(items, itemIndex, player); |
|
|
|
player = removeMoneyFromPlayer(player, itemPrice); |
|
|
|
printf("You bought item[%d] for %d$! \nYour balance is now: %d$\n", itemIndex, itemPrice, player.wallet); |
|
|
|
return player; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
printf("You don't have enough money.\n\n"); |
|
|
|
return actualPlayer; |
|
|
|
return player; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
Player sellItem(int itemIndex, Player actualPlayer) |
|
|
|
Player sellItem(int itemIndex, Player player) |
|
|
|
{ |
|
|
|
int priceItemSell = actualPlayer.itemInventory[itemIndex].price; |
|
|
|
actualPlayer = addMoneyToPlayer(actualPlayer, actualPlayer.itemInventory[itemIndex].price / 2); |
|
|
|
printf("Item has been sold for 50%% of the purchase price (purchase price: %d$)! \nYour balance is now: %d$\n", priceItemSell, actualPlayer.wallet); |
|
|
|
int priceItemSell = player.itemInventory[itemIndex].price; |
|
|
|
player = addMoneyToPlayer(player, player.itemInventory[itemIndex].price / 2); |
|
|
|
printf("Item has been sold for 50%% of the purchase price (purchase price: %d$)! \nYour balance is now: %d$\n", priceItemSell, player.wallet); |
|
|
|
|
|
|
|
actualPlayer = removeItemFromInventory(itemIndex, actualPlayer); |
|
|
|
return actualPlayer; |
|
|
|
player = removeItemFromInventory(itemIndex, player); |
|
|
|
return player; |
|
|
|
} |
|
|
|
|
|
|
|
// show |
|
|
|
void showInventory(Player actualPlayer) |
|
|
|
void showInventory(Player player) |
|
|
|
{ |
|
|
|
int inventoryItemCounter = actualPlayer.itemCounter; |
|
|
|
int inventoryItemCounter = player.itemCounter; |
|
|
|
|
|
|
|
if (inventoryItemCounter == 0) |
|
|
|
{ |
|
|
@ -112,10 +112,10 @@ void showInventory(Player actualPlayer) |
|
|
|
{ |
|
|
|
printf("*** Inventory *** \n\n"); |
|
|
|
|
|
|
|
for (int i = 0; i < actualPlayer.itemCounter; i++) |
|
|
|
for (int i = 0; i < player.itemCounter; i++) |
|
|
|
{ |
|
|
|
// printf("%d: %d - %s\n", i, inventory[i].id, inventory[i].itemName); |
|
|
|
printf("> %s - %d\n", actualPlayer.itemInventory[i].itemName, i); |
|
|
|
printf("> %s - %d\n", player.itemInventory[i].itemName, i); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|