Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Lesson3;
- import kareltherobot.*;
- /**
- * This program makes the Karel robot go up the stairs picking up the beepers along the way
- */
- public class Lesson3Activity2 extends UrRobot{
- /**
- * Constructor
- * @param x
- * @param y
- * @param d
- * @param b
- */
- public Lesson3Activity2 (int x, int y, Direction d, int b) {
- super(x, y, d, b);
- }
- /**
- * Main function puts together for loop to repeat the step up 6 times for 6 steps, it then goes up the final step
- * @param args
- */
- public static void main(String[] args) {
- World.setDelay(15);
- World.setVisible();
- Lesson3Activity2 MrDaddy = new Lesson3Activity2(1,1,North, 0);
- World.readWorld("Lesson3World2.kwld");
- for (int index = 0; index < 6; index++) {
- MrDaddy.stepIt();
- }
- MrDaddy.stepIt();
- MrDaddy.move();
- }
- /**
- * Function just to appear to turn right instantaneously. Used to make visuals smoother
- */
- public void turnRight(){
- int delay = World.delay();
- World.setDelay(0);
- turnLeft();
- turnLeft();
- World.setDelay(delay);
- turnLeft();
- }
- /**
- * Primary function for the program. Does everything: goes up, turns towards next stair, goes on next stair and picks up beeper, faces forward
- */
- public void stepIt(){
- move();
- turnRight();
- move();
- pickBeeper();
- turnLeft();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement