Hey guys I need help asap. I been spending 8 hours on this and I can't figure it out, I'm using a world called MyClara and I am stuck in a infinite loop. My object is to follow a trail of leafs, and collect those leafs. After I have collected those leafs, Clara stops, but she keeps continuing and I have no idea why. These are the commands I can use: And here is my code:
public void run()
{
// TODO: Write your code below
while(onLeaf())
{
removeLeaf();
move();
if(!onLeaf())
{
getBackOnTrack();
}
}
}
public void getBackOnTrack()
{
turnLeft();
turnLeft();
move();
turnRight();
move();
}
}
• turnLeft(); - Clara turns 90 degrees to the left
• move() - Clara moves one step forward in the direction she is currently facing
• putLeaf() - Clara puts one leaf at her current position
• removeLeaf(); - Clara removes a leaf at her current position
• stop(); - Has the same effect as pressing the “pause” button
• turnRight(); - Clara turns 90 degrees to the right
• onLeaf(); - Returns true if Clara is positioned on top of a leaf or false otherwise
• treeFront(); - Returns true if there is a tree one step ahead in the direction Clara faces or false otherwise
• treeLeft(); - Returns true if there is a tree to the left from Clara or false otherwise
• treeRight(); - Returns true if there is a tree to the right from Clara or false otherwise
• mushroomFront(); Returns true if there is a tree to the right from Clara or false otherwise
We can also use For loops, and while loops and if statements and such. Here is the photo of what you need to achieve
[Disallowed URL]
