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

2015/6/11

coufl

owainjac owainjac

2015/6/11

#
public class Crab extends Actor
{
   private int world; 
  
    /**
     * Act - do whatever the Crab wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
      move(2);
      eat();
        
    }
    public void MoveandTurn()
    {
      if(Greenfoot .isKeyDown("left")) {
        turn(6);
    }
    
    if(Greenfoot .isKeyDown("right")) {
        turn(-6);
    }
        move(2);
    }  
    public void eat()
    {
    Actor alligator;
    alligator = getOneObjectAtOffset(0, 0, alligator.class);
    if (alligator != null)
    {
       World World;
       world = getWorld();
       World.removeObject(alligator);
    }
  }
}
azazeel azazeel

2015/6/11

#
what is this ?
danpost danpost

2015/6/11

#
azazeel wrote...
what is this ?
My thoughts exactly. However, I can say that 'MoveandTurn' is never called and big problems exist with lines 32 through 34. Line 32 declares a 'World' variable (initialized as 'null') that line 34 tries to call 'removeObject' on (cannot call method on a 'null' reference); and line 3 declares an 'world' int type field that line 33 tries to assign a world object to.
You need to login to post a reply.