예제 #1
0
        public static IPlayer Shopping(IPlayer player)
        {
            weapons     = CreateWeapons(player.Level);
            armors      = CreateArmors(player.Level);
            consumables = CreateConsumables(player.Level);

            Console.WriteLine($"Welcome to my shop {player.Name}");
            Console.WriteLine("What do you want to purchase");
            Console.WriteLine($"you have {player.Gold} gold");
            IEquipable  weapon = new Weapons();
            IEquipable  armor  = new Armors();
            IConsumable drink  = new Potions();


            Console.WriteLine("1. A weapon");
            Console.WriteLine("2. An armor");
            Console.WriteLine("3. Some potions");
            Console.WriteLine("4. Nothing");


            var cki = Console.ReadKey();

            if (cki.Key == ConsoleKey.D1 || cki.Key == ConsoleKey.NumPad1)
            {
                weapon = weapon.BuyStuff(weapons, player);
                if (player.Gold < weapon.Price)
                {
                    Console.WriteLine("you don't have enough gold, press enter to continue");
                }
                else
                {
                    player.Gold  -= weapon.Price;
                    player.Weapon = weapon;
                    Console.WriteLine("Congratulation on your purchase, press enter to continue");
                }

                Console.ReadLine();
            }
            else if (cki.Key == ConsoleKey.D2 || cki.Key == ConsoleKey.NumPad2)
            {
                armor = armor.BuyStuff(armors, player);
                if (player.Gold < armor.Price)
                {
                    Console.WriteLine("you don't have enough gold, press enter to continue");
                }
                else
                {
                    player.Gold -= armor.Price;
                    player.Armor = armor;
                    Console.WriteLine("Congratulation on your purchase, press enter to continue");
                }
                Console.WriteLine($"You have {player.Gold} gold left");
                Console.ReadLine();
            }
            else if (cki.Key == ConsoleKey.D3 || cki.Key == ConsoleKey.NumPad3)
            {
                int ownedPotions;
                if (player.Consumable != null)
                {
                    ownedPotions = player.Consumable.Count;
                }
                else
                {
                    ownedPotions = 0;
                }
                consumables = drink.BuyStuff(consumables, player);
                var total            = consumables.Sum(item => item.Price);
                var potion           = consumables.FirstOrDefault();
                var reduction        = ownedPotions * potion.Price;
                var transactionPrice = total - reduction;
                if (player.Gold < transactionPrice)
                {
                    Console.WriteLine("you don't have enough gold, press enter to continue");
                }
                else
                {
                    player.Gold      -= transactionPrice;
                    player.Consumable = consumables;
                    Console.WriteLine("Congratulation on your purchase, press enter to continue");
                }

                Console.ReadLine();
            }
            else if (cki.Key == ConsoleKey.D4 || cki.Key == ConsoleKey.NumPad4)
            {
                Console.WriteLine("");
            }

            return(player);
        }