0

I've written a mini pacman code, using greenfoot. My question is, once all the leaves have been collected Clara is to stop infront of the first tree, however, i continue getting an error, saying she cannot move the tree. Below is my code:

/**
 * MyClara is a subclass of Clara. Therefore, it inherits all methods of Clara: <p>
 * 
 * PERMITTED COMMANDS
 * Actions:     move(), turnLeft(), turnRight(), putLeaf(), removeLeaf(), stop()
 * Sensors:     onLeaf(), treeFront() 
 * JAVA:        if, else, !, &&, ||, for, while
 */
public class MyClara extends Clara 
{ 

    public void run()
    {

        if (!treeFront())
        {
            eatLeaf();
            moveThroughMaze();

        }

    }

    void stopInfrontOfFirstTree()
    {
        if (treeFront())

            stop();
    }

    void eatLeaf()
    {
        while(onLeaf())
        {
            removeLeaf();
            move();
        }

    }

    void turnAround()
    {
        turnLeft();
        turnLeft();
        move();
        turnLeft();
        turnLeft();        

    }

    void checkLeft()
    {
        turnLeft();
        move();
        if (onLeaf())
            eatLeaf();
        else
            turnAround();

    }

    void checkRight()
    {
        turnRight();
        move();
        if (onLeaf())
            eatLeaf();
        else
            turnAround();

    }

    void moveThroughMaze()
    {
        eatLeaf();
        turnAround();
        checkLeft();
        turnAround();
        checkLeft();
        turnAround();
        checkRight();
        turnAround();
        checkRight();
        turnAround();
        checkRight();
        turnAround();
        checkLeft();
        turnAround();
        checkLeft();
        turnAround();
        checkLeft();

    }
}
user3459720
  • 29
  • 1
  • 4
  • 2
    We need more information. Can we see the complete error message? Can we seen an image of the maze? Can you explain your methods like `moveThroughMaze()` (explain all of them, but that one in particular)? – But I'm Not A Wrapper Class Apr 03 '14 at 03:11
  • moveThroughMaze() follows course of the maze and collects the leaves. the error message states " clara cant move because of the tree, however i have written in my code that if (treeFront()) stop(); – user3459720 Apr 03 '14 at 03:17
  • Your image hasn't shown up. Make sure you uploaded it correctly. Also, are you manually going through the maze? That's what it seems like? – But I'm Not A Wrapper Class Apr 03 '14 at 03:21
  • the image seems to be failing to upload. Yes i am going maually, however am trying to make it generic – user3459720 Apr 03 '14 at 03:58

0 Answers0