Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. /**
  2. * This program has alpha bot
  3. * by: Alejandro Antorcha
  4. */
  5. package Lesson3;
  6. import kareltherobot.*;
  7.  
  8. public class Lesson3Activity3 extends UrRobot{
  9.  
  10. //constructor from UrRobot for my alphabot
  11. public Lesson3Activity3(int x, int y, Direction d, int b) {
  12. super(x, y, d, b);
  13. }
  14.  
  15. public static void main(String[] args) {
  16. World.readWorld("Lesson3World3.kwld");
  17.  
  18. World.setDelay(10);
  19. World.setVisible();
  20.  
  21. Lesson3Activity3 alphaBot = new Lesson3Activity3(1,1,North, 0);
  22.  
  23. //runs program
  24. alphaBot.wholeHarvest();
  25.  
  26. }
  27.  
  28. /**
  29. * makes the robot appear to turn right
  30. * @param
  31. * @return void
  32. */
  33. public void turnRight() {
  34. //changing the delay to 0
  35. int delay = World.delay();
  36. World.setDelay(0);
  37. turnLeft();
  38. turnLeft();
  39.  
  40. //setting the relay to what it was previously set to
  41. World.setDelay(delay);
  42.  
  43. turnLeft();
  44. }
  45.  
  46. /**
  47. * runs one harvest latitude-ly
  48. * @param
  49. * @return void
  50. */
  51. public void harvest() {
  52. for(int i = 0; i < 6; i++) {
  53. pickBeeper();
  54. move();
  55. }
  56. pickBeeper();
  57.  
  58. }
  59.  
  60. /**
  61. * the turn between the different harvests
  62. * @param turn - caries the number of which lane alphabot is in
  63. */
  64. public void harvestTurn(int turn) {
  65. for (int j = 0; j < 2; j++) {
  66.  
  67. //chooses to go left or right
  68. if (turn % 2 == 1) {
  69. turnRight();
  70. } else {
  71. turnLeft();
  72. }
  73.  
  74. //moves between the two turns but not after
  75. if (j == 0) {
  76. move();
  77. }
  78. }
  79. }
  80.  
  81. /**
  82. * runs the whole harvest
  83. * @param
  84. * @return void
  85. */
  86. public void wholeHarvest() {
  87. turnRight();
  88. move();
  89.  
  90. for(int i = 0; i < 3; i++) {
  91. harvest();
  92. harvestTurn(i);
  93. }
  94. //last harvest and orientation
  95. harvest();
  96. move();
  97. turnRight();
  98.  
  99. }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement