迷你pacman代码java

迷你pacman代码java,java,pacman,greenfoot,Java,Pacman,Greenfoot,我已经用greenfoot编写了一个迷你pacman代码。我的问题是,一旦收集了所有的叶子,Clara就要停在第一棵树前,然而,我继续得到一个错误,她说她不能移动这棵树。下面是我的代码: /** * MyClara is a subclass of Clara. Therefore, it inherits all methods of Clara: <p> * * PERMITTED COMMANDS * Actions: move(), turnLeft(),

我已经用greenfoot编写了一个迷你pacman代码。我的问题是,一旦收集了所有的叶子,Clara就要停在第一棵树前,然而,我继续得到一个错误,她说她不能移动这棵树。下面是我的代码:

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

    }
}
/**
*MyClara是Clara的一个子类。因此,它继承了Clara的所有方法:
* 
*允许的命令
*操作:move()、turnlight()、turnlight()、putLeaf()、removeLeaf()、stop()
*传感器:onLeaf(),treeFront()
*JAVA:if,else,!,&&,| |,暂时
*/
公共类MyClara扩展了Clara
{ 
公开募捐
{
如果(!treeFront())
{
eatLeaf();
moveThroughMaze();
}
}
void stopfrontoffirsttree()
{
if(treeFront())
停止();
}
void eatLeaf()
{
while(onLeaf())
{
removeLeaf();
move();
}
}
无效周转()
{
左转();
左转();
move();
左转();
左转();
}
void checkLeft()
{
左转();
move();
如果(onLeaf())
eatLeaf();
其他的
扭转();
}
void checkRight()
{
右转();
move();
如果(onLeaf())
eatLeaf();
其他的
扭转();
}
void moveThroughMaze()
{
eatLeaf();
扭转();
checkLeft();
扭转();
checkLeft();
扭转();
checkRight();
扭转();
checkRight();
扭转();
checkRight();
扭转();
checkLeft();
扭转();
checkLeft();
扭转();
checkLeft();
}
}

我们需要更多信息。我们能看到完整的错误信息吗?我们能看到迷宫的图像吗?你能解释一下你的方法吗,比如说
moveThroughMaze()
(解释所有的方法,但要特别说明那一种)?moveThroughMaze()遵循迷宫的过程,收集树叶。错误消息表示“由于树的原因,clara无法移动,但是我在代码中编写了if(treeFront())stop();您的图像尚未显示。请确保您已正确上载。此外,您是否正在手动通过迷宫?看起来是这样的?图像似乎无法上载。是的,我将使用Maualy,但我正在尝试使其通用