コード例 #1
0
        /// <summary>
        /// Called when the game is over.
        /// </summary>
        /// <param name="message"></param>
        public void GameOver(string message)
        {
            DrawBoard();
            message += "\n";
            message += $"The {game.GetWinner()} player won the game.\n";
            message += "Do you want to play again?";
            MessageBoxResult result = MessageBox.Show(message, "Game Over", MessageBoxButton.YesNo);

            if (result == MessageBoxResult.Yes)
            {
                NewGame();
            }
            else
            {
                // Used to avoid mutltithreading issue. An InvalidOperationException is thrown if
                // it is not secured with Dispatcher.Invoke.
                this.Dispatcher.Invoke(() =>
                {
                    Application.Current.Shutdown();
                });
            }
        }