Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. package kareltherobot;
  2. public class SuperRobot extends Robot
  3. { public SuperRobot(int street, int avenue,
  4. Directions.Direction direction, int beepers)
  5. { super(street, avenue, direction, beepers);
  6. }
  7.  
  8.  
  9.  
  10. public void turnRight ()
  11. {
  12. for(int x=0; x<3; x++)
  13. turnLeft();
  14. }
  15.  
  16. public void turnAround()
  17. {
  18. for(int x=0; x<2; x++)
  19. turnLeft();
  20. }
  21.  
  22. public void backUp()
  23. {
  24. turnAround();
  25. move();
  26. turnAround();
  27. }
  28.  
  29. public void turnNorth()
  30. {
  31. while(!facingNorth())
  32. turnLeft();
  33. }
  34.  
  35. public void turnSouth()
  36. {
  37. while(!facingSouth())
  38. turnLeft();
  39. }
  40.  
  41. public void turnEast()
  42. {
  43. while(!facingEast())
  44. turnLeft();
  45. }
  46.  
  47. public void turnWest()
  48. {
  49. while(!facingWest())
  50. turnLeft();
  51. }
  52.  
  53. public boolean leftIsClear()
  54. {
  55. turnLeft();
  56.  
  57.  
  58. if(frontIsClear())
  59. {
  60. turnRight();
  61. return true;
  62. }
  63.  
  64. else
  65. {
  66. turnRight();
  67. return false;
  68. }
  69. }
  70.  
  71. public boolean rightIsClear()
  72. {
  73. turnRight();
  74.  
  75.  
  76. if(frontIsClear())
  77. {
  78. turnLeft();
  79. return true;
  80. }
  81.  
  82. else
  83. {
  84. turnLeft();
  85. return false;
  86. }
  87. }
  88.  
  89. public void walkAcross()
  90. {
  91. while(frontIsClear())
  92. move();
  93.  
  94. if(!frontIsClear())
  95. turnLeft();
  96. pickUpAllBeepers();
  97. }
  98.  
  99. public void climbWall()
  100. {
  101. while(frontIsClear() && !rightIsClear())
  102. move();
  103.  
  104. if(rightIsClear())
  105. {
  106. turnRight();
  107. move();
  108. turnRight();
  109. }
  110. while(frontIsClear())
  111. move();
  112. if(!frontIsClear())
  113. turnLeft();
  114.  
  115.  
  116. }
  117.  
  118. public void walls()
  119. {
  120. while(frontIsClear())
  121. {
  122. walkAcross();
  123. climbWall();
  124. pickUpAllBeepers();
  125. }
  126. }
  127.  
  128. public void pickUpAllBeepers()
  129. {
  130. while(nextToABeeper())
  131. {
  132.  
  133. pickBeeper();
  134.  
  135. if(!nextToABeeper() && facingEast() && frontIsClear())
  136. {
  137. turnOff();
  138. }
  139. }
  140. }
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement