Exemple #1
0
        void Buy()
        {
            var selection = "";

            while (string.IsNullOrEmpty(selection))
            {
                Console.WriteLine("");
                Console.WriteLine("What Would you like to purchase? ");
                selection = Console.ReadLine();
            }

            if (!ItemCatalog.ContainsKey(selection))
            {
                Console.WriteLine("");
                Console.WriteLine("That selection is not valid please try again.");
                Buy();
            }

            if (VerifyFunds(selection))
            {
                FinalizeBuy(selection);
            }

            this.Menu();
        }
Exemple #2
0
        public void BuyItem()
        {
            ShowShopInventory();
            var itemDictNum = ("");

            Console.Write("Enter the code of the item you would like to purchase.");
            itemDictNum = Console.ReadLine();
            if (ItemCatalog.ContainsKey(itemDictNum))
            {
                CheckOut(itemDictNum);
            }
            else if (!ItemCatalog.ContainsKey(itemDictNum))
            {
                Console.WriteLine("Please Enter a Valid Code.");
                Start();
            }
        }
Exemple #3
0
        public void SellItem()
        {
            ShowHeroInventory();

            var heroItemNum = "";

            Console.Write("Enter the code of the item you would like to sell.");
            heroItemNum = Console.ReadLine();

            if (HeroItems.ContainsKey(heroItemNum))
            {
                switch (heroItemNum.Substring(0, 1))
                {
                case "a":
                    var armor = (Armor)HeroItems[heroItemNum];

                    if (ShopGold >= armor.ResellValue)
                    {
                        Hero.Gold += armor.ResellValue;
                        Hero.ArmorsBag.Remove(armor);
                        this.ArmorList.Add(armor);
                        Console.WriteLine($"You sold a {armor.Name} for {armor.ResellValue} gold");
                        Start();
                    }
                    else
                    {
                        Console.WriteLine($"Shop does not have enough gold to purchase {armor.Name}");
                        Start();
                    }
                    break;

                case "p":
                    var potion = (Potion)HeroItems[heroItemNum];

                    if (ShopGold >= potion.ResellValue)
                    {
                        Hero.Gold += potion.ResellValue;
                        Hero.PotionsBag.Remove(potion);
                        this.PotionsList.Add(potion);
                        Console.WriteLine($"You sold a {potion.Name} for {potion.ResellValue} gold");
                        Start();
                    }
                    else
                    {
                        Console.WriteLine($"Shop does not have enough gold to purchase {potion.Name}");
                        Start();
                    }
                    break;

                case "w":
                    var weapon = (Weapon)HeroItems[heroItemNum];

                    if (ShopGold >= weapon.ResellValue)
                    {
                        Hero.Gold += weapon.ResellValue;
                        Hero.WeaponsBag.Remove(weapon);
                        this.WeaponsList.Add(weapon);
                        Console.WriteLine($"You sold a {weapon.Name} for {weapon.ResellValue} gold");
                        Start();
                    }
                    else
                    {
                        Console.WriteLine($"Shop does not have enough gold to purchase {weapon.Name}");
                        Start();
                    }
                    break;
                }
            }
            else if (!ItemCatalog.ContainsKey(heroItemNum))
            {
                Console.WriteLine("Please Enter a Valid Code");
                Start();
            }
        }