-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZBug.java
executable file
·46 lines (41 loc) · 1.1 KB
/
ZBug.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
package apcs.gridWorld;
import info.gridworld.actor.Bug;
import java.awt.*;
import java.util.Random;
public class ZBug extends Bug {
private int steps;
private int side;
private final int sideLength;
private boolean done = false;
public ZBug(int length) {
steps = 0;
sideLength = length;
side = 0;
}
public void act() {
Random rand = new Random();
this.setColor(new Color(rand.nextFloat(), rand.nextFloat(), rand.nextFloat()));
if(steps == sideLength || side == 0) {
switch(side) {
case 3:
done = true;
break;
case 2:
turn();
turn();
case 1:
turn();
case 0:
turn();
turn();
default:
steps = 0;
side++;
}
}
if(!done) {
move();
steps++;
}
}
}