コード例 #1
0
ファイル: Store.cs プロジェクト: Garrett2261/LemonadeStand
        public void BuyLemons(Player Player, Inventory Inventory)
        {
            Console.WriteLine("You can either buy '10' lemons for 0.65, '30' lemons for 2.16, or '75' lemons for 4.34. Or if you don't need any and or already have enough, you can enter 'menu' to go back to the Main Menu.");
            string amountWanted = Console.ReadLine();

            switch (amountWanted)
            {
            case "10":
                lemonsBought = 10;
                break;

            case "30":
                lemonsBought = 30;
                break;

            case "75":
                lemonsBought = 75;
                break;

            case "menu":
                ExploreStore(Player, Inventory);
                return;

            default:
                Console.WriteLine("You can only purchase '10', '30', or '75' lemons at a time. Please try again.");
                BuyLemons(Player, Inventory);
                return;
            }
            if (lemonsBought == 10)
            {
                lemonCost = priceOfTenLemons;
            }
            else if (lemonsBought == 30)
            {
                lemonCost = priceOfThirtyLemons;
            }
            else if (lemonsBought == 75)
            {
                lemonCost = priceOfSeventyFiveLemons;
            }
            if (Player.money >= lemonCost)
            {
                Console.WriteLine("You have successfully bought" + ' ' + lemonsBought + ' ' + "lemons.");
                SeeTotalCostForIngredients(lemonCost);
                Player.money -= lemonCost;
                Console.WriteLine("You have" + ' ' + "$" + Player.money + "left.");
                Inventory.AddLemonsFromStore(lemonsBought);
            }
            else if (Player.money < lemonCost)
            {
                Console.WriteLine("You don't have enought money to buy that amount of lemons. Please choose a lower amount, or come back with more money. If you want to buy less lemons, enter 'buy again' or if you don't have enough money and can't buy anymore and want to go back to the Main Menu, enter 'menu'.");
                string answer = Console.ReadLine();
                switch (answer)
                {
                case "buy again":
                    BuyLemons(Player, Inventory);
                    break;

                case "menu":
                    ExploreStore(Player, Inventory);
                    break;

                default:
                    ExploreStore(Player, Inventory);
                    break;
                }
            }

            BuyLemons(Player, Inventory);
        }