示例#1
0
 private bool CheckSquaresSameColor(SquareViewModel s1, SquareViewModel s2, SquareViewModel s3, SquareViewModel s4)
 {
     if (s1 != null && s2 != null && s3 != null && s4 != null)
     {
         return(((int)currentPlayer == s1.Token) &&
                ((int)currentPlayer == s2.Token) &&
                ((int)currentPlayer == s3.Token) &&
                ((int)currentPlayer == s4.Token));
     }
     return(false);
 }
示例#2
0
        public void ClickBtnColumn(int column)
        {
            SquareViewModel s = GetEmptySquareInColumn(column);

            if (s != null)
            {
                s.Token = (int)currentPlayer;

                bool checkEndGame_CurrentPlayerWins = CheckEndGame_CurrentPlayerWins();
                bool checkEndGame_NoEmptySquares    = CheckEndGame_NoEmptySquares();

                if (checkEndGame_CurrentPlayerWins)
                {
                    string msg = "Red player wins!";
                    if (currentPlayer == TypeToken.TOKEN_BLACK)
                    {
                        msg = "Black player wins!";
                    }
                    MessageBox.Show(msg);
                    NuevoJuego();
                }
                else if (checkEndGame_NoEmptySquares)
                {
                    MessageBox.Show("Draw, Empate");
                    NuevoJuego();
                }
                else
                {
                    if (currentPlayer == TypeToken.TOKEN_BLACK)
                    {
                        currentPlayer = TypeToken.TOKEN_RED;
                    }
                    else
                    {
                        currentPlayer = TypeToken.TOKEN_BLACK;
                    }
                }

                if (SelectedOption == OPTION_ORDENADOR && currentPlayer == TypeToken.TOKEN_RED)
                {
                    OrdenadorIA ordenadorIA        = new OrdenadorIA(Squares, NumRows, NumColumns);
                    int         columnSelectedByIA = ordenadorIA.GetSelectedColumn();
                    //Random r = new Random();
                    //int columnSelectedByIA = 0;
                    //do
                    //{
                    //    columnSelectedByIA = r.Next(0, NumColumns);
                    //}
                    //while (GetEmptySquareInColumn(columnSelectedByIA) == null);
                    ClickBtnColumn(columnSelectedByIA);
                }
            }
        }
示例#3
0
        private bool CheckEndGame_CurrentPlayerWins()
        {
            for (int row = 0; row < NumRows; row++)
            {
                for (int col = 0; col < NumColumns; col++)
                {
                    //Horizontal
                    SquareViewModel s1H = GetSquare(row, col);
                    SquareViewModel s2H = GetSquare(row, col + 1);
                    SquareViewModel s3H = GetSquare(row, col + 2);
                    SquareViewModel s4H = GetSquare(row, col + 3);
                    bool            squaresSameColorH = CheckSquaresSameColor(s1H, s2H, s3H, s4H);
                    if (squaresSameColorH)
                    {
                        return(true);
                    }
                    //Vertical
                    SquareViewModel s1V = GetSquare(row, col);
                    SquareViewModel s2V = GetSquare(row + 1, col);
                    SquareViewModel s3V = GetSquare(row + 2, col);
                    SquareViewModel s4V = GetSquare(row + 3, col);
                    bool            squaresSameColorV = CheckSquaresSameColor(s1V, s2V, s3V, s4V);
                    if (squaresSameColorV)
                    {
                        return(true);
                    }

                    //Diagonal
                    SquareViewModel s1D = GetSquare(row, col);
                    SquareViewModel s2D = GetSquare(row + 1, col + 1);
                    SquareViewModel s3D = GetSquare(row + 2, col + 2);
                    SquareViewModel s4D = GetSquare(row + 3, col + 3);
                    bool            squaresSameColorD = CheckSquaresSameColor(s1D, s2D, s3D, s4D);
                    if (squaresSameColorD)
                    {
                        return(true);
                    }

                    //Diagonal2
                    SquareViewModel s1D2 = GetSquare(row, col);
                    SquareViewModel s2D2 = GetSquare(row + 1, col - 1);
                    SquareViewModel s3D2 = GetSquare(row + 2, col - 2);
                    SquareViewModel s4D2 = GetSquare(row + 3, col - 3);
                    bool            squaresSameColorD2 = CheckSquaresSameColor(s1D2, s2D2, s3D2, s4D2);
                    if (squaresSameColorD2)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
示例#4
0
        public SquareViewModel GetEmptySquareInColumn(int column)
        {
            SquareViewModel s = null;

            for (int row = NumRows - 1; row >= 0; row--)
            {
                if (GetSquare(row, column).Token == (int)TypeToken.TOKEN_NONE)
                {
                    s = GetSquare(row, column);
                    break;
                }
            }
            return(s);
        }
示例#5
0
 private bool CheckSquaresSameColor(SquareViewModel s1, SquareViewModel s2, SquareViewModel s3, SquareViewModel s4)
 {
     if (s1 != null && s2 != null && s3 != null && s4 != null)
     {
         return ((int)currentPlayer == s1.Token)
             && ((int)currentPlayer == s2.Token)
             && ((int)currentPlayer == s3.Token)
             && ((int)currentPlayer == s4.Token);
     }
     return false;
 }