import sofia.micro.jeroo.*;
public class MazeRunner extends Jeroo
{
//~ Fields ................................................................
//~ Constructor ........................................................
...
import sofia.micro.jeroo.*;
public class MazeRunner extends Jeroo
{
//~ Fields ................................................................
//~ Constructor ...........................................................
// ----------------------------------------------------------
/**
* This method creats a Jeroo that holds 15 flowers
*/
public MazeRunner()
{
super(15);
}
//~ Methods ...............................................................
/**
* This method calls upon another method while the
* the conditions of the maze are not met
*/
public void myProgram()
{
while (!allConditions())
{
this.navMaze();
}
}
/**
* This method contains all the conditions of the maze
* @return if conditions are all true the maze is complete
*/
public boolean allConditions()
{
return (this.getWorld().getObjects(Net.class).size() == 0 &&
this.getWorld().getObjects(Flower.class).size() == 0 &&
this.getGridX() == 1 && this.getGridY() == 1);
}
/**
* This method is the main navigation for the Jeroo,
* it contains instruction for gathering flowers, disabling
* traps and moving in the maze
*/
public void navMaze()
{
if (this.seesNet(AHEAD))
{
this.toss();
}
if (this.seesFlower(HERE))
{
this.pick();
}
if (!this.turnLeft() && !this.hopIfClear())
{
this.turn(RIGHT);
}
/**
* This method tells the Jeroo
* to turn left whenever it is possible to turn
* @return if conditions are true the Jeroo will turn left and hop
*/
public boolean turnLeft()
{
if (!this.seesWater(LEFT) && !this.seesNet(LEFT))
{
this.turn(LEFT);
this.hop();
return (true);
}
else
{
return (false);
}
}
/**
* This method tells the Jeroo
* to hop forward if it is clear
* @return if conditions are true the Jeroo will hop forward
*/
public boolean hopIfClear()
{
if (!this.seesWater(AHEAD) && !this.seesNet(AHEAD))
{
this.hop();
return (true);
}
else
{
return (false);
[Show More]