Ejemplo n.º 1
0
    /*
     * Refill board coroutine
     *
     */
    private IEnumerator RefillBoard_cor()
    {
        RefillBorad();          // Refill board

        yield return(new WaitForSeconds(destructionWaitTime));

        // Looks for matches
        if (CheckForMatches())
        {
            // Destroy and recursion
            isMatching = false;
            MatchedCoroutine();
        }
        else
        {
            // Clears the current match
            matchesManager.currentMatches.Clear();
            currentTile = null;

            // Deadlock check
            if (deadlock.IsGameDeadlocked())
            {
                deadlock.ShuffleBoard();
                yield return(new WaitForSeconds(destructionWaitTime * 2f));

                isMatching = false;
                MatchedCoroutine();
            }
            else
            {
                currentPlayerState = PlayerState.Active;
                isMatching         = false;
            }
        }
    }
Ejemplo n.º 2
0
    /*
     * Match Avatar Tile
     *
     * @param tiles
     */
    public void MatchAvatarTile(GameObject tile)
    {
        GameTileType tempTileType = tile.GetComponent <GameTileBase>().GetGameTileType();

        for (int i = 0; i < gameBoard.width; i++)
        {
            for (int j = 0; j < gameBoard.height; j++)
            {
                if (gameBoard.allGameTiles[i, j])
                {
                    GameTileBase tempTile = gameBoard.allGameTiles[i, j].GetComponent <GameTileBase>();

                    // Match all tiles
                    if (tile.GetComponent <GameTileBase>().GetTileType() == TileType.Avatar)
                    {
                        tempTile.SetHasMatched(true);
                    }

                    // Finds tile of same type
                    else if (gameBoard.allGameTiles[i, j].GetComponent <GameTileBase>().GetGameTileType() == tempTileType)
                    {
                        ChainSpecialMatches(tempTile.gameObject);

                        tempTile.SetHasMatched(true);
                    }
                }
            }
        }
    }
Ejemplo n.º 3
0
    /*
     * Check if matches are on board
     */
    private bool AreMatchesOnBoard()
    {
        for (int i = 0; i < gameBoard.width; i++)
        {
            for (int j = 0; j < gameBoard.height; j++)
            {
                if (gameBoard.allGameTiles[i, j])
                {
                    GameTileBase currentTile = gameBoard.allGameTiles[i, j].GetComponent <GameTileBase>();

                    if (gameBoard.allGameTiles[i, j].GetComponent <GameTileBase>().GetTileType() == TileType.Avatar)
                    {
                        return(true);
                    }

                    if (i < gameBoard.width - 2)
                    {
                        if (FindMatchAt(i, j, 1, 0))
                        {
                            return(true);
                        }
                    }
                }

                if (j < gameBoard.height - 2)
                {
                    if (FindMatchAt(i, j, 0, 1))
                    {
                        return(true);
                    }
                }
            }
        }
        return(false);
    }
Ejemplo n.º 4
0
    /*
     * Makes Avatar tile
     */
    public void MakeAvatarTileCheck()
    {
        if (gameBoard.currentTile)
        {
            // Turn current tile into Avatar
            if (gameBoard.currentTile.GetHasMatched() && gameBoard.currentTile.GetTileType() == TileType.Normal)
            {
                gameBoard.currentTile.SetHasMatched(false);
                currentMatches.Remove(gameBoard.currentTile.gameObject);
                gameBoard.currentTile.GenerateAvatarTile();
            }
            // Turn other tile into Avatar
            else if (gameBoard.currentTile.GetOtherTile())
            {
                if (gameBoard.currentTile.GetOtherTile().GetComponent <GameTileBase>())
                {
                    GameTileBase otherTile = gameBoard.currentTile.GetOtherTile().GetComponent <GameTileBase>();

                    if (otherTile.GetHasMatched() && otherTile.GetTileType() == TileType.Normal)
                    {
                        otherTile.SetHasMatched(false);
                        otherTile.GenerateAvatarTile();
                    }
                }
            }
        }
    }
