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

2015/9/16

How to see if a certain number of Animals is on the game.

4SeaBass 4SeaBass

2015/9/16

#
And if it equals 0 then the game stops.
danpost danpost

2015/9/16

#
There is a method in the World class you can use to get a list of objects of a specific type (or all objects in the world by using 'null' for the class). A sample line to be placed in your World subclass 'act' method might be:
if (getObjects(Animal.class).isEmpty())
4SeaBass 4SeaBass

2015/9/23

#
danpost wrote...
There is a method in the World class you can use to get a list of objects of a specific type (or all objects in the world by using 'null' for the class). A sample line to be placed in your World subclass 'act' method might be:
if (getObjects(Animal.class).isEmpty())
ok thanks! And if i wanted one object to be the last one there i would ?
danpost danpost

2015/9/23

#
4SeaBass wrote...
if i wanted one object to be the last one there i would ?
You could get the current number with:
int animalCount = getObjects(Animal.class).size();
or use a conditional like:
if (getObjects(Animal.class).size() == 1)
4SeaBass 4SeaBass

2015/9/24

#
danpost wrote...
4SeaBass wrote...
if i wanted one object to be the last one there i would ?
You could get the current number with:
int animalCount = getObjects(Animal.class).size();
or use a conditional like:
if (getObjects(Animal.class).size() == 1)
Thanks again! Sorry i am a student that is trying to make a project on the side!
You need to login to post a reply.