Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Lesson3;
- // Program is meant to complete three shuttle runs within a certain world
- import kareltherobot.UrRobot;
- import kareltherobot.World;
- public class Activity1Main extends UrRobot{
- public Activity1Main(int a, int s, Direction d, int b){
- super(a,s,d,b);
- }
- public static void main(String[] args){
- World.readWorld("Lesson3World1.kwld");
- World.setDelay(20);
- World.setVisible();
- Activity1Main gary = new Activity1Main(4,3,North,0);
- //Runs shuttle run twice and shifts twice
- for(int i = 0; i<2; i++){
- gary.shuttleRun();
- gary.shift();
- }
- //Runs shuttle run for third column without shifting
- gary.shuttleRun();
- }
- /**
- * Allows Robot to do shuttle run by moving down a lane to pick up beeper and then back to drop it
- * @ param - none
- * @ return - void
- */
- public void shuttleRun(){
- int delay = World.delay();
- for (int j = 0; j<5;j++) {
- for (int i = 0; i < 3; i++) {
- move();
- }
- pickBeeper();
- World.setDelay(0);
- turnLeft();
- turnLeft();
- World.setDelay(delay);
- for (int i = 0; i < 3; i++) {
- move();
- }
- putBeeper();
- World.setDelay(0);
- turnLeft();
- turnLeft();
- World.setDelay(delay);
- }
- }
- /**
- * Allows Robot to shift lanes within box
- * @ param - none
- * @ return - void
- */
- public void shift(){
- turnLeft();
- turnLeft();
- turnLeft();
- move();
- turnLeft();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement