Advertisement
FrankyDM

Untitled

Nov 19th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.19 KB | None | 0 0
  1. package Lesson3;
  2. import kareltherobot.*;
  3.  
  4. /**
  5.  * Francesco Di Mise
  6.  * Program to collect a field of beepers
  7.  * To be efficient, it collects them in rows
  8.  * Uses functions and some loops
  9.  */
  10. public class Lesson3Activity3 extends UrRobot{
  11.  
  12.     /**
  13.      * Constructor
  14.      * @param x
  15.      * @param y
  16.      * @param d
  17.      * @param b
  18.      */
  19.     public Lesson3Activity3 (int x, int y, Direction d, int b) {
  20.         super(x, y, d, b);
  21.     }
  22.  
  23.     /**
  24.      * Main function. Performs a couple actions before the more complicated harvest functions. Collects every beeper
  25.      * @param args
  26.      */
  27.     public static void main(String[] args) {
  28.         World.setDelay(15);
  29.         World.setVisible();
  30.         Lesson3Activity3 MrDaddy = new Lesson3Activity3(1,1,North, 0);
  31.         World.readWorld("Lesson3World3.kwld");
  32.  
  33.  
  34.         MrDaddy.turnRight();
  35.         MrDaddy.move();
  36.         MrDaddy.pickBeeper();
  37.         MrDaddy.harvestBeepers();
  38.         MrDaddy.turnRight();
  39.     }
  40.  
  41.     /**
  42.      * Turn right function to instantaneously turn right
  43.      */
  44.     public void turnRight(){
  45.         int delay = World.delay();
  46.         World.setDelay(0);
  47.         turnLeft();
  48.         turnLeft();
  49.         World.setDelay(delay);
  50.         turnLeft();
  51.     }
  52.  
  53.     /**
  54.      * For loop to collect a single row of beepers
  55.      */
  56.     public void collectRow(){
  57.         for (int index = 0; index < 6; index++){
  58.             move();
  59.             pickBeeper();
  60.         }
  61.     }
  62.  
  63.     /**
  64.      * Go to the next lane. Specifically when the next lane is to the left
  65.      */
  66.     public void goNextLeft(){
  67.         turnLeft();
  68.         move();
  69.         pickBeeper();
  70.         turnLeft();
  71.     }
  72.  
  73.     /**
  74.      * Go to next lane, specifically when the next lane is on the right
  75.      */
  76.     public void goNextRight(){
  77.         turnRight();
  78.         move();
  79.         pickBeeper();
  80.         turnRight();
  81.     }
  82.  
  83.     /**
  84.      * Puts the turning and collection functions together to collect the whole field of beepers
  85.      */
  86.     public void harvestBeepers(){
  87.         collectRow();
  88.         goNextLeft();
  89.         collectRow();
  90.         goNextRight();
  91.         collectRow();
  92.         goNextLeft();
  93.         collectRow();
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement