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

2016/12/13

greenfoot.stop() method doesn't end the game

DL20 DL20

2016/12/13

#
In the game I check how many bugs have past a certain line on the world and delete them. In the code below, at the very end, I check the counter for the bugs and if 35 have past the line, the game ends, but it doesn't end it continues normally. Can someone help me out or know why this happens?
public class LadybugCounter extends Actor
{
    private int BugtotalCount = 0;
    Color colorW = Color.WHITE;
    Color colorB = Color.BLACK;
    Color colorR = Color.RED;
    public LadybugCounter()
    {
        setImage(new GreenfootImage("LadybugsPastYou  0", 20, colorR, colorW));
        
    }    

    public void bumpCount(int amount)
    {
        BugtotalCount += amount;
        setImage(new GreenfootImage("LadybugsPastYou    " + BugtotalCount, 20, colorR,colorW));
    }
    
    public void Greenfoot()
    {
        if (BugtotalCount == 35) {
            Greenfoot.stop();
        }
    }
}
danpost danpost

2016/12/13

#
If the value of 'amount' when calling 'bumpCount' is more than one, it is possible to have the value of 'BugtotalCount' jump over 35. Change line 21 to:
if (BugtotalCount >= 35) {
You need to login to post a reply.