示例#1
0
    public void CalculateSameColorCluster()
    {
        m_SameColorClusters.Clear();
        ClearVisitedCellsForSeperatedCluster();
        List <IntVector2> coordsToVisit = new List <IntVector2>();
        IntVector2        startCoords   = new IntVector2(0, 0);

        while (FindNonAddedCoordForSeperated(out startCoords))
        {
            BubbleCluster bubbleCluster = new BubbleCluster();
            m_SameColorClusters.Add(bubbleCluster);
            coordsToVisit.Add(startCoords);
            Color InitColor = m_Grid[startCoords.x, startCoords.y].m_Color;

            while (coordsToVisit.Count > 0)
            {
                //Remove current cell from the list
                int        indexToRemove = coordsToVisit.Count - 1;
                IntVector2 currentCoords = coordsToVisit[indexToRemove];
                coordsToVisit.RemoveAt(indexToRemove);

                //Skip iteration if current coordinate/cell is already visited
                if (m_AddedBBForSeperatedCluster[currentCoords.x, currentCoords.y] == true)
                {
                    continue;
                }



                //Retrieve ClicableCube object based on current coordinates
                DestroyableBubble currentBubble = m_Grid[currentCoords.x, currentCoords.y];



                //Skip iteration if current bubble is not the same color with the shooting bubble
                if (currentBubble.m_Color != InitColor)
                {
                    continue;
                }

                //Add current ClicableCube to the cluster
                bubbleCluster.AddBubble(currentBubble);
                //Set status of the current cell to visited
                m_AddedBBForSeperatedCluster[currentCoords.x, currentCoords.y] = true;


                //Search around the current cell for enabled neighbour cells. If found add a coordinate to the need to visit container.
                AddCoordsIfNeeded(currentCoords, new IntVector2(1, 0), ref coordsToVisit);
                AddCoordsIfNeeded(currentCoords, new IntVector2(-1, 0), ref coordsToVisit);
                AddCoordsIfNeeded(currentCoords, new IntVector2(0, 1), ref coordsToVisit);
                AddCoordsIfNeeded(currentCoords, new IntVector2(0, -1), ref coordsToVisit);
                AddCoordsIfNeeded(currentCoords, new IntVector2(1, 1), ref coordsToVisit);
                AddCoordsIfNeeded(currentCoords, new IntVector2(-1, 1), ref coordsToVisit);
                AddCoordsIfNeeded(currentCoords, new IntVector2(-1, -1), ref coordsToVisit);
                AddCoordsIfNeeded(currentCoords, new IntVector2(1, -1), ref coordsToVisit);
            }
        }
    }
示例#2
0
    // Start is called before the first frame update
    void Start()
    {
        m_Grid = new DestroyableBubble[GridDimX, GridDimY];

        m_VisitedCells = new bool[GridDimX, GridDimY];
        m_AddedBBForSeperatedCluster = new bool[GridDimX, GridDimY];

        GenerateBubbles();

        m_DestroyedBBClusters = new BubbleCluster();
        m_SameColorClusters   = new List <BubbleCluster>();
        m_SeperatedClusters   = new List <BubbleCluster>();

        m_Turret = GameObject.FindGameObjectWithTag("Turret").GetComponent <Turret>();
    }