Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Activity1;
- import kareltherobot.*;
- public class Activity1Main extends UrRobot{
- public Activity1Main (int s, int a, Direction d, int b){
- super(s, a, d, b);
- }
- public static void main(String[] args) {
- World.readWorld("Lesson3World1.kwld"); //reading and creating world
- World.setVisible();
- World.setDelay(20);
- Activity1Main arthur = new Activity1Main(4,3, North, 0);
- for (int out = 0; out < 3; out++){ //there are three columns, so it runs three times
- for (int in = 0; in < 5; in++){ //the robot does five shuttle runs
- arthur.runShuttle();
- }
- if (out != 2){ //the robot moves to the next column the first two times
- arthur.turnAround();
- arthur.turnLeft();
- arthur.move();
- arthur.turnLeft();
- }
- }
- }
- /**
- * the robot runs a single shuttle run
- * @param - none
- * @return - void
- */
- public void runShuttle(){
- runToOtherSide();
- pickBeeper();
- turnAround();
- runToOtherSide();
- putBeeper();
- turnAround();
- }
- /**
- * goes to to other side
- * @param - none
- * @return - void
- */
- public void runToOtherSide(){
- move();
- move();
- move();
- }
- /**
- * allows the robot to instantly turn around
- * @param - none
- * @return - void
- */
- public void turnAround(){
- int delay = World.delay();
- World.setDelay(0); //by changing the delay, the robot turns left instantaneously
- turnLeft();
- World.setDelay(delay);
- turnLeft();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement