Beispiel #1
0
 internal _GAME_3BTask(_GAME_3BTaskType taskType, bool isUndo, Func <IEnumerable <_GAME_3BViewModel> > getBubbles, Action complete)
 {
     this.TaskType = taskType;
     this.IsUndo   = isUndo;
     _getBubbles   = getBubbles;
     this.Complete = complete;
 }
        static Duration CalculateDuration(
            _GAME_3BTaskType taskType,
            _GAME_3BViewModel bubble,
            int millisecondsPerUnit)
        {
            int totalMilliseconds;
            switch (taskType)
            {
                case _GAME_3BTaskType.Burst:
                    totalMilliseconds = millisecondsPerUnit;
                    break;

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

                case _GAME_3BTaskType.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));
        }
Beispiel #3
0
        _GAME_3BTask CreateTask(_GAME_3BTaskType taskType, _GAME_3BViewModel[] bubblesInGroup)
        {
            Func <IEnumerable <_GAME_3BViewModel> > getBubbles;
            Action complete;

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

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

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

            default:
                throw new ArgumentException("Unrecognized task type: " + taskType);
            }
            return(new _GAME_3BTask(taskType, false, getBubbles, complete));
        }
Beispiel #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 <_GAME_3BTask> CreateTasks(_GAME_3BViewModel[] bubblesInGroup)
        {
            var taskTypes = new _GAME_3BTaskType[]
            {
                _GAME_3BTaskType.Burst,
                _GAME_3BTaskType.MoveDown,
                _GAME_3BTaskType.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());
        }
 static bool IsTaskStaggered(_GAME_3BTaskType taskType)
 {
     return taskType != _GAME_3BTaskType.Burst;
 }