Ejemplo n.º 1
0
        private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (isOnl == false)
            {
                #region offline

                # region nguoi choi
                if (numplayer == 2)
                {
                    var element = (UIElement)e.Source;

                    int    c    = Grid.GetColumn(element);
                    int    r    = Grid.GetRow(element);
                    string temp = "Column : ";
                    temp += c;
                    temp += "Row:";
                    temp += r;
                    if (chess_Board.Board[c, r] == 0 && winner == 0)
                    {
                        double width  = chessGrid.Width / 12;
                        double height = chessGrid.Height / 12;

                        chess_Board.play(c, r, activer);



                        if (chess_Board.checkWin(c, r) != 0)
                        {
                            MessageBox.Show("Winner is player" + activer);
                            winner = activer;
                        }
                        if (activer == 1)
                        {
                            activer = 2;
                        }
                        else
                        {
                            activer = 1;
                        }
                    }
                    else
                    {
                        if (winner == 0)
                        {
                            MessageBox.Show("o nay da duoc danh");
                        }
                        else
                        {
                            MessageBox.Show("da co nguoi thang cuoc");
                        }
                    }
                }
                #endregion

                # region may choi voi nguoi
                else
                {
                    if (activer == 1)
Ejemplo n.º 2
0
        public void play(chessBoard board)
        {
            if (isActi == false)
            {
                return;
            }
            else
            {
                //int count = 0;
                Cell check = null;
                for (int i = 0; i < 12; i++)
                {
                    for (int j = 0; j < 12; j++)
                    {
                        if (board.Board[i, j] != 0)
                        {
                            check = checkInLine(i, j, 4, board);
                            if (check == null)
                            {
                                check = checkDiagonalLine(i, j, 4, board);
                            }
                            if (check != null)
                            {
                                board.play(check.c, check.r, 2);
                                if (board.checkWin(check.c, check.r) == 1)
                                {
                                    isWin = true;
                                }
                                return;
                            }
                        }
                    }
                }
                if (check == null)
                {
                    for (int i = 0; i < 12; i++)
                    {
                        for (int j = 0; j < 12; j++)
                        {
                            if (board.Board[i, j] != 0)
                            {
                                check = checkInLine(i, j, 3, board);
                                if (check == null)
                                {
                                    check = checkDiagonalLine(i, j, 3, board);
                                }
                                if (check != null)
                                {
                                    board.play(check.c, check.r, 2);
                                    return;
                                }
                            }
                        }
                    }
                }
                if (check == null)
                {
                    for (int i = 0; i < 12; i++)
                    {
                        for (int j = 0; j < 12; j++)
                        {
                            if (board.Board[i, j] != 0)
                            {
                                check = checkInLine(i, j, 2, board);
                                if (check == null)
                                {
                                    check = checkDiagonalLine(i, j, 2, board);
                                }
                                if (check != null)
                                {
                                    board.play(check.c, check.r, 2);
                                    return;
                                }
                            }
                        }
                    }
                }
                if (check == null)
                {
                    for (int i = 0; i < 12; i++)
                    {
                        for (int j = 0; j < 12; j++)
                        {
                            if (board.Board[i, j] != 0)
                            {
                                check = checkInLine(i, j, 1, board);
                                if (check == null)
                                {
                                    check = checkDiagonalLine(i, j, 1, board);
                                }
                                if (check != null)
                                {
                                    board.play(check.c, check.r, 2);
                                    return;
                                }
                            }
                        }
                    }
                }

                isActi = false;
                return;
            }
        }
Ejemplo n.º 3
0
 public void play(chessBoard board)
 {
     if (isActi == false)
         return;
     else
     {
         //int count = 0;
         Cell check = null;
         for (int i = 0; i < 12; i++)
         {
             for (int j = 0; j < 12; j++)
             {
                 if (board.Board[i, j] != 0)
                 {
                     check = checkInLine(i, j, 4, board);
                     if (check == null)
                         check = checkDiagonalLine(i, j, 4, board);
                     if (check != null)
                     {
                         board.play(check.c, check.r, 2);
                         if (board.checkWin(check.c, check.r) == 1)
                             isWin = true;
                         return;
                     }
                 }
             }
         }
         if(check == null)
         {
             for (int i = 0; i < 12; i++)
                 for (int j = 0; j < 12; j++)
                 {
                     if (board.Board[i, j] != 0)
                     {
                         check = checkInLine(i, j, 3, board);
                         if (check == null)
                             check = checkDiagonalLine(i, j, 3, board);
                         if (check != null)
                         {
                             board.play(check.c, check.r, 2);
                             return;
                         }
                     }
                 }
         }
         if (check == null)
         {
             for (int i = 0; i < 12; i++)
             {
                 for (int j = 0; j < 12; j++)
                 {
                     if (board.Board[i, j] != 0)
                     {
                         check = checkInLine(i, j, 2, board);
                         if (check == null)
                             check = checkDiagonalLine(i, j, 2, board);
                         if (check != null)
                         {
                             board.play(check.c, check.r, 2);
                             return;
                         }
                     }
                 }
             }
         }
         if (check == null)
         {
             for (int i = 0; i < 12; i++)
                 for (int j = 0; j < 12; j++)
                 {
                     if (board.Board[i, j] != 0)
                     {
                         check = checkInLine(i, j, 1, board);
                         if (check == null)
                             check = checkDiagonalLine(i, j, 1, board);
                         if (check != null)
                         {
                             board.play(check.c, check.r, 2);
                             return;
                         }
                     }
                 }
         }
         
         isActi = false;
         return;
     }
 }