Exemple #1
0
        public void BuyPotion()
        {
            //Display weapon list
            Console.Clear();
            Console.WriteLine("----------------------------------------------------------------------------------------------");
            Console.WriteLine("# Potions");
            Console.WriteLine("----------------------------------------------------------------------------------------------");
            Console.WriteLine(String.Format("{0,3} | {1,-25} | {2,-7} | {3,-7} |", "ID", "Name", "Healing", "Price"));
            Console.WriteLine("----------------------------------------------------------------------------------------------");

            for (var i = 0; i < Potions.Count(); i++)
            {
                Console.WriteLine(String.Format("{0,3} | {1,-25} | {2,-7} | {3,-7} |", i + 1, Potions[i].Name, Potions[i].HealthRestored + " HP", Potions[i].Price + " Gold"));
            }

            Console.WriteLine("----------------------------------------------------------------------------------------------");
            Console.WriteLine($"# You have {Hero.GoldCoin} Gold now!");
            Console.WriteLine("----------------------------------------------------------------------------------------------");
            Console.Write("# Select the Potion ID you want to buy : ");
            var KeyInput = Hero.GetUserInputNumber();

            var shopPotion = Potions.ElementAtOrDefault(0);

            if (KeyInput > Potions.Count() || KeyInput <= 0)
            {
                Console.WriteLine("# Select the corrent Potion ID : ");
                shopPotion = null;
            }
            else
            {
                shopPotion = Potions.ElementAtOrDefault(KeyInput - 1);
            }

            if (shopPotion != null)
            {
                if ((Hero.GoldCoin - shopPotion.Price) >= 0)
                {
                    Hero.PotionsBag.Add(shopPotion);
                    Hero.GoldCoin = Hero.GoldCoin - shopPotion.Price;
                    Console.WriteLine($"Buying '{shopPotion.Name}' is Completed!");
                }
                else
                {
                    Console.WriteLine("Sorry, you don't have enough Gold !");
                }
            }
            else
            {
                Console.WriteLine("Sorry,No result!");
            }
            Console.WriteLine("----------------------------------------------------------------------------------------------");
        }