Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Lesson4;
- import kareltherobot.Robot;
- import kareltherobot.World;
- //This program uses while loops to move the robot until it hits the tower of beeper and then allows it to climb up tower.
- public class Activity2Main extends Robot {
- /**
- * Constructorfor Activity2Main class
- * @param a
- * @param s
- * @param d
- * @param b
- * @ return - none
- */
- public Activity2Main(int a,int s,Direction d, int b){
- super(a,s,d,b);
- }
- public static void main(String[] args){
- World.readWorld("Lesson4World2.kwld");
- World.setDelay(100);
- World.setVisible();
- Activity2Main gary = new Activity2Main(1,1,East, 0);
- //Moves robot forward every time there is no beeper
- while(!(gary.nextToABeeper())) {
- gary.move();
- }
- //Turns left when the robot hits the first beeper
- gary.turnLeft();
- //Moves robot forward every time it is on beeper so it climbs up tower
- while(gary.nextToABeeper()){
- gary.move();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement