SHARE
TWEET

Untitled

KUEM011 Nov 21st, 2019 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package Lesson3;
  2. import kareltherobot.*;
  3.  
  4. public class Lesson3Activity1 extends UrRobot{
  5.     /*
  6.      * @param x
  7.      * @param y
  8.      * @param d
  9.      * @param b
  10.      */
  11.     public Lesson3Activity1(int x, int y, Direction d, int b){
  12.         super(x, y, d, b);
  13.     }
  14.     /*
  15.     Function tha allows for the robot to run in one straight direction.
  16.      */
  17.     public void shuttleRun() {
  18.         move();
  19.         move();
  20.         move();
  21.     }
  22.     /*
  23.     Function that allows the robot to turn around very quickly
  24.      */
  25.     public void backwardsTurn(){
  26.         turnLeft();
  27.         turnLeft();
  28.     }
  29.     /*
  30.     Uses the idea behind the moonwalk to instantly have the robot turn around so it looks like he turns right for smoothness.
  31.      */
  32.     public void changeLane(){
  33.         int delay = World.delay();
  34.         World.setDelay(0);
  35.         backwardsTurn(); //Quickly changes the delay so that it appears instant
  36.         World.setDelay(delay);
  37.         turnLeft();
  38.         move();
  39.         turnLeft();
  40.     }
  41.     /*
  42.     Just exists to neaten up the main function. Just completes every lane
  43.      */
  44.     public void totalLoop(){
  45.         for(int index = 0; index < 5; index ++){
  46.             shuttleRun();
  47.             pickBeeper();
  48.             backwardsTurn();
  49.             shuttleRun(); //Repeats the shuttlerun 5 times so that it loops.
  50.             backwardsTurn();
  51.             putBeeper();
  52.         }
  53.     }
  54.  
  55.     /**
  56.      * Function that just runs and allows the robot to do his shuttle loop.
  57.      * @param args
  58.      */
  59.     public static void main(String[] args){
  60.         World.setDelay(20);
  61.         World.setVisible(); //Creates the world that the robot will live in.
  62.         World.readWorld("Lesson3World1.kwld");
  63.         Lesson3Activity1 roomba = new Lesson3Activity1(4, 3, North, 0);
  64.         roomba.totalLoop();
  65.         roomba.changeLane();
  66.         roomba.totalLoop();
  67.         roomba.changeLane();
  68.         roomba.totalLoop();
  69.     }
  70. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top