コード例 #1
0
        private Point playPvP(Point pos, int row, int col, Player p1, Player p2)
        {
            bool tf = false; //tf la danh dung luat = true, sai luat || chua danh = false

            while (tf == false)
            {
                if (p1.GetTurn() == true && p1.GetClick() == true)
                {
                    cell[row, col].Fill = X;
                    p.X = row;
                    p.Y = col;
                    tf  = true;
                    player1.SetTurn(false);
                    player2.SetTurn(true);
                    check[row, col] = 1;
                }

                if (p2.GetTurn() == true && p2.GetClick() == true)
                {
                    cell[row, col].Fill = O;
                    tf = true;
                    player2.SetTurn(false);
                    player1.SetTurn(true);
                    check[row, col] = 2;
                }
            }
            return(pos);
        }
コード例 #2
0
        private void GridBC_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (tf == false) //chua ai win
            {
                int   row, col;
                Point a = LayToaDo(sender, e);
                row = Convert.ToInt32(a.Y);
                col = Convert.ToInt32(a.X);
                if (check[row, col] == 0) //o chua danh // X = 1 // O = 2
                {
                    try
                    {
                        if (player2.GetClick() == true)
                        {
                            player2.SetClick(false);
                            player1.SetClick(true);
                        }
                        else
                        {
                            player2.SetClick(true);
                            player1.SetClick(false);
                        }
                        switch (state)
                        {
                        case 1:
                        {
                            playPvP(a, row, col, player1, player2);
                            break;
                        }

                        case 2:
                        {
                            playPvB(a, row, col, player1, player2);
                            break;
                        }
                        }
                    }
                    catch (Exception) { }
                }
                //check here
                tf = isWin(row, col);
            }
        }
コード例 #3
0
ファイル: MainWindow.xaml.cs プロジェクト: HramHeo/VanDap
        private Point playPvP(Point pos, int row, int col, Player p1, Player p2)
        {
            bool tf = false; //tf la danh dung luat = true, sai luat || chua danh = false
            while (tf == false)
            {
                    if (p1.GetTurn() == true && p1.GetClick() == true)
                    {
                        cell[row, col].Fill = X;                    
                        p.X = row;
                        p.Y = col;                        
                        tf = true;
                        player1.SetTurn(false);
                        player2.SetTurn(true);
                        check[row, col] = 1;
                    }

                    if (p2.GetTurn() == true && p2.GetClick() == true)
                    {
                        cell[row, col].Fill = O;
                        tf = true;
                        player2.SetTurn(false);
                        player1.SetTurn(true);
                        check[row, col] = 2;
                    }
            }
            return pos;
        }