Exemplo n.º 1
0
        private static void checkPopping(GridSquare tempGrid)
        {
            List <int[]> positions = new List <int[]>();

            if (tempGrid.y % 2 == 1)
            {
                positions.Add(new int[] { tempGrid.x, tempGrid.y - 1 });     //top left
                positions.Add(new int[] { tempGrid.x + 1, tempGrid.y - 1 }); //top right
                positions.Add(new int[] { tempGrid.x - 1, tempGrid.y });     //left
                positions.Add(new int[] { tempGrid.x + 1, tempGrid.y });     //right
                positions.Add(new int[] { tempGrid.x, tempGrid.y + 1 });     //bottom left
                positions.Add(new int[] { tempGrid.x + 1, tempGrid.y + 1 }); //bottom right
            }
            else
            {
                positions.Add(new int[] { tempGrid.x - 1, tempGrid.y - 1 }); //top left
                positions.Add(new int[] { tempGrid.x, tempGrid.y - 1 });     //top right
                positions.Add(new int[] { tempGrid.x - 1, tempGrid.y });     //left
                positions.Add(new int[] { tempGrid.x + 1, tempGrid.y });     //right
                positions.Add(new int[] { tempGrid.x - 1, tempGrid.y + 1 }); //bottom left
                positions.Add(new int[] { tempGrid.x, tempGrid.y + 1 });     //bottom right
            }

            for (int i = 0; i < positions.Count; i++)
            {
                if (positions[i][0] >= 0 && positions[i][0] <= grid.GetUpperBound(0) && positions[i][1] >= 0 && positions[i][1] <= grid.GetUpperBound(1))
                {
                    Bubble b = grid[positions[i][0], positions[i][1]].bubble;
                    if (b != null && b.getColor() == tempGrid.bubble.getColor() && !popped.Contains(b))
                    {
                        if (!popped.Contains(tempGrid.bubble))
                        {
                            popped.Add(tempGrid.bubble);
                        }
                        popped.Add(b);
                        checkPopping(grid[positions[i][0], positions[i][1]]);
                    }
                }
            }
        }