Ok so i am extremely new to java. I can learn quick but here is my problem
I need to get the actor over to the other side of the world while avoiding an object (called a Wall). My actor (robot) starts in random places each time you start the world and i need help with the programming that will get me to avoid the the walls that are randomly placed. For example if my robot hits a "wall" i need it to go around it but i have no idea how to go about this. Below is the code that i was given for the robot.
public class robot extends Actor { private static final int EAST = 0; private static final int WEST = 1; private static final int NORTH = 2; private static final int SOUTH = 3; private int direction; public robot() { setDirection(EAST); } public void act() { if(endItNow()==true) { Greenfoot.stop(); } else { int x = getX(); int y = getY(); setLocation(x + 1, y); } } public void setDirection(int direction) { this.direction = direction; switch(direction) { case SOUTH : setRotation(90); break; case EAST : setRotation(0); break; case NORTH : setRotation(270); break; case WEST : setRotation(180); break; default : break; } } public void turnLeft() { switch(direction) { case SOUTH : setDirection(EAST); break; case EAST : setDirection(NORTH); break; case NORTH : setDirection(WEST); break; case WEST : setDirection(SOUTH); break; } } public void turnRight() { switch(direction) { case SOUTH : setDirection(WEST); break; case EAST : setDirection(SOUTH); break; case NORTH : setDirection(EAST); break; case WEST : setDirection(NORTH); break; } } public boolean canMove() { World myWorld = getWorld(); int x = getX(); int y = getY(); // test for outside border if (x >= myWorld.getWidth() || y >= myWorld.getHeight()) { return false; } else if (x < 0 || y < 0) { return false; } return true; } public void forward(int howMany) { for(int loop=0;loop<howMany;loop++) { fwd(); } } public void backward(int howMany) { for(int loop=0;loop<howMany;loop++) { bwd(); } } public void bwd() { if (!canMove()) { return; } switch(direction) { case SOUTH : setLocation(getX(), getY() - 1); break; case EAST : setLocation(getX() - 1, getY()); break; case NORTH : setLocation(getX(), getY() + 1); break; case WEST : setLocation(getX() + 1, getY()); break; } } public void fwd() { if (!canMove()) { return; } switch(direction) { case SOUTH : setLocation(getX(), getY() + 1); break; case EAST : setLocation(getX() + 1, getY()); break; case NORTH : setLocation(getX(), getY() - 1); break; case WEST : setLocation(getX() - 1, getY()); break; } } public boolean checkBumpers() { Actor wall = getOneObjectAtOffset(0, 0, wall.class); if(wall!=null) { return true; } else { return false; } } public boolean endItNow() { Actor end_ = getOneObjectAtOffset(0, 0, end_.class); if(end_ != null) { return true; } else { return false; } } }