Advertisement
GARC923

Challenge 2 EsperBot

Nov 15th, 2022
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. package Challenges;
  2.  
  3. import kareltherobot.Robot;
  4. import kareltherobot.World;
  5.  
  6.  
  7. public class EsperBot2 extends Robot {
  8. public EsperBot2(int street, int avenue, Direction direction, int beeperCount) {
  9. super(street, avenue, direction, beeperCount);
  10. }
  11.  
  12.  
  13. public static void main(String[] args) {
  14. World.setDelay(50);
  15. World.setVisible();
  16. World.setSize(10, 10);
  17. World.showSpeedControl(true);
  18.  
  19. Lesson3.Activity1 zgod = new Lesson3.Activity1(1, 3, North, -1);
  20. }
  21.  
  22. /**
  23. * Turns right
  24. * @return void
  25. */
  26. public void turnRight() {
  27. int del = World.delay();
  28. World.setDelay(0);
  29. turnLeft();
  30. turnLeft();
  31. World.setDelay(del);
  32. turnLeft();
  33. }
  34.  
  35. /**
  36. * Turns right
  37. * @return boolean
  38. */
  39. boolean RETwallonright = true;
  40. public boolean wallOnRight(){
  41. int del = World.delay();
  42. World.setDelay(0);
  43. turnRight();
  44. if (frontIsClear()) { // checks if there is a wall when it turns right
  45. RETwallonright = false;
  46. }else {
  47. RETwallonright = true;
  48. }
  49. World.setDelay(del);
  50. turnLeft();
  51. return RETwallonright;
  52. }
  53.  
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement