예제 #1
0
 internal BubblesTask(BubblesTaskType taskType, bool isUndo, Func <IEnumerable <BubbleViewModel> > getBubbles, Action complete)
 {
     this.TaskType = taskType;
     this.IsUndo   = isUndo;
     _getBubbles   = getBubbles;
     this.Complete = complete;
 }
예제 #2
0
        static Duration CalculateDuration(
            BubblesTaskType taskType,
            BubbleViewModel bubble,
            int millisecondsPerUnit)
        {
            int totalMilliseconds;

            switch (taskType)
            {
            case BubblesTaskType.Burst:
                totalMilliseconds = millisecondsPerUnit;
                break;

            case BubblesTaskType.MoveDown:
                totalMilliseconds = millisecondsPerUnit * Math.Abs(bubble.Row - bubble.PreviousRow);
                break;

            case BubblesTaskType.MoveRight:
                totalMilliseconds = millisecondsPerUnit * Math.Abs(bubble.Column - bubble.PreviousColumn);
                break;

            default:
                throw new ArgumentException("Unrecognized BubblesTaskType value: " + taskType, "taskType");
            }
            return(new Duration(TimeSpan.FromMilliseconds(totalMilliseconds)));
        }
예제 #3
0
        BubblesTask CreateTask(BubblesTaskType taskType, BubbleViewModel[] bubblesInGroup)
        {
            Func <IEnumerable <BubbleViewModel> > getBubbles;
            Action complete;

            switch (taskType)
            {
            case BubblesTaskType.Burst:
                getBubbles = delegate
                {
                    _bubbleMatrix.IsIdle = false;
                    return(bubblesInGroup);
                };
                complete = delegate
                {
                    foreach (BubbleViewModel bubble in bubblesInGroup)
                    {
                        _bubbleMatrix.RemoveBubble(bubble);
                    }
                };
                break;

            case BubblesTaskType.MoveDown:
                getBubbles = delegate
                {
                    return(this.MoveNeighboringBubblesDown(bubblesInGroup));
                };
                complete = delegate
                {
                    /* Nothing to do here. */
                };
                break;

            case BubblesTaskType.MoveRight:
                getBubbles = delegate
                {
                    return(this.MoveBubblesRight());
                };
                complete = delegate
                {
                    _bubbleMatrix.IsIdle = true;
                    _bubbleMatrix.TryToEndGame();
                };
                break;

            default:
                throw new ArgumentException("Unrecognized task type: " + taskType);
            }
            return(new BubblesTask(taskType, false, getBubbles, complete));
        }
예제 #4
0
        /// <summary>
        /// Creates a sequence of tasks that must be performed for the
        /// specified collection of bubbles.
        /// </summary>
        /// <param name="bubblesInGroup">The bubbles for which tasks are created.</param>
        internal IEnumerable <BubblesTask> CreateTasks(BubbleViewModel[] bubblesInGroup)
        {
            var taskTypes = new BubblesTaskType[]
            {
                BubblesTaskType.Burst,
                BubblesTaskType.MoveDown,
                BubblesTaskType.MoveRight
            };

            // Dump the tasks into an array so that the query is not executed twice.
            return
                ((from taskType in taskTypes
                  select this.CreateTask(taskType, bubblesInGroup))
                 .ToArray());
        }
예제 #5
0
 static bool IsTaskStaggered(BubblesTaskType taskType)
 {
     return(taskType != BubblesTaskType.Burst);
 }