Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Lesson3;
- import kareltherobot.*;
- public class Lesson3Activity1 extends UrRobot{
- /*
- * @param x
- * @param y
- * @param d
- * @param b
- */
- public Lesson3Activity1(int x, int y, Direction d, int b){
- super(x, y, d, b);
- }
- /*
- Function tha allows for the robot to run in one straight direction.
- */
- public void shuttleRun() {
- move();
- move();
- move();
- }
- /*
- Function that allows the robot to turn around very quickly
- */
- public void backwardsTurn(){
- turnLeft();
- turnLeft();
- }
- /*
- Uses the idea behind the moonwalk to instantly have the robot turn around so it looks like he turns right for smoothness.
- */
- public void changeLane(){
- int delay = World.delay();
- World.setDelay(0);
- backwardsTurn(); //Quickly changes the delay so that it appears instant
- World.setDelay(delay);
- turnLeft();
- move();
- turnLeft();
- }
- /*
- Just exists to neaten up the main function. Just completes every lane
- */
- public void totalLoop(){
- for(int index = 0; index < 5; index ++){
- shuttleRun();
- pickBeeper();
- backwardsTurn();
- shuttleRun(); //Repeats the shuttlerun 5 times so that it loops.
- backwardsTurn();
- putBeeper();
- }
- }
- /**
- * Function that just runs and allows the robot to do his shuttle loop.
- * @param args
- */
- public static void main(String[] args){
- World.setDelay(20);
- World.setVisible(); //Creates the world that the robot will live in.
- World.readWorld("Lesson3World1.kwld");
- Lesson3Activity1 roomba = new Lesson3Activity1(4, 3, North, 0);
- roomba.totalLoop();
- roomba.changeLane();
- roomba.totalLoop();
- roomba.changeLane();
- roomba.totalLoop();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement