示例#1
0
        private void grdGame1_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (Game.GameIsStarted)
            {
                if (e.Source is Rectangle)
                {
                    if (Game.GameIsStarted)
                    {
                        Rectangle currentrct = (Rectangle)e.Source;
                        int       iLigne     = (int)currentrct.GetValue(Grid.RowProperty);
                        int       iColonne   = (int)currentrct.GetValue(Grid.ColumnProperty);

                        Game.playersMove(turn, iLigne, iColonne);
                        currentrct.Fill = turn == GameCst.O ? O : X;
                        if (turn == GameCst.O)
                        {
                            turn = GameCst.X;
                        }

                        else
                        {
                            turn = GameCst.O;
                        }
                        Game.CheckWinner();
                    }
                }
            }
        }
示例#2
0
        private void CheckWinner()
        {
            if (newgame.CheckWinner())
            {
                if (newgame.TurnProperty == 1)
                {
                    MessageBox.Show("Player 1 - " + player1.NameProperty + " Wins!");
                }
                else
                {
                    MessageBox.Show("Player 2 - " + player2.NameProperty + " Wins!");
                }

                const string message = "Do you want to play again?";
                const string caption = "Play Again";
                var          result  = MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (result == DialogResult.Yes)
                {
                    gameon = 0;
                    ChangeTurn();
                    ResetGame();
                    gameon = 1;
                }

                if (result == DialogResult.No)
                {
                    this.Close();
                }
            }
        }