Пример #1
0
 //All tokens move at once per turn
 private void MultiStep()
 {
     UpdatePlayersGuiLocations(TypeOfGuiUpdate.RemovePlayer);
     SpaceRaceGame.PlayOneRound();
     UpdatePlayersGuiLocations(TypeOfGuiUpdate.AddPlayer);
     UpdatesPlayersDataGridView();
 }
Пример #2
0
        } //end GameEndReturn_PerPlayer

        /// <summary>
        /// This method lets the player play the game on a per round basis.
        /// One click of the roll button now acts upon every player, and each
        /// click is a new roudn.
        ///
        /// Pre:  Player selects "no" for the radio button option.
        /// Post: Game is evolved, per round, as the roll button is pushed
        /// </summary>
        ///
        /// <param name="gameEnd">The end game state.</param>
        /// <returns>Returns the game state.</returns>
        private bool GameEndReturn_PerRound(ref bool gameEnd)
        {
            // Play One Round
            roundEnd = true;
            SpaceRaceGame.PlayOneRound(die1, die2);
            fuelEmptyCount = 0;

            // Game End test - Play One Round
            for (int i = 0; i < SpaceRaceGame.NumberOfPlayers; i++)// for each player
            {
                // Test if player is at Finish update endTxt and gameEnd
                if (SpaceRaceGame.Players[i].AtFinish)
                {
                    gameEnd = true;
                    endTxt += String.Format("\t{0}", SpaceRaceGame.names[i]);
                }

                if (SpaceRaceGame.Players[i].RocketFuel == 0)
                {
                    fuelEmptyCount++;
                }
            }

            return(gameEnd);
        } //end GameEndReturn_PerRound
Пример #3
0
        /// <summary>
        /// Algorithm below currently plays only one game
        ///
        /// when have this working correctly, add the abilty for the user to
        /// play more than 1 game if they choose to do so.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            DisplayIntroductionMessage();

            /*
             * Set up the board in Board class (Board.SetUpBoard)
             * Determine number of players - initally play with 2 for testing purposes
             * Create the required players in Game Logic class
             * and initialize players for start of a game
             * loop  until game is finished
             *  call PlayGame in Game Logic class to play one round
             *  Output each player's details at end of round
             * end loop
             * Determine if anyone has won
             * Output each player's details at end of the game
             */
            Board.SetUpBoard();
            HowManyPlayers();
            SpaceRaceGame.SetUpPlayers();
            while (!GameOver())
            {
                PressEnterForRound();
                SpaceRaceGame.PlayOneRound();
                playerstats();
            }

            PressEnter();
        }//end Main
Пример #4
0
        private void RollButton_Click(object sender, EventArgs e)
        {
            exitButton.Enabled = false;
            if (noButton.Checked == true)
            {
                UpdatePlayersGuiLocations(TypeOfGuiUpdate.RemovePlayer);
                SpaceRaceGame.PlayOneRound();
                UpdatePlayersGuiLocations(TypeOfGuiUpdate.AddPlayer);
                UpdatesPlayersDataGridView();
                CheckIfFinished();
            }
            if (yesButton.Checked == true)
            {
                UpdatePlayersGuiLocations(TypeOfGuiUpdate.RemovePlayer);
                SpaceRaceGame.PlayOneRound();
                UpdatePlayersGuiLocations(TypeOfGuiUpdate.AddPlayer);
                UpdatesPlayersDataGridView();
                CheckIfFinished();
            }

            exitButton.Enabled          = true;
            resetButton.Enabled         = true;
            playersDataGridView.Enabled = false;
            numPlayerBox.Enabled        = false;
        }
        } // end PressAny

        static void StartRound()
        {
            bool playerState = false;

            while (playerState == false) // while no one player has won yet
            {
                Console.WriteLine("\n\nPress Enter to play a round ...");
                Console.Read();
                SpaceRaceGame.PlayOneRound();
                for (int i = 0; i < SpaceRaceGame.Players.Count; i++)
                {
                    if (SpaceRaceGame.Players[i].AtFinish == true)
                    {
                        DisplayWinMessage(SpaceRaceGame.Players[i]);
                        playerState = true;
                        break; // end if any player wins
                    }

                    else if (SpaceRaceGame.AllPlayerFuel() == true)
                    {
                        playerState = true;
                        break; // end if all player has 0 fuel
                    }
                }

                if (playerState == false)
                {
                    DisplayCurrentPosition();                       // to prevent repeated displays
                }
                Console.Read();
            }
        } // End StartRound()
        } //end UpdatePlayersGuiLocations

        private void RollDiceButton_Click(object sender, EventArgs e)
        {
            // disables all the buttons/features except for the reset button
            exitButton.Enabled          = false;
            GameResetButton.Enabled     = true;
            playersDataGridView.Enabled = false;
            comboBox1.Enabled           = false;
            RollDiceButton.Enabled      = false;

            // removes the players from the board
            UpdatePlayersGuiLocations(TypeOfGuiUpdate.RemovePlayer);

            // finds the new positions of the players, according to which mode is being played
            if (singleStepYesButton.Checked == true)
            {
                SpaceRaceGame.PlayOnePlayer();
            }

            else if (singleStepNoButton.Checked == true)
            {
                SpaceRaceGame.PlayOneRound();
            }

            // adds the players back to the board at their new positions an updates the GUI
            UpdatePlayersGuiLocations(TypeOfGuiUpdate.AddPlayer);
            UpdatesPlayersDataGridView();

            // re-enables necessary features after this process
            RollDiceButton.Enabled = true;
            exitButton.Enabled     = true;

            // determines if no one has any fuel
            if (SpaceRaceGame.NoOneHasFuel == true)
            {
                RollDiceButton.Enabled = false;
                MessageBox.Show("The Game is Over, because everyone has run out of fuel!");
            }

            // determines if someone has won the game
            if (SpaceRaceGame.SomeoneHasWon == true)
            {
                string text = "";

                RollDiceButton.Enabled = false;

                for (int i = 0; i < SpaceRaceGame.NumberOfPlayers; i++)
                {
                    if (SpaceRaceGame.Players[i].Position == 55)
                    {
                        text = text + SpaceRaceGame.Players[i].Name + "\n\t";
                    }
                }

                MessageBox.Show("The following player(s) have finished the game\n\n\t" + text);
            }
        }
        } // end SingleStep() method

        private void AllStep()
        {
            UpdatePlayersGuiLocations(TypeOfGuiUpdate.RemovePlayer);
            SpaceRaceGame.PlayOneRound();
            UpdatePlayersGuiLocations(TypeOfGuiUpdate.AddPlayer);
            UpdatesPlayersDataGridView();
            resetButton.Enabled = true;
            ToggleAll(false);
            EndGame();
            WinnerMessage(EndGame());
        } // no single step
Пример #8
0
        }//end PrepareToPlay()

        private void NoButton_Click(object sender, EventArgs e)
        {
            stepBox.Enabled    = false;
            rollButton.Enabled = true;
            // Play 1 round when clicking no
            UpdatePlayersGuiLocations(TypeOfGuiUpdate.RemovePlayer);
            SpaceRaceGame.PlayOneRound();
            UpdatePlayersGuiLocations(TypeOfGuiUpdate.AddPlayer);
            UpdatesPlayersDataGridView();
            CheckIfFinished();
        }
Пример #9
0
        }                                   //end UpdatePlayersGuiLocations

        // Play one round if GameState is unfinished [OC]
        private void GUIPlayOneRound()
        {
            if (SpaceRaceGame.GameState == -1)
            {
                btnRoll.Enabled = false;
                UpdatePlayersGuiLocations(TypeOfGuiUpdate.RemovePlayer);
                SpaceRaceGame.PlayOneRound();
                UpdatePlayersGuiLocations(TypeOfGuiUpdate.AddPlayer);
                UpdatesPlayersDataGridView();
                btnRoll.Enabled = true;
            }
        }
Пример #10
0
        private void button1_Click(object sender, EventArgs e)
        {
            RollDiceButton_Click.Enabled = false;
            button2.Enabled             = false;
            exitButton.Enabled          = false;
            groupBox1.Enabled           = false;
            comboBox1.Enabled           = false;
            playersDataGridView.Enabled = false;

            UpdatePlayersGuiLocations(TypeOfGuiUpdate.RemovePlayer);


            //Play one round
            SpaceRaceGame.PlayOneRound();

            //reset available if round finishes on single step
            if (SpaceRaceGame.SingleStep)
            {
                //from game logic - SpaceRaceGame.PlayOneRound()
                if (SpaceRaceGame.PlayerNum == 0)
                {
                    button2.Enabled    = true;
                    exitButton.Enabled = true;
                }
            }
            else
            {
                button2.Enabled    = true;
                exitButton.Enabled = true;
            }


            UpdatePlayersGuiLocations(TypeOfGuiUpdate.AddPlayer);
            UpdatesPlayersDataGridView();


            //allow rolls
            RollDiceButton_Click.Enabled = true;


            //if game is finished - remove roll availability
            if (SpaceRaceGame.GameFinished)
            {
                RollDiceButton_Click.Enabled = false;
                var msg_box = MessageBox.Show(SpaceRaceGame.DisplayGameResults());
            }
        }
Пример #11
0
        /// <summary>
        /// Algorithm below currently plays only one game
        ///
        /// when have this working correctly, add the abilty for the user to
        /// play more than 1 game if they choose to do so.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            DisplayIntroductionMessage();
            Board.SetUpBoard();

            /*
             * Set up the board in Board class (Board.SetUpBoard)
             * Determine number of players - initally play with 2 for testing purposes
             * Create the required players in Game Logic class
             * and initialize players for start of a game
             *
             * loop  until game is finished
             *  call PlayGame in Game Logic class to play one round
             *  Output each player's details at end of round
             * end loop
             * Determine if anyone has won
             * Output each player's details at end of the game
             */
            bool playagain = true;

            do
            {
                Console.WriteLine("Press Enter to play a round \n");

                //Clear players bindinglist
                //Clear all previous winners from winningPlayers
                //setup number of players
                //setup each pieces
                SpaceRaceGame.Players.Clear();
                SpaceRaceGame.winningPlayers.Clear();
                SpaceRaceGame.NumberOfPlayers = EnterNumberOfPlayers();
                SpaceRaceGame.SetUpPlayers();

                //loop until somebody wins the game
                //the game is displayed one round at a time
                //loops everytime the user types Y to playagain
                do
                {
                    SpaceRaceGame.PlayOneRound(); Console.ReadKey();
                } while (SpaceRaceGame.won == false);
                playagain = PlayAgain();
            } while (playagain == true);


            PressEnter();
        }//end Main
Пример #12
0
        static void Main(string[] args)
        {
            DisplayIntroductionMessage();
            Board.SetUpBoard();

            // While the user wants to continue playing, the game runs.
            bool playingSpaceRace = true;

            while (playingSpaceRace)
            {
                // After each game the user is prompted to enter the number of players,
                // sets up the appropriate amount of players based on what was entered.
                EnterPlayers();
                SpaceRaceGame.SetUpPlayers();
                PressEnter();

                // While the round is running, continue to another round,
                // if a player hasn't finished
                bool gameInProgress = true;
                while (gameInProgress)
                {
                    // While the game isn't finished play one round and check if
                    // any player finished or if all players out of fuel
                    SpaceRaceGame.PlayOneRound();
                    DisplayProgress();

                    if (PlayerAtFinish())
                    {
                        gameInProgress = false;
                    }
                    else if (AllPlayersOutOfFuel())
                    {
                        gameInProgress = false;
                        DisplayInConsole(AllPlayersOutMessage());
                    }

                    PressEnter();
                }

                // Prompt user if they want to play again, if not terminate game
                playingSpaceRace = PlayAgain();
            }

            PressEnterToExit();
        }//end Main
Пример #13
0
        static void PlayAgain()
        {
            Console.Write("\n\tPress 'y' or 'Y' to play again: ");
            char input;

            char.TryParse(Console.ReadLine(), out input);
            if (input == 'y' || input == 'Y')
            {
                for (int i = 0; i < SpaceRaceGame.NumberOfPlayers; i++)
                {
                    SpaceRaceGame.Players[i].Position   = 0;
                    SpaceRaceGame.Players[i].Location   = Board.StartSquare;
                    SpaceRaceGame.Players[i].RocketFuel = Player.INITIAL_FUEL_AMOUNT;
                    SpaceRaceGame.Players[i].HasPower   = true;
                    SpaceRaceGame.Players[i].AtFinish   = false;
                }

                GetNumberPlayers();
                Board.SetUpBoard();
                SpaceRaceGame.SetUpPlayers();
                bool finished = false;
                SpaceRaceGame.PlayOneRound();
                PressEnter();
                while (finished == false)
                {
                    SpaceRaceGame.PlayOneRound();
                    KeepPlaying();

                    for (int i = 0; i < SpaceRaceGame.NumberOfPlayers; i++)
                    {
                        if (SpaceRaceGame.Players[i].AtFinish == true)
                        {
                            finished = true;
                        }
                    }
                }
                ShowFinalInfo();
            }
            else
            {
                Console.Write("\n\nThanks for playing Space Race.\n");
                Console.Write("\nPress Enter to terminate program ...");
                Console.ReadLine();
            }
        }
Пример #14
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
Пример #15
0
        private void RollButton_Click(object sender, EventArgs e)
        {
            //Disable data grid to be edited during game
            //Enable reset button on every round.
            playersDataGridView.Enabled = false;
            ResetButton.Enabled         = true;

            //Show name of winners of the game in a messagebox
            if (SpaceRaceGame.won == true)
            {
                foreach (var item in SpaceRaceGame.winningPlayers)
                {
                    MessageBox.Show(item.Name + " won the game ");
                }
            }
            else
            {
                //If checkbox is checked at YES, allow multi step movement
                if (stepMulti.Checked == true)
                {
                    UpdatePlayersGuiLocations(TypeOfGuiUpdate.RemovePlayer);
                    SpaceRaceGame.PlayOneRound();
                    UpdatePlayersGuiLocations(TypeOfGuiUpdate.AddPlayer);
                }

                //else, allow single step movement
                else if (stepOne.Checked == true)
                {
                    {
                        RollButton.Enabled = true;
                        for (int i = 0; i < SpaceRaceGame.NumberOfPlayers; i++)
                        {
                            UpdatePlayersGuiLocations(TypeOfGuiUpdate.RemovePlayer, SpaceRaceGame.Players[i]);
                            SpaceRaceGame.PlayOneRound(SpaceRaceGame.Players[i]);
                            UpdatePlayersGuiLocations(TypeOfGuiUpdate.AddPlayer, SpaceRaceGame.Players[i]);
                        }
                    }
                }
                //update the players data grid view
                UpdatesPlayersDataGridView();
                exitButton.Enabled = true;
            }
        }
        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();
            }
        }
Пример #17
0
        /// <summary>
        /// Algorithm below currently plays only one game
        ///
        /// when have this working correctly, add the abilty for the user to
        /// play more than 1 game if they choose to do so.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            DisplayIntroductionMessage();
            GetNumberPlayers();

            /*
             * Set up the board in Board class (Board.SetUpBoard)
             * Determine number of players - initally play with 2 for testing purposes
             * Create the required players in Game Logic class
             * and initialize players for start of a game
             * loop  until game is finished
             *  call PlayGame in Game Logic class to play one round
             *  Output each player's details at end of round
             * end loop
             * Determine if anyone has won
             * Output each player's details at end of the game
             */
            Board.SetUpBoard();
            SpaceRaceGame.SetUpPlayers();

            bool finished = false;

            SpaceRaceGame.PlayOneRound();
            PressEnter();

            while (finished == false)
            {
                SpaceRaceGame.PlayOneRound();
                KeepPlaying();

                for (int i = 0; i < SpaceRaceGame.NumberOfPlayers; i++)
                {
                    if (SpaceRaceGame.Players[i].AtFinish == true)
                    {
                        finished = true;
                    }
                }
            }

            ShowFinalInfo();
        }//end Main
Пример #18
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
Пример #19
0
        } //end UpdatePlayersGuiLocations

        /// <summary>
        /// Event handler for roll button. Plays either single round or single step.
        /// Pre:  No of players and single step option selected
        /// Post:  tableLayoutPanel and dataGridView updated
        /// </summary>
        private void rolButton_Click(object sender, EventArgs e)
        {
            UpdatePlayersGuiLocations(TypeOfGuiUpdate.RemovePlayer);

            // Split functionality based on groupBox selection
            if (yesRadioButton.Checked == true)   // single step mode
            {
                SpaceRaceGame.PlayRoundSingleStep();
            }
            else   // play complete round
            {
                SpaceRaceGame.PlayOneRound();
            }

            UpdatePlayersGuiLocations(TypeOfGuiUpdate.AddPlayer);
            UpdatesPlayersDataGridView();

            // Update GUI controls
            if (SpaceRaceGame.playerTurnCounter == SpaceRaceGame.NumberOfPlayers)
            {
                resetButton.Enabled = true;
                exitButton.Enabled  = true;
            }
            else
            {
                resetButton.Enabled = false;
                exitButton.Enabled  = false;
            }

            playersDataGridView.Enabled = false;
            comboBox1.Enabled           = false;

            // check if users have completed the game on current round
            if (SpaceRaceGame.GameComplete == true && SpaceRaceGame.playerTurnCounter == SpaceRaceGame.NumberOfPlayers)
            {
                rolButton.Enabled = false;
                displayWinners();
            }
        }
Пример #20
0
        private void diceButton_Click(object sender, EventArgs e)
        {
            //disable exit button until round finished, make player names uneditable, disable numOfPlayers combo box
            exitButton.Enabled = false;
            playersDataGridView.Columns[1].ReadOnly = true;
            numOfPlayers.Enabled = false;

            //remove players from current gui location, play a round and add them to their new locations
            UpdatePlayersGuiLocations(TypeOfGuiUpdate.RemovePlayer);
            SpaceRaceGame.PlayOneRound();
            UpdatePlayersGuiLocations(TypeOfGuiUpdate.AddPlayer);
            UpdatesPlayersDataGridView();

            //enable reset button after a round is played
            resetButton.Enabled = true;

            //if any players have reached the end, display message of who won, disable the dice button and enable exit
            for (int i = 0; i < SpaceRaceGame.NumberOfPlayers; i++)
            {
                if (SquareControlAt(55).ContainsPlayers[i] == true)
                {
                    string message = "";

                    for (int player = 0; player < SquareControlAt(55).ContainsPlayers.Length; player++)
                    {
                        if (SquareControlAt(55).ContainsPlayers[player] == true)
                        {
                            message += "\t" + SpaceRaceGame.Players[player].Name + "\n";
                        }
                    }
                    MessageBox.Show("The following have won the game:\n" + message);

                    diceButton.Enabled = false;
                    exitButton.Enabled = true;
                }
            }
        }
        /// <summary>
        /// Algorithm below currently plays only one game
        ///
        /// when have this working correctly, add the abilty for the user to
        /// play more than 1 game if they choose to do so.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            DisplayIntroductionMessage();
            // Set up the board in Board class (Board.SetUpBoard)
            Board.SetUpBoard();

            /*Determine number of players - initally play with 2 for testing purposes
             * Create the required players in Game Logic class
             * and initialize players for start of a game
             * loop  until game is finished
             * call PlayGame in Game Logic class to play one round
             * Output each player's details at end of round
             * end loop
             * Determine if anyone has won
             * Output each player's details at end of the game
             */
            do
            {
                int numberOfPlayers = GetInput_numberOfPlayers();
                SpaceRaceGame.NumberOfPlayers = numberOfPlayers;
                SpaceRaceGame.SetUpPlayers();
                int roundNumber = 0;
                SpaceRaceGame.GameOver = false;
                while (!SpaceRaceGame.GameOver)
                {
                    RoundStarter(roundNumber);
                    SpaceRaceGame.PlayOneRound();
                    DisplayResults();
                    roundNumber++;
                }
                DisplayRanking();
            }while(PlayAgain());

            GoodbyeMessage();

            PressEnter();
        }//end Main
Пример #22
0
        /// <summary>
        /// Loops over the PlayOneRound method until game is complete.
        /// Calls DisplayResults method to print winners and final positions
        /// Pre:  board and players have been initialised.
        /// Post:  leads in to play again option.
        /// </summary>
        public static void PlayGame()
        {
            int roundCounter = 0;  // tracks how many individual round have been played.

            while (SpaceRaceGame.GameComplete == false)
            {
                Console.WriteLine("\n\nPress Enter to play a round ...\n");
                Console.ReadLine();

                if (roundCounter == 0)
                {
                    Console.WriteLine("\tFirst Round\n");
                }
                else
                {
                    Console.WriteLine("\tNext Round\n");
                }

                SpaceRaceGame.PlayOneRound();
                roundCounter = roundCounter + 1;
                DisplayPositionAndFuel();
            }
            DisplayResults();
        }// end PlayGame
Пример #23
0
 private void btGameRoll_Click(object sender, EventArgs e)
 {
     cbNumberOfPlayers.Enabled = false;
     if (!singleMode)
     {
         UpdatePlayersGuiLocations(TypeOfGuiUpdate.RemovePlayer);
         SpaceRaceGame.PlayOneRound();
         UpdatePlayersGuiLocations(TypeOfGuiUpdate.AddPlayer);
         UpdatesPlayersDataGridView();
         btGameReset.Enabled       = true;
         dgvPlayers.Enabled        = false;
         cbNumberOfPlayers.Enabled = false;
     }
     else
     {
         dgvPlayers.Enabled  = false;
         btExit.Enabled      = false;
         btGameReset.Enabled = false;
         UpdatePlayerGuiLocations(TypeOfGuiUpdate.RemovePlayer, numberOfTurn);
         SpaceRaceGame.PlaySingle(numberOfTurn);
         UpdatePlayerGuiLocations(TypeOfGuiUpdate.AddPlayer, numberOfTurn);
         UpdatesPlayersDataGridView();
         numberOfTurn++;
         if (numberOfTurn == SpaceRaceGame.NumberOfPlayers)
         {
             btGameReset.Enabled = true;
             dgvPlayers.Enabled  = true;
             btExit.Enabled      = true;
             numberOfTurn        = 0;
         }
     }
     if (!SpaceRaceGame.IsGameActive() || SpaceRaceGame.LosedGame())
     {
         FinishGame();
     }
 }
