-
Notifications
You must be signed in to change notification settings - Fork 0
/
StoneMasonKarel.java
60 lines (53 loc) · 1.48 KB
/
StoneMasonKarel.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* File: StoneMasonKarel.java
* --------------------------
* The StoneMasonKarel subclass as it appears here does nothing.
* When you finish writing it, it should solve the "repair the quad"
* problem from Assignment 1. In addition to editing the program,
* you should be sure to edit this comment so that it no longer
* indicates that the program does nothing.
*
* This program now runs Karel successfully in the maps that are provided.
*/
public class StoneMasonKarel extends SuperDuperKarel {
public void run() {
while (frontIsClear()){
karelRestoresColumn();
moveKarelEast();
}
karelRestoresColumn();
faceDirection(Direction.EAST);
}
/*
This method moves Karel east to the next column
*/
private void moveKarelEast() {
faceDirection(Direction.EAST);
move();
move();
move();
move();
}
/*
This is a helper function which turns Karel until it is facing in the desired compass direction.
*/
/*
This method has Karel restore the column
*/
private void karelRestoresColumn() {
faceDirection(Direction.NORTH);
while (frontIsClear()) {
if (noBeepersPresent()) {
putBeeper();
}
move();
}
if (noBeepersPresent()){
putBeeper();
}
faceDirection(Direction.SOUTH);
while (frontIsClear()) {
move();
}
}
}