Reputation: 2065
So I have been working and trying for a couple of hours. I am creating a BubbleBreaker type of game. I Can do it using for loop or while but I am trying to also get practice in using Linq. Here is what I am trying to do in pesudo code.
Each Bubble has a Column and Row Property. If The bubble subtracts one from its Column property and finds the same Color bubble, it should Select it then Subtract -1 and see if two bubbles away there is also a same color bubble. If there is then subtract -2 and so on. So What I am trying to do is
var test= _theBubbles.TakeWhile((i, s) => i.BubbleColor== bubble.BubbleColor)//Then somehow tell it to do bubble.Column-s
and then Subtract s from bubble.Column So the Idea is to keep looking down the column till the bubble isnt the same
Upvotes: 1
Views: 100
Reputation: 131656
Let's assume that _theBubbles
is a list of all of the bubbles on the game board. In that case, givena particular starting bubble you could use the following query to find all bubbles below the given one that are the same color (I assume that the bottom-most row is row zero):
var bubble = ... // some known bubble
var sameColorBubblesBelowTheBubble =
_theBubbles.Where( b => b.Column == bubble.Column &&
b.Row < bubble.Row )
.OrderByDescending( b => b.Row )
.TakeWhile( (b,i) => b.BubbleColor == bubble.BubbleColor );
Upvotes: 1