Пример #24
0
 static void StartGame()
 {
     DisplayInstructionMessage();
     if (Int32.TryParse(Console.ReadLine(), out var numberOfPlayers) && numberOfPlayers <= 6 && numberOfPlayers >= 2)
     {
         Board.SetUpBoard();
         SpaceRaceGame.NumberOfPlayers = numberOfPlayers;
         SpaceRaceGame.SetUpPlayers();
         var round = "First";
         while (SpaceRaceGame.IsGameActive())
         {
             PressEnter();
             SpaceRaceGame.PlayOneRound();
             DisplayCurrentRound(ref round);
         }
         DisplayWinners();
         PlayAgain();
     }
     else
     {
         Console.WriteLine("\nError: invalid number of players entered.\n");
         StartGame();
     }
 }
Пример #25
0
        /// <summary>
        /// Algorithm below currently plays only one game
        ///
        /// when have this working correctly, add the abilty for the user to
        /// play more than 1 game if they choose to do so.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            DisplayIntroductionMessage();
            Board.SetUpBoard();

            bool playGame = true;

            //until user doesn't want to play another game
            while (playGame)
            {
                //Determine and create specified number of players and initialise players
                NumPlayers();
                SpaceRaceGame.SetUpPlayers();

                bool endGame = false;
                //until the game ends
                while (endGame != true)
                {
                    Console.WriteLine("\nPress enter to play a round...");
                    Console.ReadLine();

                    SpaceRaceGame.PlayOneRound();

                    foreach (Player currentPlayer in SpaceRaceGame.Players)
                    {
                        if (currentPlayer.Position >= Board.FINISH_SQUARE_NUMBER)
                        {
                            //still want to display all details before stating who won.
                            Console.WriteLine("\t{0} on square {1} with {2} yottawott of power remaining.",
                                              currentPlayer.Name, currentPlayer.Position, currentPlayer.RocketFuel);
                            endGame = true;
                        }//end AtFinish check if
                        else
                        {
                            if (currentPlayer.RocketFuel == 0)
                            {
                                Console.WriteLine("\t{0} at square {1} has run out of fuel.",
                                                  currentPlayer.Name, currentPlayer.Position);
                            }
                            else
                            {
                                Console.WriteLine("\t{0} on square {1} with {2} yottawott of power remaining.",
                                                  currentPlayer.Name, currentPlayer.Position, currentPlayer.RocketFuel);
                            } //end write current player's info if still playing
                        }     //end if rocket fuel is finished
                    }         //end foreach
                }             //end while

                //determine who has finished
                Console.WriteLine("\nThe following player(s) finished the game\n");
                FinishedPlayers();

                //output all players details
                Console.WriteLine("\nIndividual players finished with their remaining fuel at the locations specified.");
                PlayerInfo();

                //prompt player if they want to play another game
                playGame = PlayAgain();
            }
            PressEnter(); //terminates program
        }//end Main
Пример #26
0
        }//end GetPosition

        /// <summary>
        /// This method encapsulates all of the initialisations for the console game.
        /// The board is setup, the die instance are crated, then the game is run via the console.
        ///
        /// The amount of players are selected using the GetPlayers() method.
        ///
        /// The game continues to run until the players have run out of fuel or if players
        /// are able to finsh the game.
        /// </summary>
        static void PlayGame()
        {
            // Setup Board and Dice
            Board.SetUpBoard();
            Die d1 = new Die();
            Die d2 = new Die();

            // Get number of players for 1st round
            GetPlayers();

            SpaceRaceGame.SetUpPlayers();

            bool finishedGame = false;
            int  roundCount = 1, fuelEmptyCount = 0;

            while (!finishedGame)
            {
                fuelEmptyCount = 0; // track players with zero fuel each round

                Console.WriteLine("\nPress Enter to play a round  ...");
                Console.ReadLine();

                if (roundCount == 1)
                {
                    Console.WriteLine("First Round\n");
                }
                else
                {
                    Console.WriteLine("Next Round\n");
                }


                SpaceRaceGame.PlayOneRound(d1, d2);


                // Update if players have Finished or are out of Fuel
                for (int i = 0; i < SpaceRaceGame.NumberOfPlayers; i++)
                {
                    DisplayGame(SpaceRaceGame.Players[i]);

                    // Test if ANY player is at Finish and update finishedGame to true.
                    if (SpaceRaceGame.Players[i].AtFinish == true)
                    {
                        finishedGame = true;
                    }

                    // Test if ANY player has zero fuel
                    if (SpaceRaceGame.Players[i].RocketFuel == 0)
                    {
                        fuelEmptyCount++;
                    }
                }

                // Print statement and End game if ALL players fuel zero
                if (fuelEmptyCount == SpaceRaceGame.NumberOfPlayers)
                {
                    Console.WriteLine("\nAll players are out of fuel: GAME OVER!");
                    finishedGame = true;
                }

                roundCount++;
            }
        }//end PlayGame
