Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 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 turnEast()
  36. {
  37. while(!facingEast())
  38. turnLeft();
  39. }
  40.  
  41. public void turnWest()
  42. {
  43. while(!facingWest())
  44. turnLeft();
  45. }
  46.  
  47. public void turnSouth()
  48. {
  49. while(!facingSouth())
  50. turnLeft();
  51. }
  52.  
  53. public boolean leftIsClear()
  54. {
  55. turnLeft();
  56.  
  57. if(frontIsClear())
  58. {
  59. turnRight();
  60. return true;
  61. }
  62.  
  63. else
  64. {
  65. turnRight();
  66. return false;
  67. }
  68. }
  69.  
  70. public boolean rightIsClear()
  71. {
  72. turnRight();
  73.  
  74. if(frontIsClear())
  75. {
  76. turnLeft();
  77. return true;
  78. }
  79.  
  80. else
  81. {
  82. turnLeft();
  83. return false;
  84. }
  85. }
  86.  
  87. public void walkAcross()
  88. {
  89. while(frontIsClear())
  90. move();
  91.  
  92. if(!frontIsClear())
  93. turnLeft();
  94. }
  95.  
  96. public void climbWall()
  97. {
  98. while(frontIsClear() && !rightIsClear())
  99. {
  100. move();
  101.  
  102. if(rightIsClear())
  103. {
  104. turnRight();
  105. move();
  106. turnRight();
  107. walkAcross();
  108.  
  109.  
  110. while(frontIsClear())
  111.  
  112. move();
  113.  
  114. }
  115. if(!frontIsClear())
  116. {
  117. turnLeft();
  118. }
  119. }
  120.  
  121. }
  122.  
  123. public void walls()
  124. {
  125. while(frontIsClear())
  126. {
  127. walkAcross();
  128. climbWall();
  129. }
  130. }
  131.  
  132. public void pickAllBeepers()
  133. {
  134. while(nextToABeeper())
  135. {
  136. pickBeeper();
  137. }
  138. }
  139.  
  140.  
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement