} // 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> /// 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