Пример #1
0
        private void RemoveRandomFromBoard(int removedIndex)
        {
            var deleter = new DeleteBubbleAction();
            var placer  = new PlaceBubbleAction();

            var allRandomBubbles = GetAllRandomBubbles();

            manipulator.PushState();

            foreach (var bubble in allRandomBubbles)
            {
                var modifier      = bubble.modifiers.First(m => m.type == BubbleModifierType.Random);
                var modifierIndex = int.Parse(modifier.data);

                if (modifierIndex == removedIndex)
                {
                    // Delete randoms that were part of this group
                    deleter.Perform(manipulator, bubble.X, bubble.Y);
                }
                else if (modifierIndex > removedIndex)
                {
                    // Shift higher random groups down to fill the gap
                    modifier.data = (modifierIndex - 1).ToString();
                    manipulator.SetBubbleType(bubble.Type);
                    placer.Perform(manipulator, bubble.X, bubble.Y);
                }
            }

            manipulator.PopState();
        }
        private void ApplyTransformation(LevelManipulator manipulator, BubbleTransformation transformation)
        {
            var placer = new PlaceBubbleAction();

            manipulator.PushState();

            foreach (var bubble in savedState)
            {
                if (manipulator.Models.ContainsKey(bubble.Key))
                {
                    var replacement = transformation(bubble);

                    manipulator.Models[replacement.Key] = replacement;
                    manipulator.SetBubbleType(replacement.Type);
                    placer.Perform(manipulator, replacement.X, replacement.Y);
                }
            }

            manipulator.PopState();
        }