示例#1
0
        public void DayLoop(Inventory inventory, Weather weather)
        {
            // loop each customer object through a sales calculation that determines if they buy lemonade or not
            Console.Clear();
            Console.WriteLine("How much would you like to sell each cup for?");
            lemonadePrice = player.DoubleInputTest();
            if (lemonadePrice == 0)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(errorMessage + "Please enter in a valid price");
                Console.ReadKey();
                Console.ResetColor();
                InitializeDay(player, inventory);
            }
            else if (recipeList[0] == 0 || recipeList[1] == 0 || recipeList[2] == 0)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(errorMessage + "one or more ingrediants are not set.");
                Console.ReadKey();
                Console.ResetColor();
                DayLoop(inventory, weather);
            }
            else
            {
                Random rngCustomerCount = new Random();
                int    customerCount    = 0;
                if (weather.actualWeather == "Sunny" || weather.actualWeather == "Partly Cloudy")
                {
                    customerCount = rngCustomerCount.Next(50, 101);
                }
                else if (weather.actualWeather == "Cloudy" || weather.actualWeather == "Foggy")
                {
                    customerCount = rngCustomerCount.Next(30, 86);
                }
                Console.WriteLine("Building Customer List, please wait...");
                while (customerCount >= customerList.Count)
                {
                    // building list of customers that will be check if they want to buy lemonade
                    Customer customer = new Customer(0, 0);
                    customer.Creation(weather);
                    customerList.Add(customer);
                }
                Console.WriteLine("Customer List completed.");
                foreach (var item in customerList)
                {
                    if (item.maxExpectedPrice <= lemonadePrice)
                    {
                        salesCounter++;
                    }
                    else
                    {
                        if (salesCounter >= 15)
                        {
                            Random rngSaleOverride = new Random();
                            int    SaleOverride    = rngSaleOverride.Next(1, 101);
                            System.Threading.Thread.Sleep(20);
                            if (SaleOverride <= item.temptation)
                            {
                                salesCounter++;
                            }
                        }
                    }
                }
                // math below is calculating the netLoss based on ingrediants used during the day
                var    pitchersMade = Math.Ceiling((Convert.ToDecimal(salesCounter)) / 10);
                double lemonsUsed;
                double iceCubesUsed;
                double sugarUsed;
                lemonsUsed   = (recipeList[0] * Convert.ToInt32(pitchersMade));
                iceCubesUsed = (recipeList[1] * Convert.ToInt32(pitchersMade));
                sugarUsed    = (recipeList[2] * Convert.ToInt32(pitchersMade));
                netLoss      = ((lemonsUsed * 0.25) + (Convert.ToDouble(Math.Ceiling((Convert.ToDecimal(iceCubesUsed)) / 50)) * 0.50) + (sugarUsed * 0.20));
                netProfit    = ((salesCounter * lemonadePrice) - netLoss);

                GUI.EndOfDayReport(inventory, salesCounter, lemonadePrice, netLoss);
                Console.WriteLine("\n" + "Press any key to continue.");
                Console.ReadKey();
            }
            dayCounter++;
            InitializeDay(player, inventory);
        }