Advertisement
KevinNT03

Karel - Field Harvester

Nov 15th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.63 KB | None | 0 0
  1. package Activity3;
  2. import kareltherobot.*;
  3.  
  4. public class Activity3Main extends UrRobot{
  5.  
  6.     public Activity3Main(int s, int a, Direction d, int b){
  7.         super(s, a, d, b);
  8.     }
  9.  
  10.     public static void main(String[] args) {
  11.  
  12.         World.readWorld("Lesson3World3.kwld"); //reads and creates world
  13.         World.setVisible();
  14.         World.setDelay(20);
  15.  
  16.         Activity3Main waluigi = new Activity3Main(1,1, North, 1);
  17.  
  18.         for (int z = 0; z < 3; z++){ //turns left 3 times to give the program time to load
  19.             waluigi.turnLeft();
  20.         }
  21.  
  22.         for(int t = 0; t < 2; t++){ //loop - runs half the field twice
  23.             waluigi.pickRowOfBeepers();
  24.  
  25.             waluigi.move();     //moves to face the next row
  26.             waluigi.turnLeft();
  27.             waluigi.move();
  28.             waluigi.turnLeft();
  29.  
  30.             waluigi.pickRowOfBeepers();
  31.  
  32.             waluigi.move();     //moves to face the next row
  33.             waluigi.turnRight();
  34.             waluigi.move();
  35.             waluigi.turnRight();
  36.         }
  37.     }
  38.  
  39.     /**
  40.      * Robot picks a sing;e row of beepers
  41.      * @param - none
  42.      * @return - void
  43.      */
  44.     public void pickRowOfBeepers(){
  45.         for(int x = 0; x < 7; x++){  //seven beepers = seven times
  46.             move();
  47.             pickBeeper();
  48.         }
  49.     }
  50.  
  51.     /**
  52.      * allows the robot to instantaneously turn right
  53.      * @param - none
  54.      * @return - Void
  55.      */
  56.     public void turnRight(){
  57.         int delay = World.delay();
  58.         World.setDelay(0);
  59.         turnLeft();
  60.         turnLeft();
  61.         World.setDelay(delay);
  62.         turnLeft();
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement