This site requires JavaScript, please enable it in your browser!
Greenfoot back
Fadawar
Fadawar wrote ...

2016/4/21

How to tell if all of one class is null inside the world?

Fadawar Fadawar

2016/4/21

#
I have a game where I have a multitude of enemies and I would like to start a new round when all of the enemies are gone. I have thought of using an array and then removing them when they die. But I don't know if this would be the right approach or how to go about implementing it. My main question is how can I tell if all the enemies are dead(removed from the world)? Please help and Thank you!!
danpost danpost

2016/4/21

#
If the enemies are gone then the list returned from using 'getObjects(Enemy.class)' should be an empty list (or be of size zero). The List class has both a 'size' method as well as an 'isEmpty' method that can be used on the list:
if (getObjects(Enemy.class).isEmpty())

// or
if (getObjects(Enemy.class).size() == 0)
Fadawar Fadawar

2016/4/21

#
Thank you!!
You need to login to post a reply.