I'm making a rogue-like maze style game for a college assignment, and the idea is that every time the player presses an arrow key and moves, the enemy actors move in a random direction. The method "move" is being sent to a "controller" class, which is inheritting from the world class, and a void is then sent from the controller to the enemy class. Upon moving, the game immediately crashes and I receive this error.
Player class move method:
Controller class:
Swine class:
private void move(int velocityX, int velocityY){
setLocation(getX() + velocityX, getY() + velocityY); //move in specified direction
controller.move();
}public class Controller extends World
{
private static int level;
private static int score;
private static int lives = 3;
private Player thePlayer;
private Swine swineEnemy;
private Scoreboard scoreStatus;
public Controller()
{
super(800, 600, 1);
level = 1;
scoreStatus = new Scoreboard();
thePlayer = new Player(this);
swineEnemy = new Swine();
Greenfoot.setWorld(new Level(this, thePlayer, scoreStatus, level));
}
public void changeWorld(){
level++;
Greenfoot.setWorld(new Level(this, thePlayer, scoreStatus, level));
}
public void setScore(int scoreIncrimant){
score += scoreIncrimant;
}
public int getScore(){
return score;
}
public void setLives(int livesIncrimant){
lives += livesIncrimant;
}
public int getLives(){
return lives;
}
public void move(){
swineEnemy.move();
}
}public class Swine extends Mover
{
private Controller controller;
int destinationX;
int destinationY;
private boolean intersectedWall = false;
private final int speed = 1;
public Swine(){
}
public void setDestination(int locationX, int locationY){
destinationX = locationX;
destinationY = locationY;
}
public void act(){
if(getX() != destinationX){
if(destinationX > getX())
setLocation(getX() + speed, getY());
if(destinationX < getX())
setLocation(getX() - speed, getY());
}
if(getY() != destinationY){
if(destinationY > getY())
setLocation(getX(), getY() + speed);
if(destinationY < getY())
setLocation(getX(), getY() - speed);
}
}
public void move(){
do{
int random = Greenfoot.getRandomNumber(4);
if(random == 1)
destinationY = getY() - 20;
else if (random == 2)
destinationX = getX() + 20;
else if (random == 3)
destinationY = getY() + 20;
else if (random == 4)
destinationX = getX() - 20;
if(destinationX > getX())
setLocation(getX() + speed, getY());
if(destinationX < getX())
setLocation(getX() - speed, getY());
if(destinationY > getY())
setLocation(getX(), getY() + speed);
if(destinationY < getY())
setLocation(getX(), getY() - speed);
if(getOneIntersectingObject(Wall.class) != null){ //if player interesects wall
intersectedWall = true;
setLocation(getX(), getY());
random = Greenfoot.getRandomNumber(4);
}
else
intersectedWall = false;
}while(intersectedWall);
}
}

