Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package kareltherobot;
- public class SuperRobot extends Robot
- { public SuperRobot(int street, int avenue,
- Directions.Direction direction, int beepers)
- { super(street, avenue, direction, beepers);
- }
- public void turnRight ()
- {
- for(int x=0; x<3; x++)
- turnLeft();
- }
- public void turnAround()
- {
- for(int x=0; x<2; x++)
- turnLeft();
- }
- public void backUp()
- {
- turnAround();
- move();
- turnAround();
- }
- public void turnNorth()
- {
- while(!facingNorth())
- turnLeft();
- }
- public void turnEast()
- {
- while(!facingEast())
- turnLeft();
- }
- public void turnWest()
- {
- while(!facingWest())
- turnLeft();
- }
- public void turnSouth()
- {
- while(!facingSouth())
- turnLeft();
- }
- public boolean leftIsClear()
- {
- turnLeft();
- if(frontIsClear())
- {
- turnRight();
- return true;
- }
- else
- {
- turnRight();
- return false;
- }
- }
- public boolean rightIsClear()
- {
- turnRight();
- if(frontIsClear())
- {
- turnLeft();
- return true;
- }
- else
- {
- turnLeft();
- return false;
- }
- }
- public void walkAcross()
- {
- while(frontIsClear())
- move();
- if(!frontIsClear())
- turnLeft();
- }
- public void climbWall()
- {
- while(frontIsClear() && !rightIsClear())
- {
- move();
- if(rightIsClear())
- {
- turnRight();
- move();
- turnRight();
- walkAcross();
- while(frontIsClear())
- move();
- }
- if(!frontIsClear())
- {
- turnLeft();
- }
- }
- }
- public void walls()
- {
- while(frontIsClear())
- {
- walkAcross();
- climbWall();
- }
- }
- public void pickAllBeepers()
- {
- while(nextToABeeper())
- {
- pickBeeper();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement