-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGiant.java
More file actions
64 lines (58 loc) · 1.77 KB
/
Copy pathGiant.java
File metadata and controls
64 lines (58 loc) · 1.77 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
/**@Gilbert CS145 Giant
*@version 1.0 (04/22/2023)
*@see Giant class*/
import java.awt.*;
public class Giant extends Critter {
private int count;
private String giantName;
public Giant(){
count = 0;
giantName="fee";
}
/**Construct and initialize the getMove function
@param info gets the information where does the Giant moves*/
/**returns the move of the Giant
@return INFECT infects other animals in front of the Giant
@return HOP moves forward when there is an empty square in front of the Giant
@return RIGHT turns right if there is a wall in front of the Bear**/
public Action getMove(CritterInfo info) {
count++;
if (count == 6) {
if (giantName.equals("fee")){
giantName = "fie";
count = 0;
}
else if (giantName.equals("fie")){
giantName = "foe";
count = 0;
}
else if (giantName.equals("foe")){
giantName = "fum";
count = 0;
}
else if (giantName.equals("fum")){
giantName = "fee";
count = 0;
}
}
if (info.getFront() == Neighbor.OTHER) {
return Action.INFECT;
}
else if (info.getFront() == Neighbor.EMPTY ){
return Action.HOP;
}
else {
return Action.RIGHT;
}
}
/**returns the color of the Giant
@return GRAY makes the giant's color gray*/
public Color getColor() {
return Color.GRAY;
}
/**returns the String representing the Giant
@return giantName alternates different String every 6 steps to represent the giant*/
public String toString() {
return giantName;
}
}