Пример #1
0
        }//End DisplayGameFinished

        /// <summary>
        ///If the game has been complete prompts
        ///the user to decide if they would like
        ///to play a new game and restarts a fresh
        ///game if they decide yes.
        /// Pre: Prompts user to input "y" or "Y".
        /// Post: If input is "y" or "Y" starts a fresh game,
        /// any other input is counted as a no.
        /// </summary>
        static void RestartGame()
        {
            Console.Write("\n\nPlay again? (Y or N): ");
            string input = Console.ReadLine();

            if (input == "y" || input == "Y")
            {
                Console.WriteLine();
                SpaceRaceGame.Players.Clear();
                SpaceRaceGame.TotalPlayers();
                SpaceRaceGame.SetUpPlayers();
                SpaceRaceGame.round = 1;

                //Code below is essentially running Main again
                //if the user decides to play again.
                while (!SpaceRaceGame.GameFinished())
                {
                    SpaceRaceGame.PlayOneRound();
                    if (SpaceRaceGame.CheckAllPlayerFuel())
                    {
                        AllPlayersOutOfFuel();
                        break;
                    }
                    SpaceRaceGame.DisplayPlayerRoundInfo();
                }

                DisplayGameFinished();
                RestartGame();
            }

            //Else gracefully ends the program.
            else if (input != "y" || input != "Y")
            {
                Console.WriteLine("\nThanks for playing Space Race.");
                PressEnter();
            }

            else
            {
                Console.WriteLine("\nPlease enter Y or N.");
                RestartGame();
            }
        }//End RestartGame
        private void rollDiceButton_Click(object sender, EventArgs e)
        {
            UpdatePlayersGuiLocations(TypeOfGuiUpdate.RemovePlayer);

            if (!singleStep)
            {
                roundCounter++;
                SpaceRaceGame.PlayOneRound();
            }

            else if (singleStep)
            {
                PlayOneTurn();
            }

            UpdatePlayersGuiLocations(TypeOfGuiUpdate.AddPlayer);
            UpdatesPlayersDataGridView();

            if (roundCounter > 0)
            {
                roundDisabler();
            }
            else if (turnCounter > 0)
            {
                turnDisabler();
            }
            else if (turnCounter == 0 || turnCounter == SpaceRaceGame.NumberOfPlayers)
            {
                startOfTurnDisabler();
            }

            if (SpaceRaceGame.GameFinished())
            {
                guiGameFinished();
            }

            if (SpaceRaceGame.CheckAllPlayerFuel())
            {
                allPlayersOutOfFuel();
            }
        }
Пример #3
0
        /// <summary>
        /// Runs the methods required to operate the console
        /// version of the Space Race Game.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            DisplayIntroductionMessage();

            Board.SetUpBoard();
            SpaceRaceGame.TotalPlayers();
            SpaceRaceGame.SetUpPlayers();

            while (!SpaceRaceGame.GameFinished())
            {
                SpaceRaceGame.PlayOneRound();
                if (SpaceRaceGame.CheckAllPlayerFuel())
                {
                    AllPlayersOutOfFuel();
                    break;
                }
                SpaceRaceGame.DisplayPlayerRoundInfo();
            }
            DisplayGameFinished();
            RestartGame();
        }//End Main