Advertisement
KevinNT03

Karel - Climbing Staircase and Picking Beepers

Nov 15th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.26 KB | None | 0 0
  1. package Activity2;
  2. import kareltherobot.*;
  3.  
  4. public class Activity2Main extends UrRobot{
  5.  
  6.     public Activity2Main (int s, int a, Direction d, int b){
  7.         super(s, a, d, b);
  8.     }
  9.  
  10.     public static void main(String[] args) {
  11.  
  12.         World.readWorld("Lesson3World2.kwld"); //reading and creating world
  13.         World.setVisible();
  14.         World.setDelay(25);
  15.  
  16.         Activity2Main kratos = new Activity2Main(1,1, North, 0);
  17.  
  18.         for(int i = 0; i < 4; i++){ //robot spins in place to give the program time to load
  19.             kratos.turnLeft();
  20.         }
  21.  
  22.         for(int y = 0; y < 7; y++){ //loop executes seven times - seven steps
  23.             kratos.climbStep();
  24.             kratos.pickBeeper();
  25.         }
  26.        
  27.     }
  28.  
  29.     /**
  30.      * The robot climbs one step up
  31.      * @param - none
  32.      * @return - none
  33.      */
  34.     public void climbStep(){
  35.         move();
  36.         turnRight();
  37.         move();
  38.         turnLeft();
  39.     }
  40.  
  41.     /**
  42.      * allows the robot to instantaneously turn right
  43.      * @param - none
  44.      * @return - none
  45.      */
  46.     public void turnRight(){
  47.         int delay = World.delay();
  48.         World.setDelay(0);
  49.         turnLeft();
  50.         turnLeft();
  51.         World.setDelay(delay);
  52.         turnLeft();
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement