/// <summary> /// Searches for a bubble group in which the specified bubble /// is a member. If a group is found, this object's BubblesInGroup /// collection will contain the bubbles in that group afterwards. /// </summary> /// <param name="bubble"> /// The bubble with which to begin searching for a group. /// </param> /// <returns> /// Returns this object, enabling a fluid-style API usage. /// </returns> internal _3BGroup FindBubbleGroup(_GAME_3BViewModel bubble) { if (bubble == null) { throw new ArgumentNullException("bubble"); } bool isBubbleInCurrentGroup = this.BubblesInGroup.Contains(bubble); if (!isBubbleInCurrentGroup) { this.BubblesInGroup.Clear(); this.SearchForGroup(bubble); bool addOriginalBubble = this.HasBubbles && !this.BubblesInGroup.Contains(bubble); if (addOriginalBubble) { this.BubblesInGroup.Add(bubble); } } return(this); }
IEnumerable <_GAME_3BViewModel> FindMatchingNeighbors(_GAME_3BViewModel bubble) { var matches = new List <_GAME_3BViewModel>(); // Check above. var match = this.TryFindMatch(bubble.Row - 1, bubble.Column, bubble.BubbleType); if (match != null) { matches.Add(match); } // Check below. match = this.TryFindMatch(bubble.Row + 1, bubble.Column, bubble.BubbleType); if (match != null) { matches.Add(match); } // Check left. match = this.TryFindMatch(bubble.Row, bubble.Column - 1, bubble.BubbleType); if (match != null) { matches.Add(match); } // Check right. match = this.TryFindMatch(bubble.Row, bubble.Column + 1, bubble.BubbleType); if (match != null) { matches.Add(match); } return(matches); }
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)); }
void SearchForGroup(_GAME_3BViewModel bubble) { if (bubble == null) { throw new ArgumentNullException("bubble"); } foreach (_GAME_3BViewModel groupMember in this.FindMatchingNeighbors(bubble)) { if (!this.BubblesInGroup.Contains(groupMember)) { this.BubblesInGroup.Add(groupMember); this.SearchForGroup(groupMember); } } }