User talk:Awesomeness

From Robowiki
Revision as of 15:09, 2 May 2009 by Nat (talk | contribs) (grammar correction)
Jump to navigation Jump to search
Archived talks:
Archived Talk 20090502

Okay, I need to make a list of bullets. I have made a bullet class and everything, but I need a special list that will let me access all of the bullets in a while/for loop and be able to add and remove them at any time and never mess up. If I did this in a normal array I could do a for loop and access using an increasing number, but I wouldn't know when to stop. In a while loop, if I used while(bulletsArray[x] != null) and then increment x, after I remove my first bullet that say, hit a wall, it will stop there. I need help!

Thanks,
Awesomeness 14:02, 2 May 2009 (UTC)

I think this will do:

ArrayList<Bullet> bullets = new ArrayList<Bullet>();
for (int i = 0; i < bullets.size(); i++) {
    Bullet bullet = bullets.get(i);
    if (bullet.needRemove()) {
        // I think this will work
        // bullets.remove(i--);
        // but usually I do
        bullets.remove(bullet);
        i--;
    }
}

Here I assume that you use ArrayList to store you bullets and your bullet's classname is Bullet. If you use a plain array to keep the bullets, consider change to ArrayList. It is more flexible. » Nat | Talk » 14:09, 2 May 2009 (UTC)


You cannot post new threads to this discussion page because it has been protected from new threads, or you do not currently have permission to edit.

There are no threads on this page yet.