-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPieceGuard.java
More file actions
133 lines (120 loc) · 3.84 KB
/
PieceGuard.java
File metadata and controls
133 lines (120 loc) · 3.84 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/**
* @author John Henry Cooper
* @version 15.0.2
* Contains All methods and member fields for a PieceGuard object. (getters , setters, constructors, valid action methods, can methods)
*
*/
public class PieceGuard extends PieceArcher{
// New Extended Piece Modification
protected int health;
public int numThrows;
public boolean workingShield;
public static int MAX_NUM_TIMES_SPAWNED = 2;
public static int MAX_THROWS = 1;
public PieceGuard(char symbol, String teamColor, int numAttacks, int numTimesSpawned, boolean hidden, boolean original, int health, int numThrows, boolean workingShield){
super(symbol,teamColor,numAttacks,numTimesSpawned,hidden,original);
this.health = health;
this.numThrows = numThrows;
this.workingShield = workingShield;
}
public PieceGuard (){
this ('G',"NAN",0,0,false,true,3,0,true);
}
public int getHealth(){
return health;
}
public int getNumThrows(){
return numThrows;
}
public boolean getWorkingShield(){
return workingShield;
}
public void setHealth(int health) {
this.health = health;
}
public void setWorkingShield(boolean workingShield){
this.workingShield = workingShield;
}
/**
* Prints "Stabdubg Guard!"
*/
public void speak(){
System.out.println("Standing Guard!");
}
/**
* @param fromRow
* @param fromColumn
* @param toRow
* @param toColumn
* @return boolean
* checks if the action path is valid
*/
public boolean validAttackPath(int fromRow, int fromColumn, int toRow, int toColumn) {
if ((fromRow == toRow) && ( toColumn == fromColumn + 1 || toColumn == fromColumn - 1)){
return true;
}
else if ((fromColumn == toColumn) && (toRow == fromRow + 1)){
return true;
}
else if ((toRow == fromRow + 1) && ( toColumn == fromColumn + 1 || toColumn == fromColumn - 1)){
return true;
}
return false;
}
/**
* @param fromRow
* @param fromColumn
* @param toRow
* @param toColumn
* @return boolean
* checks if the action path is valid
*/
public boolean validSpawnPath(int fromRow , int fromColumn , int toRow, int toColumn) {
return ((toRow == fromRow ) && ((toColumn == fromColumn - 1) || (toColumn == fromColumn + 1)));
}
/**
* @param fromRow
* @param fromColumn
* @param toRow
* @param toColumn
* @return boolean
* checks if the action path is valid
*/
public boolean validMovePath(int fromRow , int fromColumn , int toRow , int toColumn){
return ((toRow == fromRow + 1 || toRow == fromRow -1) && (fromColumn == toColumn));
}
/**
* @param fromRow
* @param fromColumn
* @param toRow
* @param toColumn
* @return boolean
* checks if the action path is valid
*/
public boolean validThrowSpearPath(int fromRow , int fromColumn , int toRow , int toColumn){
if(getTeamColor().equals("Blu")){
return ((fromColumn==toColumn) && (toRow<fromRow));
}
return((fromColumn==toColumn)&& (toRow>fromRow));
}
public boolean canSpawn() {
return (this.getNumTimesSpawned() < MAX_NUM_TIMES_SPAWNED);
}
/**
*
* @return boolean
* checks if the number of attacks is less then max
*/
public boolean canThrow(){
return (this.numThrows < MAX_THROWS);
}
/**
* Setter for health, If health reaches zero, sets workingShield to false
*/
public void updateHealth(){
this.health--;
if (this.health <= 0){
this.workingShield = false;
}
}
}