-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHungryCritter.java
More file actions
69 lines (59 loc) · 1.39 KB
/
Copy pathHungryCritter.java
File metadata and controls
69 lines (59 loc) · 1.39 KB
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
/* CRITTERS Main.java
* EE422C Project 5 submission by
* Anthony Bauer
* amb6869
* 16480
* Grant Uy
* gau84
* 16480
* Slip days used: <0>
* Fall 2016
*/
package assignment5;
import javafx.scene.paint.Color;
/**
* HungryCritter
* The HungryCritter will move in a random default direction
* Upon entering a fight with nonAlgae the Hungry Critter will look for an empty spot and move to it
*/
public class HungryCritter extends Critter {
@Override
public CritterShape viewShape() {
return CritterShape.TRIANGLE;
}
@Override
public Color viewOutlineColor() {
return Color.BLACK;
}
@Override
public Color viewFillColor() {
return Color.FIREBRICK;
}
@Override
public String toString() { return "H"; }
private int dir;
public HungryCritter() {
dir = Critter.getRandomInt(8);
}
public boolean fight(String opponent) {
if(opponent.equals("@"))
return true;
for (int dir = 0; dir < 8; dir++) {
if(this.look(dir, false) == null) {
walk(dir);
return false;
}
}
for (int dir = 0; dir < 8; dir++) {
if(this.look(dir, true) == null) {
run(dir);
return false;
}
}
return false;
}
@Override
public void doTimeStep() {
walk(dir);
}
}