c# - LINQ: grouping collection -
I'm programming space invaders for practice ;-) And works quite well, but my invaders There is a problem of returning to the fire. / P>
I have stored a list of all the invaders and I use linq to add to group those invaders by X-location so I can randomly access any group and that column In the lower part, we can shoot the attacker back. / P>
var r = Attack by attacker by group of invaders. Attackers. Invader Group Choosing Invasive Group Orderbuy Invader Group in X Move (random.Next (0, invaderGroup.Count ())); But whatever I try (such as select new {invaderGroup.Key, invadergroup} ) My results are always null
Can someone give me some help / hints? Thanks
I have two problems with your query; Instead of sorting the invaders you are adjusting the group, and you are using lo with zero to a random number so that it can return an empty result.
Getting it works invaders to group by the X coordinate them to sort by Y coordinate, with randomly select a group and the highest Y coordinate of the attacker:
var r = Attack by invaders by attacking attacker. place . Descending group invader by attacker place. Select Invading Group in X Invader Group; Invader fire = RSCP (Random. Next (R.Count ()) first (). First ();
Comments
Post a Comment