1.5.4: Pancakes, 1.5.5: Mario Karel

Code for these lessons:

1.5.4: Pancakes

  1. public void run(){
  2.      move();
  3.      putBall();
  4.      putBall();
  5.      putBall();
  6.      move();
  7.      move();
  8.      putBall();
  9.      putBall();
  10.      putBall();
  11.      move();
  12.      move();
  13.      putBall();
  14.      putBall();
  15.      putBall();
  16.      move();
  17. }

1.5.5: Mario Karel

  1. public void run(){
  2.      move();
  3.      jumpUp();
  4.      move();
  5.      move();
  6.      jumpDown();
  7.      move();
  8.      move();
  9.      jumpUp();
  10.      move();
  11.      move();
  12.      jumpDown();
  13. }
  14. private void jumpUp(){
  15.      turnLeft();
  16.      for(int i = 0; i < 4; i++){
  17.           move();
  18.           if(ballsPresent()){
  19.                takeBall();
  20.                takeBall();
  21.           }
  22.      }
  23.      turnRight();
  24. }
  25. private void jumpDown(){
  26.      turnRight();
  27.      for(int i = 0; i < 4; i++){
  28.           move();
  29.           if(ballsPresent()){
  30.                takeBall();
  31.                takeBall();
  32.           }
  33.      }
  34.      turnLeft();
  35. }
  36. private void turnRight(){
  37.      turnLeft();
  38.      turnLeft();
  39.      turnLeft();
  40. }

Comments

Post a Comment

Popular posts from this blog

1.9.5: Marathon Karel, 1.9.6: Take 'em All, 1.9.7: Dizzy Karel, 1.9.8: For Loop Square, 1.9.9: Lots of Hurdles

1.4.4: Slide Karel, 1.4.5: Fireman Karel