| 01 | import stanford.karel.*; |
| 02 | |
| 03 | public class StoneMasonKarel extends SuperKarel { |
| 04 | public void run() { |
| 05 | //putting beepers into the broken columns in the world |
| 06 | |
| 07 | while (frontIsClear()) { |
| 08 | topOfColumn(); |
| 09 | putBeeperInColumn(); |
| 10 | nextColumn(); |
| 11 | } |
| 12 | topOfColumn(); |
| 13 | putBeeperInColumn(); |
| 14 | } |
| 15 | |
| 16 | public void topOfColumn() { |
| 17 | //getting to the top of the Column |
| 18 | |
| 19 | turnLeft(); |
| 20 | goToWall(); |
| 21 | turnAround(); |
| 22 | |
| 23 | } |
| 24 | public void putBeeperInColumn() { |
| 25 | //putting beepers into the empty parts of the column |
| 26 | |
| 27 | while (frontIsClear()) { |
| 28 | if (noBeepersPresent()) { |
| 29 | putBeeper(); |
| 30 | } |
| 31 | move(); |
| 32 | } |
| 33 | if (noBeepersPresent()) { |
| 34 | putBeeper(); |
| 35 | } |
| 36 | } |
| 37 | public void goToWall() { |
| 38 | while(frontIsClear()){ |
| 39 | move(); |
| 40 | } |
| 41 | } |
| 42 | public void nextColumn() { |
| 43 | //going to the next column in the world |
| 44 | |
| 45 | turnLeft(); |
| 46 | move(); |
| 47 | move(); |
| 48 | move(); |
| 49 | move(); |
| 50 | } |
| 51 | |
| 52 | } |