Пример #1
0
            public virtual void Use()
            {
                Console.WriteLine("What do you want to consume?");
                Inventory.MyInventory();
                string ConsumeItem = Convert.ToString(Console.ReadLine());

                if (FoodItems.ContainsKey(ConsumeItem))
                {
                    Console.WriteLine("You eat " + ConsumeItem);
                    Inventory.MyItems.Remove(ConsumeItem);
                }
                else if (DrinkItems.Equals(ConsumeItem))
                {
                    Console.WriteLine("You drink " + ConsumeItem);
                    Inventory.MyItems.Remove(ConsumeItem);
                }
                else if (SnackItems.Equals(ConsumeItem))
                {
                    Console.WriteLine("You snack on " + ConsumeItem);
                    Inventory.MyItems.Remove(ConsumeItem);
                }
                else
                {
                    Console.WriteLine("you don't have the item in your inventory.");
                }
                //Jämnför input med vad som finns i dictionaries. Stämmer det så ska den ge tillbaka en string beroende på vilken dictionary som ger "true". Ta bort saken från inventory.
            }
Пример #2
0
            public virtual void Purchase()
            {
                Inventory ClassInv  = new Inventory();
                bool      isRunning = true;

                while (isRunning)
                {
                    Console.WriteLine("What do you want to purchase?");
                    ClassInv.ShowStock();
                    string PurchaseInput = Convert.ToString(Console.ReadLine());
                    if (FoodItems.ContainsKey(PurchaseInput) || DrinkItems.ContainsKey(PurchaseInput) || SnackItems.ContainsKey(PurchaseInput))
                    {
                        int price;
                        if (FoodItems.TryGetValue(PurchaseInput, out price) || DrinkItems.TryGetValue(PurchaseInput, out price) || SnackItems.TryGetValue(PurchaseInput, out price))
                        {
                            int CheckPrice = Convert.ToInt32(price);
                            if (MoneyPool.money >= CheckPrice)
                            {
                                Console.WriteLine("You add " + PurchaseInput + " to your items.");
                                Inventory.MyItems.Add(PurchaseInput);
                                MoneyPool.money -= CheckPrice;
                                Console.WriteLine("Your change is " + MoneyPool.money);
                                MoneyPool.money = 0;

                                Console.ReadKey();
                                Console.Clear();
                                isRunning = false;
                                //Om den hittar en som passar så ska den sparas i en lokal variabel så priset kan kollas och subtraheras ifrån vad användaren har.
                            }
                            else
                            {
                                Console.WriteLine("You don't have enough money to purchase that product.");
                                Console.ReadKey();
                            }
                        }
                        else
                        {
                            Console.WriteLine("Error, can't find value.");
                            Console.ReadKey();
                        }
                    }
                    else
                    {
                        Console.WriteLine("You entered the wrong product.");
                        Console.ReadKey();
                        Console.Clear();
                        isRunning = false;
                    }
                }
            }