forked from sweskills/prog-method-assignment-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StoneMasonKarel.java
executable file
·76 lines (62 loc) · 1.62 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
* 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.
*/
import stanford.karel.*;
public class StoneMasonKarel extends SuperKarel {
// You fill in this part
public void run(){
turnLeft();
moveOn();
moveOn();
moveOn();
move();
turnRight();
moveFour();
turnRight();
moveOn();
move();
moveOn();
move();
turnLeft();
moveFour();
turnLeft();
moveOn();
moveOn();
move();
moveOn();
turnRight();
moveFour();
turnRight();
moveOn();
moveOn();
}
private void moveOn(){
if (beepersPresent()){
move();
}
if (frontIsClear() && !beepersPresent()){
putBeeper();
move();
}
else if (frontIsClear() && beepersPresent())
move();
else if (frontIsBlocked() && beepersPresent())
move();
else
putBeeper();
}
private void moveDouble(){
move();
move();
}
private void moveFour(){
moveDouble();
moveDouble();
}
}