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

2013/12/31

It just doesn't die!

GreenAnthony GreenAnthony

2013/12/31

#
Okay following problem I have got this space invasion game and there is supposed to be this one final enemy and he is supposed to have like three lives. But he just doesn't die and I can't find why... I can shoot him as often as I want...
import greenfoot.*;

/**
 * 
 *
 */
public class BossEnemy extends Animal
{
    int Counter = 3;
    /**
     * Act - do whatever the BossEnemy wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        if (canSee(Bullet.class))
        {
            Counter--; 
            eat(Bullet.class);
        }
        if (Counter == 0)
        {
            getWorld().removeObject(this);
        }
                if (canSee(EnemyRocket.class))
        {
            eat(EnemyRocket.class);
            getWorld().addObject(new EnemyRocket(), Greenfoot.getRandomNumber(800),Greenfoot.getRandomNumber(170));  
        }
    }    
}
Please help me! What's the problem with those codes?
lordhershey lordhershey

2014/1/1

#
What are you shooting at it? If you some how jump over 0 for Counter (not sure how you could) you can miss the Counter == 0 condition, try changing it to say Counter < 1 .
You need to login to post a reply.