Advertisement
FrankyDM

Untitled

Nov 15th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.52 KB | None | 0 0
  1. package Lesson3;
  2. import kareltherobot.*;
  3.  
  4. /**
  5.  * This program makes the Karel robot go up the stairs picking up the beepers along the way
  6.  */
  7. public class Lesson3Activity2 extends UrRobot{
  8.  
  9.     /**
  10.      * Constructor
  11.      * @param x
  12.      * @param y
  13.      * @param d
  14.      * @param b
  15.      */
  16.     public Lesson3Activity2 (int x, int y, Direction d, int b) {
  17.         super(x, y, d, b);
  18.     }
  19.  
  20.     /**
  21.      * Main function puts together for loop to repeat the step up 6 times for 6 steps, it then goes up the final step
  22.      * @param args
  23.      */
  24.     public static void main(String[] args) {
  25.         World.setDelay(15);
  26.         World.setVisible();
  27.         Lesson3Activity2 MrDaddy = new Lesson3Activity2(1,1,North, 0);
  28.         World.readWorld("Lesson3World2.kwld");
  29.  
  30.  
  31.         for (int index = 0; index < 6; index++) {
  32.             MrDaddy.stepIt();
  33.         }
  34.  
  35.         MrDaddy.stepIt();
  36.  
  37.         MrDaddy.move();
  38.     }
  39.  
  40.     /**
  41.      * Function just to appear to turn right instantaneously. Used to make visuals smoother
  42.      */
  43.     public void turnRight(){
  44.         int delay = World.delay();
  45.         World.setDelay(0);
  46.         turnLeft();
  47.         turnLeft();
  48.         World.setDelay(delay);
  49.         turnLeft();
  50.     }
  51.  
  52.     /**
  53.      * Primary function for the program. Does everything: goes up, turns towards next stair, goes on next stair and picks up beeper, faces forward
  54.      */
  55.     public void stepIt(){
  56.         move();
  57.         turnRight();
  58.         move();
  59.         pickBeeper();
  60.         turnLeft();
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement