Ejemplo n.º 1
0
    //Checks a board state. Give it string parameters of "Row", "Column", "Diagonal", or "Draw". Dimension only matters for row and column checks
    //If Draw return a false, then something achieved victory
    private bool CheckBoardState(string check, int dimension)
    {
        if (check != "Row" && check != "Column" && check != "Diagonal" && check != "Draw")
        {
            Debug.LogError("Invalid board state to check");
            return(false);
        }

        if (check == "Row")
        {
            if (BoardState.CheckRow(dimension, (int)GameManager.CurrentPlayer))
            {
                return(true);
            }
            return(false);
        }


        else if (check == "Column")
        {
            if (BoardState.CheckColumn(dimension, (int)GameManager.CurrentPlayer))
            {
                return(true);
            }
            return(false);
        }

        else if (check == "Diagonal")
        {
            if (BoardState.CheckBackDiagonal((int)GameManager.CurrentPlayer))
            {
                return(true);
            }
            if (BoardState.CheckFrontDiagonal((int)GameManager.CurrentPlayer))
            {
                return(true);
            }
            return(false);
        }

        else if (check == "Draw")
        {
            for (int i = 0; i < BoardState.BoardDimension; i++)
            {
                if (BoardState.CheckColumn(i, (int)GameManager.Player.P1) || BoardState.CheckRow(i, (int)GameManager.Player.P1) ||
                    BoardState.CheckColumn(i, (int)GameManager.Player.P2) || BoardState.CheckRow(i, (int)GameManager.Player.P2))
                {
                    return(false);
                }
            }
            if (BoardState.CheckBackDiagonal((int)GameManager.CurrentPlayer) || BoardState.CheckFrontDiagonal((int)GameManager.CurrentPlayer))
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }

        return(false);
    }