Ejemplo n.º 1
0
        public void Explode(Bubble bubble)
        {
            var x     = bubble.X;
            var y     = bubble.Y;
            var power = bubble.Power;

            merged.Add(bubble);
            for (int bubbleSide = 0; bubbleSide < SIDES_COUNT; bubbleSide++)
            {
                var link = bubble.GetLinked((BubbleSide)bubbleSide);
                if (!link)
                {
                    continue;
                }
                if (!merged.Contains(link))
                {
                    merged.Add(link);
                }
            }

            CheckMergedFall();

            for (int i = merged.Count - 1; i >= 0; i--)
            {
                ReleaseBubble(merged[i]);
            }

            OnExplosion?.Invoke(new ExplosionInfo()
            {
                x     = x,
                y     = y,
                power = power
            });
        }
Ejemplo n.º 2
0
        private void CheckAttachedToTop(Bubble bubble, ref bool attached)
        {
            if (bubble == null || merged.Contains(bubble))
            {
                return;
            }

            for (int i = 0; i < SIDES_COUNT; i++)
            {
                var bubbleSide = i;
                var link       = bubble.GetLinked((BubbleSide)bubbleSide);
                if (link == null || merged.Contains(link))
                {
                    continue;
                }

                if (link.Y == maxY - 1)
                {
                    attached = true;
                    break;
                }
                if (!askedAttached.Contains(link))
                {
                    askedAttached.Add(link);
                    CheckAttachedToTop(link, ref attached);
                }
            }
        }
Ejemplo n.º 3
0
        private void GetAllLinks(Bubble bubble, List <Bubble> buffer)
        {
            for (int i = 0; i < SIDES_COUNT; i++)
            {
                var bubbleSide = i;
                var link       = bubble.GetLinked((BubbleSide)bubbleSide);

                if (link == null || buffer.Contains(link) || merged.Contains(link))
                {
                    continue;
                }

                buffer.Add(link);
                GetAllLinks(link, buffer);
            }
        }
Ejemplo n.º 4
0
        private void CheckBubblePower(Bubble prevBubble, Bubble bubble, List <Bubble> linked)
        {
            for (int i = 0; i < SIDES_COUNT; i++)
            {
                var bubbleSide = i;
                var link       = bubble.GetLinked((BubbleSide)bubbleSide);

                if (link == null || link.Power != bubble.Power || prevBubble == link)
                {
                    continue;
                }

                if (!linked.Contains(link))
                {
                    linked.Add(link);
                    CheckBubblePower(bubble, link, linked);
                }
            }
        }