我需要有关stop命令的帮助 [英] I need help with the stop command

查看:62
本文介绍了我需要有关stop命令的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我目前正在大学学习并需要一些帮助我的java程序。

我得到了我的生物穿过迷宫,当她走过时拾起树叶,然而当我走到尽头时,她一直撞到一个物体。我不被允许使用stop();命令。



任何帮助都将不胜感激。'



谢谢



Hi all,

I am currently studying at uni and need some help with my java program.
I am getting my creature to move through a maze and pick up leaves as she moves through, however when i get to the end she keeps crashing into an object. I am not allowed to use the stop(); command.

Any help would be appreciated.'

Thanks

// Make move around the maze and put leaves in empty cells until reaches the mushroom
            while (!treeFront())
            {
                leafLitter();
                travelForward();
            }
            safeMove();

    }

    //will put leaves in the empty cells as moves forward
    //If lands on a leaf will continue to move to the next cell until there is an empty one can put a leaf in.
    void leafLitter()
    {
        while (!treeFront())
            if (!onLeaf())
                putLeaf();

            else
                move();
    }

    // will repostition 90degrees to the left 
    void travelForward()
    {
        if (treeFront() && treeRight())
            turnLeft();
    }





我的尝试:



我试过执行break;和if / else语句



What I have tried:

I have tried executing break; and if/else statements

推荐答案

你需要检查一下你是否已经到达蘑菇(我看不到蘑菇代码)。



如果前面有一棵树,右边有一棵树,你还需要转左。



而你实际上并没有在travelForward方法中前进;只剩下了。
You need to check if you've arrived at the mushroom at some point (I see no "mushroom" code).

You also need to turn "left" when there is a tree in the front and one to the right.

And you aren't actually ever moving "forward" in your "travelForward" method; only left.


这篇关于我需要有关stop命令的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