daily pastebin goal
41%
SHARE
TWEET

Untitled

a guest Dec 16th, 2018 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. import stanford.karel.*;
  3.  
  4. public class FirstProgram extends SuperKarel {
  5.  
  6.     private int worldWidth = 0;
  7.     private int worldHeight = 0;
  8.  
  9.     public void run() {
  10.  
  11.         checkForWorldSize();
  12.         checkForBeeper();
  13.  
  14.         for (int i = 0; i < Math.min(worldWidth, worldHeight); i++) {
  15.             move();
  16.             turnLeft();
  17.             move();
  18.             turnRight();
  19.             checkForBeeper();
  20.         }
  21.  
  22.         turnRight();
  23.  
  24.         moveTillBlocked();
  25.  
  26.         turnLeft();
  27.         checkForBeeper();
  28.  
  29.         for (int i = 0; i < Math.min(worldWidth, worldHeight); i++) {
  30.             move();
  31.             turnRight();
  32.             move();
  33.             turnLeft();
  34.             checkForBeeper();
  35.         }
  36.     }
  37.  
  38.     private void checkForWorldSize() {
  39.         while (frontIsClear()) {
  40.             move();
  41.             worldWidth++;
  42.         }
  43.         goBack();
  44.         turnLeft();
  45.         while (frontIsClear()) {
  46.             move();
  47.             worldHeight++;
  48.         }
  49.         goBack();
  50.         turnRight();
  51.     }
  52.  
  53.     private void goBack() {
  54.         turnAround();
  55.         while (frontIsClear()) {
  56.             move();
  57.         }
  58.         turnAround();
  59.     }
  60.  
  61.     private void checkForBeeper() {
  62.         if (noBeepersPresent())
  63.             putBeeper();
  64.     }
  65.  
  66.     private void moveTillBlocked() {
  67.         while (frontIsClear()) {
  68.             move();
  69.         }
  70.     }
  71. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top