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

        /// <summary>
        ///If the game has finished, displays
        ///the results to the console including
        ///winners and individual positions of
        ///all players.
        /// Pre: None.
        /// Post: Details of the players displayed as well as winners.
        /// </summary>
        static void DisplayGameFinished()
        {
            if (SpaceRaceGame.GameFinished())
            {
                //Write all the players who have won to the console.
                for (int kiterator = 0; kiterator < SpaceRaceGame.NumberOfPlayers; kiterator++)
                {
                    if (kiterator == 0)
                    {
                        Console.WriteLine
                        (
                            "\n\n\tThe following player(s) finished the game in round {0}\n",
                            SpaceRaceGame.round - 1
                        );
                    }

                    if (SpaceRaceGame.Players[kiterator].AtFinish)
                    {
                        Console.WriteLine
                        (
                            "\t\t{0}\n", SpaceRaceGame.Players[kiterator].Name
                        );
                    }
                }

                //Write all players information to the console including the winners.
                for (int jiterator = 0; jiterator < SpaceRaceGame.NumberOfPlayers; jiterator++)
                {
                    if (jiterator == 0)
                    {
                        Console.WriteLine("\n\n\tIndividual players finished at the following locations specified.\n");
                    }

                    Console.WriteLine
                    (
                        "\t\tPlayer {0} with {1} yottawatts of power at square {2}",
                        SpaceRaceGame.Players[jiterator].Name,
                        SpaceRaceGame.Players[jiterator].RocketFuel,
                        SpaceRaceGame.Players[jiterator].Position
                    );
                }
            }
        }//End DisplayGameFinished
Пример #2
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();
            }
        }
Пример #4
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