import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class ChaseKiller here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class ChaseKiller extends Actor
{
/**
* Act - do whatever the ChaseKiller wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
int a = UJANG.buttons2;
do{
move(1);
if (getWorld().getObjects(UJANG.class).isEmpty()) return; // skips following if the ujang is not in world
Actor ujang = (Actor)getWorld().getObjects(UJANG.class).get(0); // gets reference to ujang
turnTowards(ujang.getX(), ujang.getY()); // turn toward ujang
}while(a<=5);
}
} import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class UJANG here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class UJANG extends Actor
{
private int buttons = 0;
public static int buttons2 = 0;
/**
* Act - do whatever the UJANG wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
if (Greenfoot.isKeyDown("left"))
{
move(-4);
}
if (Greenfoot.isKeyDown("right"))
{
move(4);
}
if (Greenfoot.isKeyDown("up"))
{
setLocation(getX(), getY()-4);
}
if (Greenfoot.isKeyDown("down"))
{
setLocation(getX(), getY()+4);
}
Labirin a = (Labirin)getOneObjectAtOffset(0,0,Labirin.class);
if(a!=null){
World world = getWorld();
world.addObject(new GameOver(), world.getWidth()/2, world.getHeight()/2);
Greenfoot.stop();
}
Barangbukti b = (Barangbukti)getOneObjectAtOffset(0,0,Barangbukti.class);
if(b!=null){
buttons++;
getWorld().removeObject(b);
}
Buttons2 d = (Buttons2)getOneObjectAtOffset(0,0,Buttons2.class);
if(d!=null){
UJANG.buttons2++;
getWorld().removeObject(d);
}
Actor Locked;
if(buttons==5){
World world = getWorld();
getWorld().removeObjects(getWorld().getObjects(Locked.class));
}
Actor Locked2;
if(buttons2>=5){
World world = getWorld();
getWorld().removeObjects(getWorld().getObjects(Locked.class));
}
Locked c = (Locked)getOneObjectAtOffset(0,0,Locked.class);
if(c!=null){
World world = getWorld();
world.addObject(new GameOver(), world.getWidth()/2, world.getHeight()/2);
Greenfoot.stop();
}
Locked2 e = (Locked2)getOneObjectAtOffset(0,0,Locked2.class);
if(e!=null){
World world = getWorld();
world.addObject(new GameOver(), world.getWidth()/2, world.getHeight()/2);
Greenfoot.stop();
}
wayout f = (wayout)getOneObjectAtOffset(0,0, wayout.class);
if(f!=null){
World world = getWorld();
world.addObject(new victory(), world.getWidth()/2, world.getHeight()/2);
Greenfoot.stop();
}ChaseKiller ck = (ChaseKiller)getOneObjectAtOffset(0,0, ChaseKiller.class);
}
}
