Example #1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var clickedButton = sender as Button;

            if (!tempContent && !string.IsNullOrEmpty(clickedButton.Content.ToString()) || gameController.GameOver)
            {
                return; //this square already taken or game is over
            }

            clickedButton.Content    = gameController.GetPlayer();
            tempContent              = false;
            clickedButton.Foreground = Brushes.Purple;
            string buttonName = clickedButton.Name;

            gameController.Game_grid[getXCoordinate(buttonName), getYCoordinate(buttonName)] = gameController.GetPlayer();

            if (gameController.IsGameOver())
            {
                gameController.GameOver = true;
                gameController.DeclareWinner(clickedButton.Content.ToString());
                HighlightWinningCells();
                gameController.ResetButtonLabel = "Play Again";
            }
            else
            {
                gameController.SwitchPlayer();
            }
        }