Advertisement
seby_stephens

Lesson 3 Activity 2

Nov 15th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 KB | None | 0 0
  1. package Lesson3;
  2. //This is meant to go up the stairs and pick up beepers at each step to clear them
  3. import kareltherobot.UrRobot;
  4. import kareltherobot.World;
  5.  
  6. public class Activity2Main extends UrRobot {
  7.     public Activity2Main(int a, int s, Direction d, int b) {
  8.         super(a, s, d, b);
  9.     }
  10.  
  11.     public static void main(String[] args) {
  12.         World.readWorld("Lesson3World2.kwld");
  13.         World.setDelay(60);
  14.         World.setVisible();
  15.         Activity2Main gary = new Activity2Main(1, 1, North, 0);
  16.         //Does the step 7 times since there are 7 steps on stairs
  17.         for(int i = 0; i<7;i++){
  18.             gary.riseUp();
  19.         }
  20.     }
  21.  
  22.     /**
  23.      * Allows the robot to turn right
  24.      * @ param - none
  25.      * @ return - void
  26.      */
  27.     public void turnRight(){
  28.         int delay = World.delay();
  29.         World.setDelay(0);
  30.         turnLeft();
  31.         turnLeft();
  32.         World.setDelay(delay);
  33.         turnLeft();
  34.     }
  35.  
  36.     /**
  37.      * Allows robot to take a step on the stair and pick up a beeper
  38.      * @ param - none
  39.      * @ return - void
  40.      */
  41.     public void riseUp(){
  42.         move();
  43.         turnRight();
  44.         move();
  45.         pickBeeper();
  46.         turnLeft();
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement