} // end exitButton_Click /// <summary> /// Handles the Roll Dice button being clicked /// Pre: Roll Dice button is clicked /// Post: The game runs according to the specified versions ('Single Step' or 'All Together') /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void rollDiceButton_Click(object sender, EventArgs e) { int numberOfPlayers = GetNumberOfPlayers(); bool finished = false; if (noRadiobutton.Checked == true) { UpdatePlayersGuiLocations(TypeOfGuiUpdate.RemovePlayer); for (int i = 0; i < numberOfPlayers; i++) { HareAndTortoiseGame.PlayOneRound(HareAndTortoiseGame.Players, i); HareAndTortoiseGame.SetInactivePlayers(numberOfPlayers); } // end for UpdatePlayersGuiLocations(TypeOfGuiUpdate.AddPlayer); finished = HareAndTortoiseGame.AllPlayerFinished(numberOfPlayers); if (finished == true) { DisableRollDiceButton(); DisableNextPlayerButton(); HareAndTortoiseGame.IdentifyWinner(numberOfPlayers); } // end if RefreshPlayersInfoInDataGridView(); } // end if } // end rollDiceButton_Click
/// <summary> /// Constructor with initialising parameters. /// Pre: none. /// Post: the form is initialised, ready for the game to start. /// </summary> public HareAndTortoiseForm() { InitializeComponent(); HareAndTortoiseGame.NumberOfPlayers = HareAndTortoiseGame.MAX_PLAYERS; // Max players, by default. HareAndTortoiseGame.InitialiseAllThePlayers(); Board.SetUpBoard(); SetupTheGui(); ResetGame(); } // end form constructor
/// <summary> /// Handle the Next Players Roll button being clicked. /// Pre: the Next Players Roll button is clicked. /// Post: based on single move animation, plays one round of the game. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnNextPlayersRoll_Click(object sender, EventArgs e) { SingleStepAnimation(TypeOfGuiUpdate.RemovePlayer); HareAndTortoiseGame.PlayOneRound(); SingleStepAnimation(TypeOfGuiUpdate.AddPlayer); if (HareAndTortoiseGame.Finished) { btnNextPlayersRoll.Enabled = false; } }
/// <summary> /// Handle the Roll Dice button being clicked. /// Pre: the Roll Dice button is clicked. /// Post: plays one round of the game. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnRollDice_Click(object sender, EventArgs e) { UpdatePlayersGuiLocations(TypeOfGuiUpdate.RemovePlayer); HareAndTortoiseGame.PlayOneRound(); UpdatePlayersGuiLocations(TypeOfGuiUpdate.AddPlayer); if (HareAndTortoiseGame.Finished) { btnRollDice.Enabled = false; } }
/// <summary> /// Resets the game, including putting all the players on the Start square. /// This requires updating what is displayed in the GUI, /// as well as resetting the attrtibutes of HareAndTortoiseGame . /// This method is used by both the Reset button and /// when a new value is chosen in the Number of Players ComboBox. /// Pre: none. /// Post: the form displays the game in the same state as when the program first starts /// (except that any user names that the player has entered are not reset). /// </summary> private void ResetGame() { // removes players from the board ResetPlayersInfoInDataGridView(); UpdatePlayersGuiLocations(TypeOfGuiUpdate.RemovePlayer); // places players location at the start of the board HareAndTortoiseGame.SetPlayersAtTheStart(); // resets game controls groupBox1.Visible = true; // adds all players the board UpdatePlayersGuiLocations(TypeOfGuiUpdate.AddPlayer); }
/// <summary> /// The event handler for Timer /// Pre: The Roll Dice button is clicked /// Post: Timer starts ticking /// When the player reaches the specified square, it stops ticking /// NOTE: This method involves with animation /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void timer_Tick(object sender, EventArgs e) { int numberOfPlayers = GetNumberOfPlayers(); int diceResultNumber = HareAndTortoiseGame.GetDiceResult(playerNumber); bool finished = false; tickCounter[tick] = diceResultNumber; tick++; UpdateSinglePlayerGuiLocation(TypeOfGuiUpdate.RemovePlayer, playerNumber); HareAndTortoiseGame.MoveSingleSquare(playerNumber); UpdateSinglePlayerGuiLocation(TypeOfGuiUpdate.AddPlayer, playerNumber); if (HareAndTortoiseGame.Players[playerNumber].Location == Board.FinishSquare) { StopTimer(); EnableResetButton(); RefreshPlayersInfoInDataGridView(); EnableNextPlayerButton(); tick = 0; } else if (tick == tickCounter[0]) { HareAndTortoiseGame.CheckMoney(playerNumber); if (HareAndTortoiseGame.Players[playerNumber].Location.Name == "LotteryWin") { tick = tick - 1; } else { StopTimer(); EnableResetButton(); RefreshPlayersInfoInDataGridView(); EnableNextPlayerButton(); tick = 0; } } // end if finished = HareAndTortoiseGame.AllPlayerFinished(numberOfPlayers); if (finished == true) { DisableRollDiceButton(); DisableNextPlayerButton(); HareAndTortoiseGame.IdentifyWinner(numberOfPlayers); } // end if RefreshPlayersInfoInDataGridView(); } // end timer_Tick
} // end SetupPlayersDataGridView /// <summary> /// Resets the game, including putting all the players on the Start square. /// This requires updating what is displayed in the GUI, /// as well as resetting the attrtibutes of HareAndTortoiseGame . /// This method is used by both the Reset button and /// when a new value is chosen in the Number of Players ComboBox. /// Pre: none. /// Post: the form displays the game in the same state as when the program first starts /// (except that any user names that the player has entered are not reset). /// </summary> private void ResetGame() { // ########################### Code needs to be written ############################################## UpdatePlayersGuiLocations(TypeOfGuiUpdate.RemovePlayer); HareAndTortoiseGame.SetPlayersAtTheStart(); UpdatePlayersGuiLocations(TypeOfGuiUpdate.AddPlayer); SetMaxNumberOfPlayers(); DisableRollDiceButton(); ClearRadioButtons(); EnableSingleStepGroupBox(); DisableNextPlayerButton(); MakeNextPlayerButtonInvisible(); RefreshPlayersInfoInDataGridView(); playerNumber = HareAndTortoiseGame.FIRST_PLAYER_NUMBER - 1; } // end ResetGame
} // end resetButton_Click /// <summary> /// Handles the Number of Players combobox being selected /// Pre: Number of players is selected /// Post: The game runs with specified number of players /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void numberOfPlayersComboBox_SelectedIndexChanged(object sender, EventArgs e) { int numberOfPlayers = GetNumberOfPlayers(); UpdatePlayersGuiLocations(TypeOfGuiUpdate.RemovePlayer); HareAndTortoiseGame.SetPlayersAtTheStart(numberOfPlayers); HareAndTortoiseGame.SetInactivePlayers(numberOfPlayers); UpdatePlayersGuiLocations(TypeOfGuiUpdate.AddPlayer); playerNumber = HareAndTortoiseGame.FIRST_PLAYER_NUMBER - 1; EnableSingleStepGroupBox(); ClearRadioButtons(); DisableNextPlayerButton(); MakeNextPlayerButtonInvisible(); DisableRollDiceButton(); RefreshPlayersInfoInDataGridView(); } // end numberOfPlayersComboBox_SelectedIndexChanged
/// <summary> /// Resets the game, including putting all the players on the Start square. /// This requires updating what is displayed in the GUI, /// as well as resetting the attrtibutes of HareAndTortoiseGame . /// This method is used by both the Reset button and /// when a new value is chosen in the Number of Players ComboBox. /// Pre: none. /// Post: the form displays the game in the same state as when the program first starts /// (except that any user names that the player has entered are not reset). /// </summary> private void ResetGame() { // ########################### Code needs to be written ############################################### //UpdatePlayersGuiLocations(TypeOfGuiUpdate.RemovePlayer); cbPlayers.SelectedItem = HareAndTortoiseGame.NumberOfPlayers; HareAndTortoiseGame.SetPlayersAtTheStart(); cbPlayers.SelectedItem = HareAndTortoiseGame.NumberOfPlayers; btnRollDice.Enabled = true; UpdatePlayersGuiLocations(TypeOfGuiUpdate.AddPlayer); foreach (Player player in HareAndTortoiseGame.Players) { player.Money = 100; player.Winner = false; } RefreshPlayersInfoInDataGridView(); }