Trying to keep enemies from being able leave the maze like I have done with the player but the same code wont work, help would be much appreciated.
public boolean canMove(int x, int y)
{
Actor sand;
sand=getOneObjectAtOffset(x,y,sandroad.class);
boolean flag=false;
if (sand !=null)
{
flag=true;
setLocation(getX()+0,getY()+0);
}
return flag;
} public void move ()
{
int random = Greenfoot.getRandomNumber(20);
int leftChange=(-60);
int rightChange=(60);
int upChange=(-60);
int downChange=(60);
{if(canMove(leftChange, 0) ==true){
if (random == 1){
setLocation(getX()+leftChange, getY()) ;}
}
}
{if(canMove(rightChange, 0) ==true){
if (random == 2) {
setLocation(getX()+rightChange, getY()) ;}
}
}
{if(canMove(upChange, 0) ==true){
if (random == 3){
setLocation(getX(), getY()+upChange) ;}
}
}
{if(canMove(downChange, 0) ==true){
if (random == 4){
setLocation(getX(), getY()+downChange) ;}
}
}
}