0

greenfoot を使用して、ミニ パックマン コードを作成しました。私の質問は、すべての葉が集められたら、クララは最初の木の前で止まるということですが、彼女は木を動かすことができないというエラーが引き続き発生します。以下は私のコードです:

/**
 * 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();

    }
}
4

0 に答える 0