Advertisement
seby_stephens

Lesson 3 Activity 1

Nov 15th, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.71 KB | None | 0 0
  1. package Lesson3;
  2. // Program is meant to complete three shuttle runs within a certain world
  3. import kareltherobot.UrRobot;
  4. import kareltherobot.World;
  5.  
  6. public class Activity1Main extends UrRobot{
  7.     public Activity1Main(int a, int s, Direction d, int b){
  8.         super(a,s,d,b);
  9.     }
  10.     public static void main(String[] args){
  11.         World.readWorld("Lesson3World1.kwld");
  12.         World.setDelay(20);
  13.         World.setVisible();
  14.         Activity1Main gary = new Activity1Main(4,3,North,0);
  15.         //Runs shuttle run twice and shifts twice
  16.         for(int i = 0; i<2; i++){
  17.             gary.shuttleRun();
  18.             gary.shift();
  19.         }
  20.         //Runs shuttle run for third column without shifting
  21.         gary.shuttleRun();
  22.     }
  23.  
  24.     /**
  25.      * Allows Robot to do shuttle run by moving down a lane to pick up beeper and then back to drop it
  26.      * @ param - none
  27.      * @ return - void
  28.      */
  29.     public void shuttleRun(){
  30.         int delay = World.delay();
  31.         for (int j = 0; j<5;j++) {
  32.             for (int i = 0; i < 3; i++) {
  33.                 move();
  34.             }
  35.             pickBeeper();
  36.             World.setDelay(0);
  37.             turnLeft();
  38.             turnLeft();
  39.             World.setDelay(delay);
  40.             for (int i = 0; i < 3; i++) {
  41.                 move();
  42.             }
  43.             putBeeper();
  44.             World.setDelay(0);
  45.             turnLeft();
  46.             turnLeft();
  47.             World.setDelay(delay);
  48.         }
  49.     }
  50.  
  51.     /**
  52.      * Allows Robot to shift lanes within box
  53.      * @ param - none
  54.      * @ return - void
  55.      */
  56.     public void shift(){
  57.         turnLeft();
  58.         turnLeft();
  59.         turnLeft();
  60.         move();
  61.         turnLeft();
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement