Example #1
0
        public void RunGame()
        {
            playerList.Add(player);
            string numberOfPlayers = userInterface.AskForNumberOfPlayers();

            if (numberOfPlayers == "2")
            {
                string secondPlayer = DeterminePlayerType();
                if (secondPlayer == "computer")
                {
                    playerTwo = new Computer();
                    playerList.Add(playerTwo);
                }
                else
                {
                    playerTwo = new Human();
                    playerList.Add(playerTwo);
                }
            }

            duration    = userInterface.AskForDuration();
            gameDayList = GenerateDays(duration);

            //set all properties randomly
            for (int i = 0; i < duration; i++)
            {
                //generate weather
                Day    tomorrow = gameDayList[i];
                int    temperatureForTomorrow = tomorrow.PredictedTemperature;
                string forecastForTomorrow    = tomorrow.PredictedForecast;
                DisplayNextDayWeather("Tomorrow's", temperatureForTomorrow, forecastForTomorrow);
                supply.DayPurchased = i;

                if (playerTwo != null)
                {
                    if (playerTwo.GetType() == typeof(Computer))
                    {
                        SetComputerInventoryProperties(temperatureForTomorrow, playerTwo);
                        SetComputerProperties(temperatureForTomorrow);
                    }
                }

                foreach (Human player in playerList.OfType <Human>())
                {
                    // purchase segment
                    string purchasing = null;
                    while (purchasing != "5")
                    {
                        Console.WriteLine("Money: " + player.StartingMoney);
                        Console.WriteLine("Inventory ==> Lemons: " + player.inventory.TotalLemonsInInventory + " Sugar: " + player.inventory.TotalSugarInInventory + " Cups: " + player.inventory.CupsInInventory + " Ice Cubes: " + player.inventory.IcecubesInInventory);

                        purchasing = userInterface.PurchasingMenu();
                        if (purchasing == "5")
                        {
                            break;
                        }
                        int    purchaseQuantity = PurchaseQuantity();
                        double itemCost         = GetFromStore(purchasing, purchaseQuantity);

                        if (PlayerHasEnoughMoney(CalculateCost(itemCost, purchaseQuantity), player) == true)
                        {
                            SetInInventory(purchasing, purchaseQuantity, player);
                        }
                    }
                    string changeSetting = null;
                    while (changeSetting != "5")
                    {
                        //price/qualitycontrol segment
                        Console.WriteLine("Price/Quality Control ==> Price/Cup: " + player.PricePerCup + " Lemons/Pitcher: " + player.LemonsPerPitcher + " Sugar/Pitcher: " + player.SugarPerPitcher + " Ice Cubes/Cup: " + player.IcePerCup);
                        changeSetting = userInterface.QualityControlMenu();
                        if (changeSetting == "5")
                        {
                            player.CalculateCupsPerPitcher(player.IcePerCup);
                            break;
                        }

                        if (changeSetting == "1")
                        {
                            double newPrice = userInterface.PromptForPrice();
                            player.PricePerCup = newPrice;
                        }
                        else
                        {
                            int newSetting = userInterface.PromptForQuantity();
                            SetPlayerControls(changeSetting, newSetting, player);
                        }
                    }
                }
                Console.WriteLine("Day: " + (i + 1));
                temperatureForTomorrow = tomorrow.ActualTemperature;
                forecastForTomorrow    = tomorrow.ActualForecast;
                DisplayNextDayWeather("Today's", temperatureForTomorrow, forecastForTomorrow);

                int j = 0;
                foreach (Player player in playerList)
                {
                    //Day starts and selling begins
                    int salesCounter = 0;
                    if (SoldOut(player) == false)
                    {
                        foreach (Customer person in tomorrow.CustomerList)
                        {
                            if (SoldCup(person, tomorrow) == true)
                            {
                                SetInInventory("3", -1, player);
                                SetInInventory("4", -(player.IcePerCup), player);
                                salesCounter++;
                                if (salesCounter % player.CupsPerPitcher == 0)
                                {
                                    if (SoldOut(player) == true)
                                    {
                                        break;
                                    }
                                }
                            }
                            if ((player.inventory.IcecubesInInventory <= 0) ||
                                (player.inventory.CupsInInventory <= 0))
                            {
                                break;
                            }
                        }
                    }

                    j++;
                    player.DailyTotal    = (salesCounter * player.PricePerCup);
                    player.RunningTotal  = (player.RunningTotal + player.DailyTotal);
                    player.StartingMoney = player.StartingMoney + player.DailyTotal;
                    Console.WriteLine("Player " + j + "'s End of Day Report\n");
                    Console.WriteLine("You had " + salesCounter + " customers out of a potential " + tomorrow.CustomerList.Count());
                    Console.WriteLine("Revenue Today: " + player.DailyTotal);
                    Console.WriteLine("New Total: " + player.StartingMoney);
                    FindExpiredLemons(i, player);
                    FindExpiredSugar(i, player);
                    SetInInventory("4", -(player.inventory.IcecubesInInventory), player);
                    Console.WriteLine("The rest of your ice has melted\n");
                }
            }

            foreach (Human player in playerList.OfType <Human>())
            {
                SaveHighScore(player.StartingMoney);
            }
        }