using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ItemShop
{
class Program
{
private static List<Item> items = new List<Item>();
static void Main(string[] args)
{
InsertItem();
Console.WriteLine("Greetings Traveller! Care to take a look at my wares?");
while (true)
{
PrintItem();
string userInput = Console.ReadLine();
Console.Clear();
Console.WriteLine("User Input " + userInput);
//verifies if user input is null or empty or not a number.
if (string.IsNullOrEmpty(userInput) || !userInput.All(char.IsDigit))
{
Console.WriteLine("Sorry, but you choose to buy something i dont have!");
continue;
}
//turns the value the player has inputed from string to int.
int id = int.Parse(userInput) - 1;
//checks if the item consists within the list
if (id < 0 || id >= items.Count)
{
Console.WriteLine("Excuse me? are you messing with me?");
continue;
}
RemoveFromStore(id);
if (items.Count <= 0)
{
Console.WriteLine("Sorry but im out of stock.");
return;
}
}
}
private static void InsertItem()
{
items.Add(new Item("Health Restorative", 5, 25));
items.Add(new Item("Mana Restorative", 5, 25));
items.Add(new Item("Health Restorative EX", 10, 50));
items.Add(new Item("Mana Restorative EX", 10, 50));
items.Add(new Item("Cursed Greatsword", 5, 250));
items.Add(new Item("Battle Axe", 5, 250));
items.Add(new Item("Strange Elixir", 50, 50));
items.Add(new Item("Giant Ring", 1, 2500));
items.Add(new Item("Spell: Wrath of the Gods", 1, 25000));
items.Add(new Item("Spell: Hidden Body", 1, 25000));
}
private static void PrintItem()
{
foreach (var i in items)
{
Console.WriteLine(items.IndexOf(i) + 1 + i.ToString());
}
}
public static void RemoveFromStore(int value)
{
if (items[value].stock.Equals(1))
{
items.RemoveAt(value);
return;
}
items[value].stock--;
}
}
}