Advertisement
KevinNT03

Karel - Tower Climber

Dec 12th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. package Activity2;
  2. import kareltherobot.*;
  3.  
  4. /**
  5.  * This program makes a robot walk forward until it finds the tower of beepers, and then climb it
  6.  */
  7. public class Activity2Main extends Robot{
  8.  
  9.     public Activity2Main(int s, int a, Direction d, int b){
  10.         super(s, a, d, b);
  11.     }
  12.  
  13.     public static void main(String[] args){
  14.         World.setVisible(); //generates world
  15.         World.setDelay(35);
  16.         World.readWorld("Lesson4World2.kwld");
  17.  
  18.         Activity2Main toad = new Activity2Main(1,1, East, 0);
  19.  
  20.         while(!toad.nextToABeeper()){ //while there aren't any beepers, keep walking
  21.             toad.move();
  22.         }
  23.  
  24.         toad.turnLeft();
  25.  
  26.         while(toad.nextToABeeper()){ //while there are beepers, keep walking
  27.             toad.move();
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement