Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Activity3;
- import kareltherobot.*;
- public class Activity3Main extends UrRobot{
- public Activity3Main(int s, int a, Direction d, int b){
- super(s, a, d, b);
- }
- public static void main(String[] args) {
- World.readWorld("Lesson3World3.kwld"); //reads and creates world
- World.setVisible();
- World.setDelay(20);
- Activity3Main waluigi = new Activity3Main(1,1, North, 1);
- for (int z = 0; z < 3; z++){ //turns left 3 times to give the program time to load
- waluigi.turnLeft();
- }
- for(int t = 0; t < 2; t++){ //loop - runs half the field twice
- waluigi.pickRowOfBeepers();
- waluigi.move(); //moves to face the next row
- waluigi.turnLeft();
- waluigi.move();
- waluigi.turnLeft();
- waluigi.pickRowOfBeepers();
- waluigi.move(); //moves to face the next row
- waluigi.turnRight();
- waluigi.move();
- waluigi.turnRight();
- }
- }
- /**
- * Robot picks a sing;e row of beepers
- * @param - none
- * @return - void
- */
- public void pickRowOfBeepers(){
- for(int x = 0; x < 7; x++){ //seven beepers = seven times
- move();
- pickBeeper();
- }
- }
- /**
- * allows the robot to instantaneously turn right
- * @param - none
- * @return - Void
- */
- public void turnRight(){
- int delay = World.delay();
- World.setDelay(0);
- turnLeft();
- turnLeft();
- World.setDelay(delay);
- turnLeft();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement