Пример #1
0
        /// <summary>
        /// Lets you purchase from a merchant
        /// </summary>
        /// <param name="universe"></param>
        /// <param name="adventurer"></param>
        public static void MerchantBuy(Universe universe, Adventurer adventurer)
        {
            ConsoleKeyInfo consoleKey;
            bool           keepShopping = true;
            Dictionary <Item.Items, int> itemToPurchase = new Dictionary <Item.Items, int>();

            TextBoxViews.MerchMenu(universe);

            Item.Items item = Item.Items.SlimeGel;
            while (keepShopping)
            {
                bool purchase        = false;
                bool chooseSomething = true;


                int cost = 0;

                while (chooseSomething)
                {
                    consoleKey = Console.ReadKey();

                    switch (consoleKey.Key)
                    {
                    case ConsoleKey.NumPad1:

                        item = Item.Items.HealthPotion;

                        itemToPurchase[item] = HowMany(universe, Item.Items.HealthPotion);

                        cost = 20 * itemToPurchase[item];

                        chooseSomething = false;
                        break;

                    case ConsoleKey.D1:
                        item = Item.Items.HealthPotion;

                        itemToPurchase[item] = HowMany(universe, Item.Items.HealthPotion);

                        cost = 20 * itemToPurchase[item];

                        chooseSomething = false;

                        break;

                    case ConsoleKey.NumPad2:
                        item = Item.Items.ManaPotion;

                        itemToPurchase[item] = HowMany(universe, Item.Items.ManaPotion);

                        cost = 20 * itemToPurchase[item];

                        chooseSomething = false;
                        break;

                    case ConsoleKey.D2:
                        item = Item.Items.ManaPotion;

                        itemToPurchase[item] = HowMany(universe, Item.Items.ManaPotion);

                        cost = 20 * itemToPurchase[item];

                        chooseSomething = false;
                        break;


                    case ConsoleKey.NumPad3:
                        item = Item.Items.Stone;

                        itemToPurchase[item] = HowMany(universe, Item.Items.Stone);

                        cost = 2 * itemToPurchase[item];



                        chooseSomething = false;
                        break;

                    case ConsoleKey.D3:
                        item = Item.Items.Stone;

                        itemToPurchase[item] = HowMany(universe, Item.Items.Stone);

                        cost = 2 * itemToPurchase[item];



                        chooseSomething = false;
                        break;


                    case ConsoleKey.NumPad9:
                        keepShopping    = false;
                        chooseSomething = false;
                        break;

                    case ConsoleKey.D9:
                        keepShopping    = false;
                        chooseSomething = false;
                        break;

                    case ConsoleKey.LeftArrow:
                        keepShopping    = false;
                        chooseSomething = false;
                        break;

                    case ConsoleKey.RightArrow:
                        keepShopping    = false;
                        chooseSomething = false;
                        break;

                    case ConsoleKey.UpArrow:
                        keepShopping    = false;
                        chooseSomething = false;
                        break;

                    case ConsoleKey.DownArrow:
                        keepShopping    = false;
                        chooseSomething = false;
                        break;

                    default:
                        TextBoxViews.ReWriteToMessageBox(universe, "Please choose something I have and not the air please.", true);
                        break;
                    }
                }

                //Prints question
                if (keepShopping == true)
                {
                    TextBoxViews.ReWriteToMessageBox(universe, "So you want to buy " + itemToPurchase[item] + " " + item + "(s) for " + cost + " gold? Yes/No", true);

                    //Gets user input
                    purchase = Validators.ValidYesNo();
                }

                if (keepShopping)
                {
                    //checks if the player has enough coins
                    if (purchase && (adventurer.Coins >= cost))
                    {
                        adventurer.ItemsDictionary[item] += itemToPurchase[item];
                        adventurer.Coins -= cost;

                        TextBoxViews.ReWriteToMessageBox(universe, "Thanks for buyin", true);
                    }

                    else if (purchase && !(adventurer.Coins >= cost))
                    {
                        TextBoxViews.ReWriteToMessageBox(universe, "Hey! You dont have enough to buy that!!!", true);
                    }
                }
                TextBoxViews.DisplayPlayerInfo(adventurer);
            }
        }