示例#1
0
        private void panel1_Paint(object sender, PaintEventArgs e) //create the board
        {
            Graphics gr = panel1.CreateGraphics();

            grapP = new GraphicsPart(gr);
            board = new Board();
            board.initializeBoard();
        }
示例#2
0
 public void reset() //resets the board
 {
     holders = new Holder[3, 3];
     initializeBoard();
     GraphicsPart.setUpCanvas();
     steps = 0;
     if (getWinner() == X || getWinner() == B)
     {
         turn = X;
     }
     else
     {
         turn = O;
     }
     winner = B;
 }
示例#3
0
        public void move(int x, int y) //move function for acting
        {
            if (steps % 2 == 0)        //X's turn
            {
                if (holders[x, y].getValue() != O)
                {
                    GraphicsPart.drawX(new Point(x, y));
                    holders[x, y].setValue(X);
                    steps++;//with every click increment moves
                    turn = O;
                    if (detectRow())
                    {
                        MessageBox.Show("X has won!");
                        winner = X;
                        reset();
                    }
                }
            }
            else //O's turn
            {
                if (holders[x, y].getValue() != X)
                {
                    GraphicsPart.drawO(new Point(x, y));
                    holders[x, y].setValue(O);
                    steps++;//with every click increment moves
                    turn = X;
                    if (detectRow())
                    {
                        MessageBox.Show("O has won!");
                        winner = O;
                        reset();
                    }
                }
            }

            if (steps == 9 && detectRow() == false) //DRAW
            {
                MessageBox.Show("It's a draw!");
                winner = B;
                reset();
            }
        }