Пример #27
0
        static void Main(string[] args)
        {
            DisplayIntroductionMessage();

            do
            {
                /*
                 * Set up the board in Board class (Board.SetUpBoard)
                 * Determine number of players - initally play with 2 for testing purposes
                 * Create the required players in Game Logic class
                 * and initialize players for start of a game
                 * loop  until game is finished
                 *  call PlayGame in Game Logic class to play one round
                 *  Output each player's details at end of round
                 * end loop
                 * Determine if anyone has won
                 * Output each player's details at end of the game
                 */

                Board.SetUpBoard();

                DetermineNumberOfPlayers();

                SpaceRaceGame.SetUpPlayers();

                while (SpaceRaceGame.SomeoneHasWon == false && SpaceRaceGame.NoOneHasFuel == false)
                {
                    // Intro message before round of game is played
                    Console.WriteLine("\nPress Enter to play a round ...");
                    Console.ReadLine();

                    DetermineRoundNumber();

                    SpaceRaceGame.PlayOneRound();
                    numbOfRounds++;

                    // displays the results after a round of play
                    for (int i = 0; i < SpaceRaceGame.NumberOfPlayers; i++)
                    {
                        Console.WriteLine("\t{0}  is now on square {1}, and has {2} yottawatt of power remaining",
                                          SpaceRaceGame.Players[i].Name, SpaceRaceGame.Players[i].Position, SpaceRaceGame.Players[i].RocketFuel);
                    }
                }


                if (SpaceRaceGame.SomeoneHasWon == true)
                {
                    DisplayResultsOfGame();
                }

                if (SpaceRaceGame.NoOneHasFuel == true)
                {
                    Console.WriteLine("\n\nThe Game is Over, because all players have run out of fuel!");
                    Console.ReadLine();
                }

                PromptForAnotherGame();
            } while (SpaceRaceGame.WantsToPlayAgain == true);


            PressEnter();
        }//end Main
Пример #28
0
        private void rollButton_Click(object sender, EventArgs e)
        {
            bool   gameEnd = false, stepEnd = false;
            string endTxt = "The following player(s) finished the game\n";

            numOfPlayersInput.Enabled = false;                       // disable comboBox
            UpdatePlayersGuiLocations(TypeOfGuiUpdate.RemovePlayer); // reset player locations

            // Play Single-step or One Round
            if (step)
            {
                countPlay++; // increment player to take a step

                // Reset player count if new round
                if (countPlay == SpaceRaceGame.NumberOfPlayers)
                {
                    countPlay = 0;
                }

                // Single-step for player
                SpaceRaceGame.StepPlayer(countPlay, die1, die2);

                // Player End test - Step Play
                if (SpaceRaceGame.Players[countPlay].AtFinish)
                {
                    endTxt += String.Format("\t{0}", SpaceRaceGame.names[countPlay]);
                    stepEnd = true;
                }

                // Game End test - Step Play
                if ((countPlay == (SpaceRaceGame.NumberOfPlayers - 1) && stepEnd))
                {
                    gameEnd = true;
                }
            }

            else
            {
                // Play One Round
                SpaceRaceGame.PlayOneRound(die1, die2);

                // Game End test - Play One Round
                for (int i = 0; i < SpaceRaceGame.NumberOfPlayers; i++)// for each player
                {
                    // Test if player is at Finish update endTxt and gameEnd
                    if (SpaceRaceGame.Players[i].AtFinish)
                    {
                        gameEnd = true;
                        endTxt += String.Format("\t{0}", SpaceRaceGame.names[i]);
                    }
                }
            }

            // Update player positions for StepPlay or PlayOneRound
            UpdatePlayersGuiLocations(TypeOfGuiUpdate.AddPlayer);
            // Update player data grid for StepPlay or PlayOneRound
            UpdatesPlayersDataGridView();


            // Game End Message
            if (gameEnd) // Show player finished method if any player Finishes
            {
                rollButton.Enabled = false;
                MessageBox.Show(endTxt);
            }

            resetButton.Enabled = true; // enable reset button at round start
        }// end rollButton_Click
