コード例 #1
0
ファイル: Game.cs プロジェクト: DavidChy/Lemonade_Stand_Game
        private void RunDay(Day day)
        {
            double          pricePerCup = UserInterface.GetPricePerCup();
            List <Customer> customers   = CreateCustomers();

            int  numberOfPitchersMade = 0;
            bool haveAPitcher         = playerOne.MakeAPitcher();

            if (haveAPitcher)
            {
                numberOfPitchersMade += 1;
            }

            int remainingCupsInPitcher = 10;
            int cupsSold = 0;

            if (haveAPitcher)
            {
                for (int i = 0; i < customers.Count; i++)
                {
                    bool boughtLemonade = customers[i].LuckOfPurchase(day, pricePerCup, i);
                    if (boughtLemonade)
                    {
                        playerOne.Inventory.RemoveItems("cup", 1);
                        cupsSold += 1;

                        remainingCupsInPitcher -= 1;
                        if (remainingCupsInPitcher == 0)
                        {
                            haveAPitcher = playerOne.MakeAPitcher();
                            if (haveAPitcher)
                            {
                                numberOfPitchersMade  += 1;
                                remainingCupsInPitcher = 10;
                            }
                        }
                    }

                    if (!haveAPitcher || playerOne.Inventory.cups.Count == 0)
                    {
                        Console.WriteLine("You are SOLD OUT at least one item for today! Or you got robbed. \n");
                        playerOne.Inventory.DisplayInventory();
                        break;
                    }
                }
            }

            double loss    = numberOfPitchersMade * playerOne.Lemonade.PriceOfPitcher() + cupsSold * Cup.price;
            double revenue = cupsSold * pricePerCup;

            playerOne.Money += revenue - loss;
            day.SaveDay(revenue - loss, cupsSold);
        }