Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. /**
  2. * Moves alphaBot until it reaches the tower, then it climbs
  3. * By: Alejandro Antorcha
  4. */
  5. package Lesson4;
  6. import kareltherobot.*;
  7.  
  8. public class Activity2Lesson4 extends Robot{
  9.  
  10. public Activity2Lesson4(int x, int y, Direction d, int b) {
  11. super(x, y, d, b);
  12. }
  13.  
  14. public static void main(String[] args) {
  15. World.readWorld("Lesson4World2.kwld");
  16.  
  17. World.setDelay(15);
  18. World.setVisible();
  19.  
  20. Robot alphaBot = new Activity2Lesson4(1, 1, East, 0);
  21.  
  22. //Runs a loop that calls move() until the robot is facing north and
  23. // not on a beeper.
  24. while(!alphaBot.facingNorth() || alphaBot.nextToABeeper()) {
  25. alphaBot.move();
  26. }
  27. }
  28.  
  29. /**
  30. * @Override
  31. * Moves normally but if it is at the tower, it turns left
  32. * @param
  33. * @return void
  34. */
  35. public void move() {
  36. //turns left if at the tower
  37. if(this.facingEast() && this.nextToABeeper()) {
  38. this.turnLeft();
  39. }
  40.  
  41. //normal move forward
  42. super.move();
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement