예제 #1
0
        public static void Day()
        {
            Console.Clear();
            Player.Day++;
            Console.WriteLine($"It's Day #{Player.Day} of selling lemonade!");

            Random      rnd = new Random();
            Temperature currentTemperature = TemperatureWeight.Random();
            Weather     currentWeather     = WeatherWeight[currentTemperature].Random();

            Console.WriteLine($"Today the weather is {currentTemperature} and {currentWeather}.");
            Wait();

            double      chanceToChange      = (rnd.NextDouble() + rnd.NextDouble()) / 2;
            Temperature forecastTemperature = TemperatureWeight.Random();
            Weather     forecastWeather     = WeatherWeight[forecastTemperature].Random();

            Console.WriteLine($"However, there is a {Math.Floor(chanceToChange * 100)}% chance that it will be {forecastTemperature} and {forecastWeather} later on.");
            Wait();

            double expenses = 0;
            int    cups;

            Console.WriteLine($"To make a cup of lemonade costs ${CupCost}. How many cups of lemonade would you like to make? (${Player.Balance})");
            while (true)
            {
                cups = InputInt();
                if (cups <= 0)
                {
                    Console.WriteLine("You gave up on the useless day.");
                    Wait();
                    return;
                }

                if (Player.Deduct(cups * CupCost))
                {
                    expenses += cups * CupCost;
                    break;
                }
            }

            int signs;

            Console.WriteLine($"To buy a sign to bring more customers to your shop costs ${SignCost}. How many signs would you want? (${Player.Balance})");
            while (true)
            {
                signs = InputInt();
                if (Player.Deduct(signs * SignCost))
                {
                    expenses += signs * SignCost;
                    break;
                }
            }

            Console.WriteLine($"How much would you like to charge people for lemonade?");
            double lemonadeCost = InputDouble();

            Temperature temperature;
            Weather     weather;

            if (rnd.NextDouble() < chanceToChange)
            {
                temperature = forecastTemperature;
                weather     = forecastWeather;
                Console.WriteLine($"The weather became {temperature} and {weather}.");
                Wait();
            }

            else
            {
                temperature = currentTemperature;
                weather     = currentWeather;
                Console.WriteLine($"The weather stayed {temperature} and {weather}.");
                Wait();
            }

            double chanceToBuy = TemperatureMultiplier[temperature] * WeatherSellChance[weather] / (Math.Pow(2, lemonadeCost) / 2);
            int    sold        = 0;

            for (int i = 0; i < (cups > 15 ? 15 : cups); i++)
            {
                if (rnd.NextDouble() < chanceToBuy)
                {
                    sold++;
                }
            }

            int signSee = (int)Math.Floor((double)((rnd.Next(signs - 2, signs + 3) + rnd.Next(signs - 2, signs + 3)) / 2));

            for (int i = 0; i < signSee; i++)
            {
                if (sold >= cups)
                {
                    break;
                }
                if (rnd.NextDouble() < chanceToBuy)
                {
                    sold++;
                }
            }

            Console.WriteLine($"You successfully sold {sold} cups of lemonade.");
            Wait();

            double earnings = sold * lemonadeCost;

            Console.WriteLine($"You earned ${earnings} from this.");
            Player.Balance += earnings;

            double profit = earnings - expenses;

            if (profit > 0)
            {
                Console.WriteLine($"You made a profit of ${profit}. (${Player.Balance})");
            }
            else
            {
                Console.WriteLine($"You lost ${0 - profit}. (${Player.Balance})");
            }

            Wait();
        }