Part 6, More on List: Removing an item from Windows Phone 7

List<T> can be used for many things, think about exploding subatomic particles in the CERN research facility.  The shower of particles are thrown against sensors that measure their mass.  So you need to quickly store all of that information, and it is really a single thing: MASS.

The List generic is important.  For games, for physics, for a lot of things.

To get started review the blog post:

https://blogs.msdn.com/b/devschool/archive/2010/12/11/data-structure-part-4-even-more-on-list-lt-t-gt-wrt-generics.aspx

We used the code in the class definition that looked like the following:

 

  public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        SpriteFont Font1;
        Vector2 FontPos;

        string output, output1;


        List<String> Demo = new List<String>();

By placing the generic List<String> Demo = new List<String>( ); in the class definition, it means that the generic can be utilized throughout the class that is being defined.

We used the “Demo” Generic to add components to a list, the components were simple strings in that earlier blog.

In a game you might generate randomly defined things like bubbles in Kinect, for instance the Adventure game you knock out bubbles.  This is the gravity-free adventure where you can pretend that you float and hit the bubbles to get points. In the Kinect the bubbles are produced from a hole in the side of the container, then the bubbles take a pretty consistent pattern, but what changes? 

In Kinect you float up and down, then you knock out some of the bubbles, but not all of them, unless.  To make the game look realistic the bubbles that you “hit” are removed, the others continue on their path to one of the holes in the wall. image

Now, if we view the bubbles as a list, and you remove a bubble from the list, how do you write the code to do this.  To remove an item from the Demo list, the way we are set up right now, you would use the following code:

Demo.Remove("Jelly");

Now the question is: Where would you place this code for it to be useful in a game like Kinect?  In the Draw?  In the Update?  Where?

More in a later post.

image

NNNN