Exemplo n.º 1
0
        private void button_Click(object sender, EventArgs e)
        {
            //capture sender
            ticTacToeBtn t = (ticTacToeBtn)sender;

            if (xTurn)
            {
                t.Text      = "X";
                t.BackColor = Color.LightPink;
            }
            else
            {
                t.Text      = "O";
                t.BackColor = Color.LightBlue;
            }
            xTurn = !xTurn;

            t.Enabled = false;
            drawCount++;

            if (isWinner() == true)
            {
                MessageBox.Show("Winner!");
                resetBoard();
            }

            if (drawCount == 9 && isWinner() == false)
            {
                MessageBox.Show("its a draw");
                resetBoard();
            }
        }
Exemplo n.º 2
0
        public Form1()
        {
            InitializeComponent();
            ticTacToeBtn tic_btn = new ticTacToeBtn();

            int   x = 0, y = 0;
            Point loc = new Point(x, y);

            //initialize the grid with buttons
            for (int r = 0; r < 3; r++)
            {
                for (int c = 0; c < 3; c++)
                {
                    x          = 110 * r;
                    y          = 110 * c;
                    grid[r, c] = new ticTacToeBtn();
                    this.Controls.Add(grid[r, c]);
                    grid[r, c].Location = new Point(x, y);
                    grid[r, c].Click   += new EventHandler(button_Click);
                }

                y = 0;
            }
        }