// =================================================================== // Event handlers for the form buttons. // =================================================================== // // Resets the game statistics when the "Reset" button is clicked. // private void resetButton_Click(object sender, System.EventArgs e) { // Prompt for confirmation. ConfirmDialog dlg = new ConfirmDialog("Reset statistics?"); if (dlg.ShowDialog(this) == DialogResult.Yes) { // Reset and display the statistics. this.statistics.Reset(); this.MapStatisticsToControls(); } dlg.Dispose(); }
// // Handles a window close request. If a game is active, it will prompt // for confirmation first. // private void ReversiForm_Closing(object sender, System.ComponentModel.CancelEventArgs e) { bool doClose = true; // Prompt for confirmation if a game is in progress. if (this.gameState != ReversiForm.GameState.GameOver) { // Create and show the confirm dialog, saving the result. ConfirmDialog dlg = new ConfirmDialog("Exit the program?"); if (dlg.ShowDialog(this) != DialogResult.Yes) doClose = false; dlg.Dispose(); } // Cancel the close request if necessary. if (!doClose) e.Cancel = true; }
// // Handles a "Resign Game" click. // private void resignGameMenuItem_Click(object sender, System.EventArgs e) { bool doEnd = true; // Prompt for confirmation if a game is in progress. if (this.gameState != ReversiForm.GameState.GameOver) { // Create and show the confirm dialog, saving the result. ConfirmDialog dlg = new ConfirmDialog("Resign this game?"); if (dlg.ShowDialog(this) != DialogResult.Yes) doEnd = false; dlg.Dispose(); } // End the game if the request was not cancelled. if (doEnd) { // Stop the computer move thread, if active. this.KillComputerMoveThread(); // Stop any active animation and reset the board display. this.StopMoveAnimation(); this.UnHighlightSquares(); this.UpdateBoardDisplay(); // End the game with the resignation flag set. this.EndGame(true); } }