Exemple #1
0
    /**
     * @brief This function is a recursive algorithm that destroys blocks that are within
     * a connection of three or greater. After all checks are completed, the game objects are destroyed.
     * */
    void floodfill(int side, int row, string rootObjectType)
    {
        //adds the trapezoid game object to the
        connectedGameObjectsRow.Add(row);
        connectedGameObjectsSide.Add(side);
        visited[side, row] = true;

        //Right Side
        if (side == 5)
        {
            int wrapAround = 0;
            if (grid [wrapAround, row] != null && grid [wrapAround, row].name ==
                rootObjectType && visited [wrapAround, row] == false)
            {
                floodfill(wrapAround, row, rootObjectType);
            }
        }
        else
        {
            if (grid [side + 1, row] != null && grid [side + 1, row].name ==
                rootObjectType && visited [side + 1, row] == false)
            {
                floodfill(side + 1, row, rootObjectType);
            }
        }

        //left side
        if (side == 0)
        {
            int leftWrapAround = 5;
            if (grid [leftWrapAround, row] != null && grid [leftWrapAround, row].name
                == rootObjectType && visited [leftWrapAround, row] == false)
            {
                floodfill(leftWrapAround, row, rootObjectType);
            }
        }
        else
        {
            if (grid [side - 1, row] != null && grid [side - 1, row].name
                == rootObjectType && visited [side - 1, row] == false)
            {
                floodfill(side - 1, row, rootObjectType);
            }
        }


        //down
        if (row > 0)
        {
            if (grid [side, row - 1] != null && grid [side, row - 1].name
                == rootObjectType && visited [side, row - 1] == false)
            {
                floodfill(side, row - 1, rootObjectType);
            }
        }

        //up
        if (row < 7)
        {
            if (grid [side, row + 1] != null && grid [side, row + 1].name
                == rootObjectType && visited [side, row + 1] == false)
            {
                floodfill(side, row + 1, rootObjectType);
            }
        }

        //Ending and checking
        if (side == enteringSide && row == enteringRow)
        {
            if (connectedGameObjectsRow.Count >= 3)
            {
                score += Mathf.CeilToInt(connectedGameObjectsRow.Count * 10f * Time.timeSinceLevelLoad);
                PauseManager.text.text = "" + score;
                for (int i = 0; i < connectedGameObjectsRow.Count; i++)
                {
                    if (grid[(int)connectedGameObjectsSide[i], (int)connectedGameObjectsRow[i]].transform.childCount > 3)
                    {
                        grid[(int)connectedGameObjectsSide[i], (int)connectedGameObjectsRow[i]].transform.GetChild(3).
                        SetParent(PauseManager.canvas.transform);
                    }
                    Destroy(grid[(int)connectedGameObjectsSide[i], (int)connectedGameObjectsRow[i]]);
                    EffectScript.playDestroy();
                    grid [(int)connectedGameObjectsSide [i], (int)connectedGameObjectsRow [i]] = null;
                }
            }


            //Resets the visited array and connected game objects array
            visited = new bool[6, 8];
            connectedGameObjectsRow  = new ArrayList();
            connectedGameObjectsSide = new ArrayList();
        }
    }
Exemple #2
0
    public void destroyAllAroundRegular(int side, int row)
    {
        int leftSide  = 0;
        int rightSide = 0;

        if (side == 0)
        {
            leftSide = 5;
        }
        else
        {
            leftSide = side - 1;
        }

        if (side == 5)
        {
            rightSide = 0;
        }
        else
        {
            rightSide = side + 1;
        }

        //Top left
        if (grid [leftSide, row + 1] != null)
        {
            connectedGameObjectsRow.Add(row + 1);
            connectedGameObjectsSide.Add(leftSide);
        }

        //Top Right
        if (grid [rightSide, row + 1] != null)
        {
            connectedGameObjectsRow.Add(row + 1);
            connectedGameObjectsSide.Add(rightSide);
        }

        //Left
        if (grid [leftSide, row] != null)
        {
            connectedGameObjectsRow.Add(row);
            connectedGameObjectsSide.Add(leftSide);
        }

        //Right
        if (grid [rightSide, row] != null)
        {
            connectedGameObjectsRow.Add(row);
            connectedGameObjectsSide.Add(rightSide);
        }

        //Bottom Left
        if (grid [leftSide, row - 1] != null)
        {
            connectedGameObjectsRow.Add(row - 1);
            connectedGameObjectsSide.Add(leftSide);
        }

        //Bottom Middle
        if (grid [side, row - 1] != null)
        {
            connectedGameObjectsRow.Add(row - 1);
            connectedGameObjectsSide.Add(side);
        }

        //Bottom Right
        if (grid [rightSide, row - 1] != null)
        {
            connectedGameObjectsRow.Add(row - 1);
            connectedGameObjectsSide.Add(rightSide);
        }

        score += Mathf.CeilToInt(connectedGameObjectsRow.Count * 10f * Time.timeSinceLevelLoad);
        PauseManager.text.text = "" + score;

        for (int i = 0; i < connectedGameObjectsRow.Count; i++)
        {
            if (grid[(int)connectedGameObjectsSide[i], (int)connectedGameObjectsRow[i]].transform.childCount > 3)
            {
                grid[(int)connectedGameObjectsSide[i], (int)connectedGameObjectsRow[i]].transform.GetChild(3).
                SetParent(PauseManager.canvas.transform);
            }
            Destroy(grid[(int)connectedGameObjectsSide[i], (int)connectedGameObjectsRow[i]]);
            EffectScript.playDestroy();
            grid [(int)connectedGameObjectsSide [i], (int)connectedGameObjectsRow [i]] = null;
        }

        connectedGameObjectsRow  = new ArrayList();
        connectedGameObjectsSide = new ArrayList();

        ContinueFlowOfGame();
    }