xArtixFox

Karel the Dog Building Multiple Towers

Dec 12th, 2019
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1.  
  2. //Karel will put 8 balls at each corner and continue.
  3. public class RacingKarel extends SuperKarel
  4. {
  5.     public void run()
  6.     {  
  7.         while (frontIsClear())
  8.         {
  9.             move();
  10.         }
  11.         while(frontIsBlocked())
  12.         {
  13.             for (int i=0; i < 8; i++)
  14.             {
  15.                 putBall();
  16.             }
  17.             turnLeft();
  18.         }
  19.         
  20.         while (frontIsClear())
  21.         {
  22.             move();
  23.         }
  24.         while(frontIsBlocked())
  25.         {
  26.             for (int i=0; i < 8; i++)
  27.             {
  28.                 putBall();
  29.             }
  30.             turnLeft();
  31.         }
  32.         
  33.         while (frontIsClear())
  34.         {
  35.             move();
  36.         }
  37.         while(frontIsBlocked())
  38.         {
  39.             for (int i=0; i < 8; i++)
  40.             {
  41.                 putBall();
  42.             }
  43.             cactus();
  44.         }
  45.         
  46.         while (frontIsClear())
  47.         {
  48.             move();
  49.         }
  50.         while(frontIsBlocked())
  51.         {
  52.             for (int i=0; i < 8; i++)
  53.             {
  54.                 putBall();
  55.             }
  56.             potato();
  57.         }
  58.     }    
  59.     private void cactus()
  60.     {
  61.         turnLeft();
  62.     }
  63.     private void potato()
  64.     {
  65.         turnLeft();
  66.     }
  67. }
Add Comment
Please, Sign In to add comment