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(); } }
//Click the Roll Button private void clickRollButton_Click(Object sender, EventArgs e) { numplayerBox.Enabled = false; //Select Single Step Mode if (noButton.Checked == true) { stepGroupBox.Enabled = false; UpdatePlayersGuiLocations(TypeOfGuiUpdate.RemovePlayer); SpaceRaceGame.PlayOneRound(); round_play++; if (round_play > 0) { //Exit and Reset Buttons are enabled at the end of any round exitButton.Enabled = true; resetButton.Enabled = true; } //Update the position and fuel on the DataGridView for (int i = 0; i < SpaceRaceGame.NumberOfPlayers; i++) { playersDataGridView.Rows[i].Cells[2].Value = SpaceRaceGame.Players[i].Position; playersDataGridView.Rows[i].Cells[3].Value = SpaceRaceGame.Players[i].RocketFuel; if (SpaceRaceGame.Players[i].Position >= 55 && SpaceRaceGame.Players[i].RocketFuel > 0) { if (!players_win.Contains(SpaceRaceGame.Players[i])) { players_win.Add(SpaceRaceGame.Players[i]); } } else if (SpaceRaceGame.Players[i].Position < 55 && SpaceRaceGame.Players[i].RocketFuel == 0) { SpaceRaceGame.Players.RemoveAt(i); SpaceRaceGame.NumberOfPlayers--; num_death_player++; } } //Display the message box for the game winner(s) if (players_win.Count >= 1) { message_end_game(); } //All players run out of fuel before reaching the final square - Square if (num_death_player == SpaceRaceGame.NumberOfPlayers) { MessageBox.Show("No One Wins \n All Players Run Out Of Fuels"); rollButton.Enabled = false; numplayerBox.Enabled = false; resetButton.Enabled = true; stepGroupBox.Enabled = false; } //Update DataGridView UpdatesPlayersDataGridView(); UpdatePlayersGuiLocations(TypeOfGuiUpdate.AddPlayer); } //Select Not Single Step Mode else if (yesButton.Checked == true) { resetButton.Enabled = false; stepGroupBox.Enabled = false; exitButton.Enabled = false; UpdatePlayersGuiLocations(TypeOfGuiUpdate.RemovePlayer); //Play Single Step For Each Person SpaceRaceGame.PlaySingle(SpaceRaceGame.Players[count].Name); //Update the position and fuel on the DataGridView playersDataGridView.Rows[count].Cells[2].Value = SpaceRaceGame.Players[count].Position; playersDataGridView.Rows[count].Cells[3].Value = SpaceRaceGame.Players[count].RocketFuel; //Add game winners into the list players_win if (SpaceRaceGame.Players[count].Position >= 55 && SpaceRaceGame.Players[count].RocketFuel > 0) { if (!players_win.Contains(SpaceRaceGame.Players[count])) { players_win.Add(SpaceRaceGame.Players[count]); } } //Increment the number of death players and reset the count if any players run out of fuels //before reaching the final square else if (SpaceRaceGame.Players[count].Position < 55 && SpaceRaceGame.Players[count].RocketFuel == 0) { SpaceRaceGame.NumberOfPlayers--; num_death_player++; if (count == SpaceRaceGame.NumberOfPlayers) { count = 0; } } if (players_win.Count >= 1) { message_end_game(); } //Increment the turn in each single step count++; //If the count of clicking the roll button is equal to the number of players, reset //and increment the number of rounds if (count == SpaceRaceGame.NumberOfPlayers) { round_play++; if (round_play > 0) { //Exit and Reset Buttons are enabled at the end of any round exitButton.Enabled = true; resetButton.Enabled = true; } count = 0; } //If All Players Run Out Of Fuels - End Game if (SpaceRaceGame.NumberOfPlayers == 0) { MessageBox.Show("No One Wins \n All Players Run Out Of Fuels"); rollButton.Enabled = false; numplayerBox.Enabled = false; resetButton.Enabled = true; stepGroupBox.Enabled = false; } //Update DataGridView UpdatesPlayersDataGridView(); UpdatePlayersGuiLocations(TypeOfGuiUpdate.AddPlayer); } }