Пример #29
0
        } //end UpdatePlayersGuiLocations

        /// <summary>
        /// Rolls the dice and updates the players on the board accordingly.
        /// If single step mode enabled every time Roll button is clicked
        /// it will move a single player until each player playing has been
        /// moved for the round. Then moves the first player again.
        /// Also checks each round if a player has finished if so disables
        /// the roll button and prints a message to the screen.
        /// </summary>
        private void RollButton_Click(object sender, EventArgs e)
        {
            playersDataGridView.ReadOnly = true;
            exitButton.Enabled           = false;
            RollButton.Enabled           = false;
            comboBox1.Enabled            = false;

            // If not using single step mode, each player moves at once.
            if (NoRadioButton.Checked || YesRadioButton.Checked == false)
            {
                UpdatePlayersGuiLocations(TypeOfGuiUpdate.RemovePlayer);
                SpaceRaceGame.PlayOneRound();
                UpdatePlayersGuiLocations(TypeOfGuiUpdate.AddPlayer);
                UpdatesPlayersDataGridView();
            }

            // If using single step mode, 1 player moves every time
            // the roll dice button is clicked.
            if (YesRadioButton.Checked)
            {
                if (appropriatePlayerSelection == SpaceRaceGame.NumberOfPlayers)
                {
                    appropriatePlayerSelection = 0;
                }
                UpdateSinglePlayerLocation(TypeOfGuiUpdate.RemovePlayer, appropriatePlayerSelection);
                SpaceRaceGame.PlayOneRound(singlePlayerMove, appropriatePlayerSelection);
                UpdateSinglePlayerLocation(TypeOfGuiUpdate.AddPlayer, appropriatePlayerSelection);
                UpdatesPlayersDataGridView();

                appropriatePlayerSelection++;
            }

            RollButton.Enabled = true;

            // The following code checks if a player has finished
            // or if all the players have run out fuel.
            bool   playerAtFinish  = false;
            bool   allPlayersOut   = false;
            string playersFinished = "\n\t";
            int    countPlayersOut = 0;

            for (int i = 0; i < SpaceRaceGame.NumberOfPlayers; i++)
            {
                if (SpaceRaceGame.Players[i].AtFinish)
                {
                    playerAtFinish   = true;
                    playersFinished += (SpaceRaceGame.Players[i].Name + "\n\t");
                }

                if (SpaceRaceGame.Players[i].HasPower == false)
                {
                    countPlayersOut++;
                    if (countPlayersOut >= SpaceRaceGame.NumberOfPlayers)
                    {
                        allPlayersOut = true;
                    }
                }
            }

            if (playerAtFinish || allPlayersOut)
            {
                // Disabled the roll button, enable exit and reset.
                EndOfGame();

                // This comes first as a player can be at the finish & out of fuel.
                if (playerAtFinish)
                {
                    MessageBox.Show("The following player(s) have finished the game:\n"
                                    + playersFinished);
                }
                else
                {
                    MessageBox.Show("All players have run out of fuel, there is no winner.");
                }
            }
        }
        /// <summary>
        /// Algorithm below currently plays only one game
        ///
        /// when have this working correctly, add the abilty for the user to
        /// play more than 1 game if they choose to do so.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)

        {
            DisplayIntroductionMessage();

            /*
             * Set up the board in Board class (Board.SetUpBoard)
             * Determine number of players - initally play with 2 for testing purposes
             * Create the required players in Game Logic class
             * and initialize players for start of a game
             * loop  until game is finished
             *  call PlayGame in Game Logic class to play one round
             *  Output each player's details at end of round
             * end loop
             * Determine if anyone has won
             * Output each player's details at end of the game
             */
            // INPUT CODE BELOW

            int game_state = 10;

            while (game_state != 0)
            {
                if (game_state == 10)       //First Round
                {
                    DisplayNumOfPlayerQuery();
                    Board.SetUpBoard();
                    SpaceRaceGame.Players.Clear();
                    SpaceRaceGame.SetUpPlayers();
                    DisplayFirstRoundMessage();     //First Round Message
                    SpaceRaceGame.PlayOneRound();
                    DisplayRoundDetails();
                    game_state = 1;
                }
                else if (game_state == 1)    //Next Round
                {
                    DisplayNextRoundMessage();
                    SpaceRaceGame.PlayOneRound();
                    if (SpaceRaceGame.GameFinish())
                    {
                        game_state = 2;
                    }
                    else
                    {
                        DisplayRoundDetails();
                    }
                }

                else if (game_state == 2)
                {
                    DisplayRoundDetailsWithWinner();
                    game_state = 3;
                }

                else if (game_state == 3)    // Prompt asking to play again
                {
                    DisplayPromptToPlayAgain();
                    char x = Char.Parse(Console.ReadLine());
                    if (x == 'Y' || x == 'y')
                    {
                        game_state = 10;
                        //Console.Write(game_state);
                    }

                    else if (x == 'N' || x == 'n')
                    {
                        game_state = 0;
                    }
                }
            }

            PressEnter();
        }//end Main