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

2014/2/10

count objects in the world

Gamezocker Gamezocker

2014/2/10

#
German: Hallo, ich habe eine Welt erstellt, in welcher der Spieler Gegner töten muss. Wenn alle tot sind soll sich eine Tür öffnen. Nun ist meine frage: Wie weiß ich, dass alle Gegner tot sind und die Tür geöffnet werden kann. Muss ich mit java.util.list arbeiten? Brauchst du meinen code? English: Hello, I have created a world in which the player must kill enemies. If they are all dead is supposed to open a door. Now my question: How do I know that all enemies are dead and the door can be opened. Have I to work with java.util.List? Do you need my code? Danke für deine Hilfe! Thanks for your help!
danpost danpost

2014/2/11

#
Yes, you do have to work with List objects; but, only indirectly (meaning you do not need a field, local or otherwise, to hold the List object).
if (!door.isOpen() && getObjects(Enemy.class).isEmpty())
{
    // open door
}
You will have to supply the code for my pseudo-method 'door.isOpen()' or replace it with the appropriate conditional check. You could get away with leaving that condition out altogether; however, that would not be good programming technique to execute something every act cycle that only needs to be once.
Gamezocker Gamezocker

2014/2/13

#
thanks, it runs
You need to login to post a reply.