-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bear.java
32 lines (27 loc) · 1.08 KB
/
Bear.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
import java.awt.*;
public class Bear extends Critter {
private boolean polar = false;
private String move = "/";
public Bear(boolean polar) {
this.polar = polar;
}
// always infect if an enemy is in front, otherwise hop if possible, otherwise turn left.
public Action getMove(CritterInfo info) {
if (info.getFront() == Neighbor.OTHER) { return Action.INFECT; }
else if (info.getFront() == Neighbor.EMPTY) { return Action.HOP; }
else { return Action.LEFT; }
}
// Color.WHITE for a polar bear (when polar is true), Color.BLACK otherwise (when polar is false)
public Color getColor() {
if (this.polar) { return Color.WHITE; }
else { return Color.BLACK; }
}
// Should alternate on each different move between a slash character (/) and a backslash character () starting
// with a slash.
public String toString() {
String myChar = this.move;
if (this.move.equals("/")) { this.move = "\\"; }
else { this.move = "/"; }
return myChar;
}
}