Ejemplo n.º 1
0
    /*
     *  Checks for a match the given location
     *
     *  @param col
     *  @param row
     *  @param colIncrement
     *  @param rowIncrement
     *
     *  @return is there match?
     */
    private bool FindMatchAt(int col, int row, int colIncrement, int rowIncrement)
    {
        // Clears the previous possible match
        possibleCombo.Clear();

        int tempCol1 = col + colIncrement;
        int tempCol2 = col + (colIncrement * 2);
        int tempRow1 = row + rowIncrement;
        int tempRow2 = row + (rowIncrement * 2);

        int testValue = 0;
        int testLimit = 0;

        // Check for matches left/right
        if (colIncrement > rowIncrement)
        {
            testValue = col;
            testLimit = gameBoard.width - 2;
        }
        else
        {
            // Check for matches up/down
            testValue = row;
            testLimit = gameBoard.height - 2;
        }

        // Ensures no check happens outside the board
        if (testValue < testLimit)
        {
            // null pointer check
            if (gameBoard.allGameTiles[col, row] && gameBoard.allGameTiles[tempCol1, tempRow1] &&
                gameBoard.allGameTiles[tempCol2, tempRow2])
            {
                // Three tiles to compare
                GameTileBase currentTile = gameBoard.allGameTiles[col, row].GetComponent <GameTileBase>();
                GameTileBase otherTile1  = gameBoard.allGameTiles[tempCol1, tempRow1].GetComponent <GameTileBase>();
                GameTileBase otherTile2  = gameBoard.allGameTiles[tempCol2, tempRow2].GetComponent <GameTileBase>();

                // Checks if all are of same type
                if (currentTile.GetGameTileType() == otherTile1.GetGameTileType() &&
                    currentTile.GetGameTileType() == otherTile2.GetGameTileType())
                {
                    //Debug
                    //print(string.Format("[ {0} , {1}, {2} ]", currentTile.gameObject, otherTile1.gameObject, otherTile2.gameObject));
                    //print(string.Format("Col i = {0}, Row i = {1}", colIncrement, rowIncrement));
                    //print(string.Format("TempCol = {0}, TempRow = {1}, TempCol2 = {2}, TempRow2 = {3}", tempCol1, tempRow1, tempCol2, tempRow2));

                    // Add match to combo
                    GameObject[] combo = { currentTile.gameObject, otherTile1.gameObject, otherTile2.gameObject };
                    MakePossibleCombo(combo);
                    return(true);
                }
            }
        }
        return(false);
    }
Ejemplo n.º 2
0
    /*
     * Finds tiles to destroy by Avatar tile
     */
    private List <GameObject> GetAvatarMatches(GameObject tile)
    {
        GameTileBase tileScript = tile.GetComponent <GameTileBase>();

        List <GameObject> tiles = new List <GameObject>();

        if (!tile)
        {
            return(tiles);
        }

        GameTileType gameTileType = tileScript.GetGameTileType();

        print("Bending " + tile + " and " + gameTileType);

        for (int i = 0; i < gameBoard.width; i++)
        {
            for (int j = 0; j < gameBoard.height; j++)
            {
                // Checks for the avatar tile in list
                if (tileScript == gameBoard.allGameTiles[i, j].GetComponent <GameTileBase>())
                {
                    tiles.Add(gameBoard.allGameTiles[i, j]);
                    gameBoard.allGameTiles[tileScript.currentCol, tileScript.currentRow].GetComponent <GameTileBase>().SetHasMatched(true);
                }

                // Finds tiles of same game tile type
                if (gameBoard.allGameTiles[i, j].GetComponent <GameTileBase>().GetGameTileType() == gameTileType)
                {
                    tiles.Add(gameBoard.allGameTiles[i, j]);
                    gameBoard.allGameTiles[i, j].GetComponent <GameTileBase>().SetHasMatched(true);
                }

                // All tiles, if both are avtar
                else if (tileScript.GetTileType() == TileType.Avatar &&
                         tileScript.GetOtherTile().GetComponent <GameTileBase>().GetTileType() == TileType.Avatar)
                {
                    tiles.Add(gameBoard.allGameTiles[i, j]);
                    gameBoard.allGameTiles[i, j].GetComponent <GameTileBase>().SetHasMatched(true);
                }
            }
        }

        return(tiles);
    }
Ejemplo n.º 3
0
    /*
     * Check tile alignment
     *
     * @param passValue value to pass, for a true return
     *
     * @return has passed?
     */
    private bool CheckMatchAlignment(int passValue)
    {
        int numOfColTiles = 0;
        int numOfRowTiles = 0;

        if (!currentMatches[0])
        {
            return(false);
        }
        if (currentMatches[0].GetComponent <GameTileBase>())
        {
            GameTileBase firstTile = currentMatches[0].GetComponent <GameTileBase>();

            foreach (GameObject tile in currentMatches)
            {
                if (tile.GetComponent <GameTileBase>())
                {
                    GameTileBase gameTile = tile.GetComponent <GameTileBase>();

                    if (gameTile.GetGameTileType() == firstTile.GetGameTileType())
                    {
                        // Add to Col count
                        if (gameTile.currentCol == firstTile.currentCol)
                        {
                            numOfColTiles++;
                        }
                        // Add to Row count
                        if (gameTile.currentRow == firstTile.currentRow)
                        {
                            numOfRowTiles++;
                        }
                    }
                }
            }
        }

        if (numOfColTiles >= passValue || numOfRowTiles >= passValue)
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }