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

2012/10/17

Ending game when eaten

1
2
Penguins_and_Orbs Penguins_and_Orbs

2012/10/19

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

public class EatenPlayers extends World
{
    /**
     * Constructor for objects of class EatenPlayers.
     * 
     */
    public EatenPlayers()
    {    
        super(600, 400, 1); 
    }
    public void act()
    {
        checkPlayers();
    }
    private void checkPlayers()
    {
        if (getObjects(Penguin.class).isEmpty())if(getObjects(Bee.class).isEmpty())
        {
            Greenfoot.stop();
        }
    }  
}
SPower SPower

2012/10/19

#
Did you press run? O.O (just have to check everything :) )
SPower SPower

2012/10/19

#
O wait now I see it. You need to put the checkPlayers method in the world which is de instanciated world (the one you see on screen), otherwise the act method isn't even called.
Penguins_and_Orbs Penguins_and_Orbs

2012/10/22

#
So I can just remove the eaten players world class? Because the check players method is the only one in there.
Penguins_and_Orbs Penguins_and_Orbs

2012/10/22

#
Perhaps I could get the world to look for the two classes, and if they are false, it stops?
Penguins_and_Orbs Penguins_and_Orbs

2012/10/22

#
How would I put false at the end of this:
    public void lookForPlayers()
    {
        if (canSee(Penguin.class))if(canSee(Bee.class))
false there?----^
        {
            Greenfoot.stop();
        }
    }
danpost danpost

2012/10/22

#
I would suggest removing the 'EatenPlayers' world altogether and ask in your main world class act() method
if (getObjects(Penguin.class).isEmpty() && getObjects(Bee.class).isEmpty()) Greenfoot.stop();
Penguins_and_Orbs Penguins_and_Orbs

2012/10/22

#
Yeah... that worked.... cheers. :) and thanks SPower.
davmac davmac

2012/10/22

#
If you actually do have a 'canSee' method, you can write: if (! canSee(Penguin.class) && ! canSee(Bee.class)) { The '!' means 'not'.
You need to login to post a reply.
1
2