i was told that adding the return statement in a conditional statement inside a method will stop executing that method. it doesnt seem to work for me. is this true? or am i dong something wrong?
heres my code:
import greenfoot.*;
/**
* Write a description of class Alien here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Alien extends Actor
{
private int timer = 5;
private Counter myCounter;
public Alien(Counter counter)
{
myCounter = counter;
}
/**
* Act - do whatever the Alien wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
setLocation(getX()-5, getY());
if (getX()<=0)
{
setLocation(getWorld().getWidth()+20, Greenfoot.getRandomNumber(400));
}
killEnemy();
hit();
}
public void killEnemy()
{
if (getOneIntersectingObject(Missile.class)!=null)
{
getWorld().addObject(new Explosion(), getX(), getY());
Greenfoot.playSound("explosion.wav");
Actor missile = getOneIntersectingObject(Missile.class);
getWorld().removeObject(missile);
resurrect();
}
}
public void hit()
{
if (getOneIntersectingObject(PlayerShip.class)!=null)
{
timer--;
if (timer == 0)
{
getWorld().addObject(new Explosion(), getX(), getY());
Greenfoot.playSound("explosion.wav");
resurrect();
timer = 5;
}
}
}
public void resurrect()
{
setLocation(getWorld().getWidth()+20, Greenfoot.getRandomNumber(400));
if (myCounter.getValue()<=0)
{
return;
}
}
}
