static void Main(string[] args) { Console.WriteLine("\tWelcome to Space Race.\n"); do { //Setup the board Board.SetUpBoard(); //Displays the text "This game is for 2 to 6 players." and "How many players (2-6):" EnterPlayersText(); //Tries to parse the players text input into the numPlayers variable int numPlayers = TestPlayerTextInput(); //Sets the number of players to what the user inputted SpaceRaceGame.NumberOfPlayers = numPlayers; //Sets up the players giving them their names, positions, square and the amount of fuel they have SpaceRaceGame.SetUpPlayers(); //Plays the game PlayGame(); //Code only gets to this line when someone has won the game Console.WriteLine("\n\n\tPress Enter key to continue ...\n\n\n\n\n"); Console.ReadLine(); PlayAgain(); } while (exitGame == false); PressEnterToTerminate(); }//end Main
private void SingleStep(int playerNum) { if (this.eachStep == true) { for (int i = 0; i < SpaceRaceGame.NumberOfPlayers; i++) { prevSquare[i] = SpaceRaceGame.Players[i].Position; } eachStep = false; }// save previous position SquareControlAt(prevSquare[playerNum]).ContainsPlayers[playerNum] = false; // remove token SpaceRaceGame.PlayOneTurn(playerNum); if (SpaceRaceGame.Players[playerNum].RocketFuel == 0) { MessageBox.Show(string.Format("{0} has 0 fuel.", SpaceRaceGame.Players[playerNum].Name)); // check for 0 fuel } int onSquare = SpaceRaceGame.Players[playerNum].Position; SquareControlAt(onSquare).ContainsPlayers[playerNum] = true; // add token UpdatesPlayersDataGridView(); // update all RefreshBoardTablePanelLayout(); ToggleAll(false); EndGame(); WinnerMessage(EndGame()); } // end SingleStep() method
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; }
//All tokens move at once per turn private void MultiStep() { UpdatePlayersGuiLocations(TypeOfGuiUpdate.RemovePlayer); SpaceRaceGame.PlayOneRound(); UpdatePlayersGuiLocations(TypeOfGuiUpdate.AddPlayer); UpdatesPlayersDataGridView(); }
} //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
/// <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
private void GameResetButton_Click_1(object sender, EventArgs e) { // resets all the game state variables SpaceRaceGame.SomeoneHasWon = false; SpaceRaceGame.NoOneHasFuel = false; SpaceRaceGame.PlayerCounter = 0; // removes the players from the board, and resets all of their respective variables for (int i = 0; i < SpaceRaceGame.NumberOfPlayers; i++) { UpdatePlayersGuiLocations(TypeOfGuiUpdate.RemovePlayer); SpaceRaceGame.Players[i].Position = Board.START_SQUARE_NUMBER; SpaceRaceGame.Players[i].RocketFuel = Player.INITIAL_FUEL_AMOUNT; SpaceRaceGame.Players[i].Location = Board.StartSquare; SpaceRaceGame.Players[i].HasPower = true; } // resets the Single Step mode selection singleStepYesButton.Checked = false; singleStepNoButton.Checked = false; // resets the selection for the number of players to match the "Starting" condition comboBox1.Text = "6"; comboBox1.Enabled = true; // primes the game for gameplay DetermineNumberOfPlayers(); SpaceRaceGame.SetUpPlayers(); PrepareToPlay(); }
} // 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()
/// <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(); SpaceRaceGame.NumberOfPlayers = NumberOfPlayersInput(); SpaceRaceGame.SetUpPlayers(); StartRound(); string nextRound = YesNoInput(); // store user's input while (nextRound == "Y" || nextRound == "y") // Loop to check for next game { NextGame(); nextRound = YesNoInput(); } /* * 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 */ PressEnter(); // Enter to terminate Console.Read(); }//end Main
} //end DetermineNumberOfPlayers /// <summary> /// The players' tokens are placed on the Start square /// </summary> private void PrepareToPlay() { DetermineNumberOfPlayers(); UpdatePlayersGuiLocations(TypeOfGuiUpdate.RemovePlayer); SpaceRaceGame.SetUp(); InitGUIControls(); UpdatePlayersGuiLocations(TypeOfGuiUpdate.AddPlayer); } //end PrepareToPlay()
//Select the number of player in the combo box private void numplayerBox_SelectedIndexChanged(object sender, EventArgs e) { UpdatePlayersGuiLocations(TypeOfGuiUpdate.RemovePlayer); SpaceRaceGame.Players.Clear(); DetermineNumberOfPlayers(); SpaceRaceGame.SetUpPlayers(); UpdatePlayersGuiLocations(TypeOfGuiUpdate.AddPlayer); UpdatesPlayersDataGridView(); }
}//end DetermineNumberOfPlayers /// <summary> /// The players' tokens are placed on the Start square /// </summary> private void PrepareToPlayGame() { UpdatePlayersGuiLocations(TypeOfGuiUpdate.RemovePlayer); SpaceRaceGame.Players.Clear(); SetupPlayersDataGridView(); DetermineNumberOfPlayers(); SpaceRaceGame.SetUpPlayers(); UpdatePlayersGuiLocations(TypeOfGuiUpdate.AddPlayer); }//end PrepareToPlay()
} //end UpdatePlayersGuiLocations private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { comboBox1.Enabled = false; UpdatePlayersGuiLocations(TypeOfGuiUpdate.RemovePlayer); SpaceRaceGame.NumberOfPlayers = int.Parse(comboBox1.Text); SpaceRaceGame.SetUpPlayers(); UpdatesPlayersDataGridView(); UpdatePlayersGuiLocations(TypeOfGuiUpdate.AddPlayer); }
} //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 Main /// <summary> /// Display a welcome message to the console /// Pre: none. /// Post: A welcome message is displayed to the console. /// </summary> static void DisplayIntroductionMessage() { Console.Clear(); Console.WriteLine("\tWelcome to Space Race.\n"); Console.WriteLine("\tThis game is for 2 to 6 players."); Console.Write("\tHow many players (2-6): "); SpaceRaceGame.NumberOfPlayers = InputCheck(); Board.SetUpBoard(); SpaceRaceGame.SetUpPlayers(); } //end DisplayIntroductionMessage
} // end YesNoInput() returns user's input static void NextGame() { SpaceRaceGame.NumberOfPlayers = NumberOfPlayersInput(); for (int i = 0; i < SpaceRaceGame.NumberOfPlayers; i++) { SpaceRaceGame.Players.Clear(); // remove player for a new set } SpaceRaceGame.SetUpPlayers(); // sets up accordingly once cleared StartRound(); } // End NextGame()
}//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(); }
public SpaceRaceForm() { InitializeComponent(); Board.SetUpBoard(); ResizeGUIGameBoard(); SetUpGUIGameBoard(); SetupPlayersDataGridView(); DetermineNumberOfPlayers(); SpaceRaceGame.SetUpPlayers(); PrepareToPlay(); }
} // 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
// Play one turn if GameState is unfinished and singled step is enabled [OC] private void GUIPlayOneTurn() { if (SpaceRaceGame.GameState == -1) { btnRoll.Enabled = false; UpdatePlayersGuiLocations(TypeOfGuiUpdate.RemovePlayer); SpaceRaceGame.PlayOneTurn(); UpdatePlayersGuiLocations(TypeOfGuiUpdate.AddPlayer); UpdatesPlayersDataGridView(); btnRoll.Enabled = true; } }
public SpaceRaceForm() { InitializeComponent(); Board.SetUpBoard(); ResizeGUIGameBoard(); SetUpGUIGameBoard(); SetupPlayersDataGridView(); DetermineNumberOfPlayers(); SpaceRaceGame.SetUpPlayers(); PrepareToPlay(); resetButton.Enabled = false; rollDiceButton.Enabled = false; }
}//end DetermineNumberOfPlayers /// <summary> /// The players' tokens are placed on the Start square /// </summary> private void PrepareToPlayGame() { // More code will be needed here to deal with restarting // a game after the Reset button has been clicked. // // Leave this method with the single statement // until you can play a game through to the finish square // and you want to implement the Reset button event handler. // UpdatePlayersGuiLocations(TypeOfGuiUpdate.RemovePlayer); SpaceRaceGame.SetUpPlayers(); UpdatePlayersGuiLocations(TypeOfGuiUpdate.AddPlayer); }//end PrepareToPlay()
static void DisplayRanking() { //from : game logic - SpaceRaceGame //display for each player and wait for user to hit ENTER Console.WriteLine(SpaceRaceGame.DisplayGameResults()); Console.WriteLine("\tIndividual players finished at the locations specified."); foreach (Player player in SpaceRaceGame.Players) { Console.WriteLine(String.Format("\n\t\t{0} with {1} yottawatt of power at square {2}", player.Name, player.RocketFuel, player.Position)); } Console.WriteLine("\n\n\tPress Enter key to continue..."); Console.ReadLine(); }
/// <summary> /// Display the game results and /// wait for user to press enter key to advance /// </summary> static void PrintGameResults() { // Display Game Results Console.WriteLine(SpaceRaceGame.DisplayGameResults()); //Individual Results Console.WriteLine("\n\nIndividual players finished at the locations specified."); foreach (Player player in SpaceRaceGame.Players) { Console.WriteLine(String.Format("\n\n\n{0} with {1} yottawatt of power at square {2}", player.Name, player.RocketFuel, player.Position)); } // Wait for Enter Press Console.WriteLine("\n\n\nPress Enter key to continue..."); Console.ReadLine(); }
} //end initializeGlobalVariables /// <summary> /// This method employs the per player gameplay, selected /// from the radio button option "yes". Each click /// of the roll button acts on an individual player. /// /// Pre: Player selects "uyes" for the radio button option. /// Post: Game is evolved, per player, each time the roll button is pressed. /// </summary> /// /// <param name="gameEnd">The end game state.</param> /// <returns>Returns the game state.</returns> private bool GameEndReturn_PerPlayer(ref bool gameEnd) { // Reset player count if new round if (countPlayer == SpaceRaceGame.NumberOfPlayers) { countPlayer = 0; fuelEmptyCount = 0; } // test if the round has ended, to pass to the reset button if (countPlayer == SpaceRaceGame.NumberOfPlayers - 1) { roundEnd = true; } else { roundEnd = false; } // Single-step for player "CountPlayer" SpaceRaceGame.StepPlayer(countPlayer, die1, die2); // Player End test - Step Play if (SpaceRaceGame.Players[countPlayer].AtFinish) { endTxt += String.Format("\t{0}", SpaceRaceGame.names[countPlayer]); stepEnd = true; } // Game End test - Step Play if ((countPlayer == (SpaceRaceGame.NumberOfPlayers - 1) && stepEnd)) { gameEnd = true; } // if (SpaceRaceGame.Players[countPlayer].RocketFuel == 0) { fuelEmptyCount++; } countPlayer++; // increment player to take a step return(gameEnd); } //end GameEndReturn_PerPlayer
private void btGameReset_Click(object sender, EventArgs e) { rbtStepYes.Checked = false; rbtStepNo.Checked = false; cbNumberOfPlayers.Text = SpaceRaceGame.MAX_PLAYERS.ToString(); cbNumberOfPlayers.Enabled = true; UpdatePlayersGuiLocations(TypeOfGuiUpdate.RemovePlayer); DetermineNumberOfPlayers(); SpaceRaceGame.SetUpPlayers(); dgvPlayers.Enabled = true; btExit.Enabled = true; btGameReset.Enabled = true; btGameRoll.Enabled = false; gbSingleStep.Enabled = true; PrepareToPlay(); }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { // changes the number of players according to the new number in the combobox for (int i = 0; i < SpaceRaceGame.NumberOfPlayers; i++) { UpdatePlayersGuiLocations(TypeOfGuiUpdate.RemovePlayer); } // disables the combobox so the player can't change the number of players again comboBox1.Enabled = false; // re-initiates the process of counting the number of players and updates the GUI accordingly DetermineNumberOfPlayers(); SpaceRaceGame.SetUpPlayers(); UpdatePlayersGuiLocations(TypeOfGuiUpdate.AddPlayer); }
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()); } }
/// <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
private void DiceButton_Click(object sender, EventArgs e) { if (yesRadiobutton.Checked == true) // allow single step { SingleStep(playerStep); playerStep++; if (playerStep == SpaceRaceGame.NumberOfPlayers) { eachStep = true; resetButton.Enabled = true; exitButton.Enabled = true; playerStep = 0; // reset to first player's turn } else { for (int i = 0; i < SpaceRaceGame.NumberOfPlayers; i++) { if (SpaceRaceGame.Players[i].Position == Board.FINISH_SQUARE_NUMBER) { resetButton.Enabled = true; break; } else { resetButton.Enabled = false; } } // enable after game ends; } } if (noRadiobutton.Checked == true) { AllStep(); // all move at once } if (SpaceRaceGame.AllPlayerFuel() == true) { MessageBox.Show("All players has 0 fuel."); // if all players run out of fuel exitButton.Enabled = true; diceButton.Enabled = false; } }