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);
                }
            }
        }
Beispiel #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);
                }
            }
        }