I want a robot to avoid obstacles to get from one side if the world to the other. My idea was to have the robot follow his right until he eventually finds it. The first step i have is to get the robot to check to see if he has a wall to his right side. I've only used Greenfoot for about a month so I'm not sure of all the details about returning values and true/false stuff. Anyway, here's what i have for now.
What do I need to do to get this working?
public void followRight() { if (checkRight()==true) { fwd(); } else { turnRight(); fwd(); } } public boolean checkRight() { if (getDirection()==NORTH) { return northWall(); } if (getDirection()==SOUTH) { return southWall(); } if (getDirection()==EAST) { return eastWall(); } if (getDirection()==WEST) { return westWall(); } } public int getDirection() { return direction; } public boolean northWall() { Actor wall = getOneObjectAtOffset(1, 0, wall.class); if(wall!=null) { return true; } else { return false; } } public boolean southWall() { Actor wall = getOneObjectAtOffset(-1, 0, wall.class); if(wall!=null) { return true; } else { return false; } } public boolean eastWall() { Actor wall = getOneObjectAtOffset(0, 1, wall.class); if(wall!=null) { return true; } else { return false; } } public boolean westWall() { Actor wall = getOneObjectAtOffset(0, -1, wall.class); if(wall!=null) { return true; } else { return false; } }