Advertisement
seby_stephens

Lesson 3 Activity 3

Nov 20th, 2019
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.25 KB | None | 0 0
  1. package Lesson3;
  2. //This program is meant to harvest a field of beepers (pick them up) by using functions in an effective manner.
  3. import kareltherobot.UrRobot;
  4. import kareltherobot.World;
  5.  
  6. public class Activity3Main extends UrRobot{
  7.     public Activity3Main(int a, int s, Direction d, int b){
  8.         super(a,s,d,b);
  9.     }
  10.     public static void main(String[] args){
  11.         //Imports world map
  12.         World.readWorld("Lesson3World3.kwld");
  13.         World.setDelay(20);
  14.         World.setVisible();
  15.         //Declares object gary
  16.         Activity3Main gary = new Activity3Main(1,1,North,0);
  17.         //Functions in the order they have to be to efficiently harvest beepers
  18.         //Starts --> harvests -->shifts row --> harvests-->shifts row a different way --> ...
  19.         gary.start();
  20.         gary.harvest();
  21.         gary.shift();
  22.         gary.harvest();
  23.         gary.shiftTwo();
  24.         gary.harvest();
  25.         gary.shift();
  26.         gary.harvest();
  27.     }
  28.  
  29.     /**
  30.      * Allows the robot to turn right
  31.      * @ param - none
  32.      * @ return - void
  33.      */
  34.     public void turnRight(){
  35.         int delay = World.delay();
  36.         World.setDelay(0);
  37.         turnLeft();
  38.         turnLeft();
  39.         turnLeft();
  40.         World.setDelay(delay);
  41.     }
  42.     /**
  43.      * Starts the movement of robot by turning it and allowing it to move a space w/o picking up beeper
  44.      * @ param - none
  45.      * @ return - void
  46.      */
  47.     public void start(){
  48.         turnRight();
  49.         move();
  50.     }
  51.     /**
  52.      * Allows robot to pick up beeper every time it moves to harvest them
  53.      * @ param - none
  54.      * @ return - void
  55.      */
  56.     public void harvest(){
  57.         for(int i=0;i<7;i++){
  58.             pickBeeper();
  59.             move();
  60.         }
  61.     }
  62.     /**
  63.      * Allows robot to change rows when its on the right side of the beepers
  64.      * @ param - none
  65.      * @ return - void
  66.      */
  67.     public void shift(){
  68.         turnLeft();
  69.         move();
  70.         turnLeft();
  71.         move();
  72.     }
  73.     /**
  74.      * Allows robot to change rows when its on the left side of the beepers
  75.      * @ param - none
  76.      * @ return - void
  77.      */
  78.     public void shiftTwo(){
  79.         turnRight();
  80.         move();
  81.         turnRight();
  82.         move();
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement