Browse Source

added shop function

remotes/origin/navigation
KRUGSON 2 years ago
parent
commit
d8c2a24930
  1. 49
      src/c/shop.c
  2. 8
      src/c/shop.h

49
src/c/shop.c

@ -0,0 +1,49 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "shop.h"
int openShop(Item *availableItems)
{
int userInput;
fflush(stdout);
bool shopIsOpen = 1;
while (shopIsOpen == 1)
{
printf("*** SHOP-Items *** \n\n");
// printf("%-5s %-30s %5s\n", "Index", "Name", "Price");
for (int i = 0; i < 6; i++)
{
printf("%-5d %-40s %5d$\n", availableItems[i].id, availableItems[i].itemName, availableItems[i].price);
}
printf("\n-> to buy items type '[index of item]' \n-> write '0' to quit the shop'\n\n");
while (scanf("%d", &userInput) != 1)
{
printf("Invalid [index]. Please try again: ");
fflush(stdout);
}
if (userInput > 0)
{
return userInput;
// BUY ITEM added later -> addItemToInventory(userInput);
}
else if (userInput == 0)
{
shopIsOpen = 0;
printf("Enjoy your items, have a great day!\n");
return 0;
}
else
{
printf("Invalid [index]. Please try again: ");
}
}
return 0;
}

8
src/c/shop.h

@ -0,0 +1,8 @@
#ifndef SHOP_H
#define SHOP_H
#include "items.h"
int openShop(Item *availableItems);
#endif
Loading…
Cancel
Save