示例#1
0
        // Get a list of indeies of bubbles that connect with new bubble and have the same color.
        private ArrayList GetAdjacentSameColorBubbles(IndexPair newBubbleIndex, BubbleColor color)
        {
            ArrayList bubbleIndexList = new ArrayList();

            bubbleIndexList.Add(newBubbleIndex);
            Stack bubbleIndexStack = new Stack();

            bubbleIndexStack.Push(newBubbleIndex);
            while (bubbleIndexStack.Count != 0)
            {
                IndexPair   current     = (IndexPair)bubbleIndexStack.Pop();
                IndexPair[] nearbyIndex = getAllNearbyIndex(current.X, current.Y);
                for (int i = 0; i <= 5; i++)
                {
                    if (!IndexCheck(nearbyIndex [i].X, nearbyIndex [i].Y))
                    {
                        continue;
                    }

                    Bubble bubble = bubbleMap [nearbyIndex [i].X, nearbyIndex [i].Y];
                    if (bubble == null || bubble.Color != color || bubbleIndexList.Contains(nearbyIndex [i]))
                    {
                        continue;
                    }

                    bubbleIndexStack.Push(nearbyIndex [i]);
                    bubbleIndexList.Add(nearbyIndex [i]);
                }
            }
            return(bubbleIndexList);
        }
示例#2
0
        private static Level ParseTextAsset(TextAsset levelAsset)
        {
            var columns = Context.Instance.Settings.Columns;
            var colors  = new List <BubbleColor[]>();
            var text    = levelAsset.text;
            var lines   = Regex.Split(text, "\n|\r|\r\n");

            foreach (var valueLine in lines)
            {
                if (string.IsNullOrWhiteSpace(valueLine))
                {
                    continue;
                }

                var values = Regex.Split(valueLine, ";");

                if (values.Length != columns)
                {
                    continue;
                }

                var row = new BubbleColor[columns];

                for (var i = 0; i < columns; i++)
                {
                    row[i] = Context.Instance.ColorCollection[values[i]];
                }

                colors.Add(row);
            }

            return(new Level
            {
                Rows = colors.Count,
                Columns = columns,
                Colors = colors.ToArray()
            });
        }
示例#3
0
 // Get color from BubbleColor enum type.
 public Color GetColor(BubbleColor bubbleColor)
 {
     return(colorTable [(int)bubbleColor]);
 }
示例#4
0
        // Get a random color.
        public Color GetRandomColor()
        {
            BubbleColor bubbleColor = GetRandomBubbleColor();

            return(GetColor(bubbleColor));
        }
示例#5
0
 public Bubble(int xIndex, int yIndex, BubbleColor color)
 {
     this.index = new IndexPair(xIndex, yIndex);
     this.color = color;
 }