Ejemplo n.º 5
0
    /*
     * Shuffles the board
     */
    public void ShuffleBoard()
    {
        // New collection to store tiles in
        List <GameObject> newTilesCollection = new List <GameObject>();

        // Gets all the pieces on the board
        for (int i = 0; i < gameBoard.width; i++)
        {
            for (int j = 0; j < gameBoard.height; j++)
            {
                if (gameBoard.allGameTiles[i, j])
                {
                    newTilesCollection.Add(gameBoard.allGameTiles[i, j]);
                }
            }
        }

        // Shuffle the new board
        for (int i = 0; i < gameBoard.width; i++)
        {
            for (int j = 0; j < gameBoard.height; j++)
            {
                int newIndex = Random.Range(0, newTilesCollection.Count);

                // Use a similiar check to ensure that the board doesn't shuffle into an immediate match
                GameTileType tempGameTileType = newTilesCollection[newIndex].GetComponent <GameTileBase>().GetGameTileType();

                int maxLoops = 0;

                while (gameBoard.CheckSetUpMatch(i, j, tempGameTileType) && maxLoops < 25)
                {
                    newIndex = Random.Range(0, newTilesCollection.Count);
                    maxLoops++;
                }

                GameTileBase tileScript = newTilesCollection[newIndex].GetComponent <GameTileBase>();

                // Assigns variables to the tiles new position
                tileScript.currentCol        = i;
                tileScript.currentRow        = j;
                gameBoard.allGameTiles[i, j] = newTilesCollection[newIndex];

                newTilesCollection.Remove(newTilesCollection[newIndex]);
            }
        }

        // Deadlock Check
        if (IsGameDeadlocked())
        {
            ShuffleBoard();
            return;
        }
        else
        {
            // immediately check for matches
            matchesManager.CheckForMatches();
        }
    }
Ejemplo n.º 6
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.º 7
0
    /*
     * Match single Glider Tile
     *
     * @param tiles
     */
    private void MatchGliderTile(GameObject tile)
    {
        if (tile)
        {
            if (tile.GetComponent <GameTileBase>())
            {
                GameTileBase tempTile = tile.GetComponent <GameTileBase>();

                if (tempTile.GetTileType() == TileType.Glider)
                {
                    GetGliderMatches(tile, tempTile.currentCol, tempTile.currentRow);
                }
            }
        }
    }
Ejemplo n.º 8
0
    /*
     * Makes char tile
     *
     */
    public void MakeCharTileCheck()
    {
        if (gameBoard.currentTile)
        {
            // Turn current tile into Char
            if (gameBoard.currentTile.GetHasMatched() && gameBoard.currentTile.GetTileType() == TileType.Normal)
            {
                gameBoard.currentTile.SetHasMatched(false);
                currentMatches.Remove(gameBoard.currentTile.gameObject);

                if (gameBoard.currentTile.swipeDirection == SwipeDirection.Left ||
                    gameBoard.currentTile.swipeDirection == SwipeDirection.Right)
                {
                    gameBoard.currentTile.GenerateCharTile(true);
                }
                else
                {
                    gameBoard.currentTile.GenerateCharTile(false);
                }
            }

            // Turn other tile into Char
            else if (gameBoard.currentTile.GetOtherTile())
            {
                if (gameBoard.currentTile.GetOtherTile().GetComponent <GameTileBase>())
                {
                    GameTileBase otherTile = gameBoard.currentTile.GetOtherTile().GetComponent <GameTileBase>();

                    if (otherTile.GetHasMatched() && otherTile.GetTileType() == TileType.Normal)
                    {
                        otherTile.SetHasMatched(false);
                        currentMatches.Remove(gameBoard.currentTile.gameObject);

                        if (gameBoard.currentTile.swipeDirection == SwipeDirection.Left ||
                            gameBoard.currentTile.swipeDirection == SwipeDirection.Right)
                        {
                            gameBoard.currentTile.GenerateCharTile(true);
                        }
                        else
                        {
                            gameBoard.currentTile.GenerateCharTile(false);
                        }
                    }
                }
            }
        }
    }
Ejemplo n.º 9
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.º 10
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);
        }
    }