-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRules.java
More file actions
147 lines (132 loc) · 6.33 KB
/
Rules.java
File metadata and controls
147 lines (132 loc) · 6.33 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import java.util.Scanner;
/**
* @author John Henry Cooper
* @version 15.0.2
* Contains all rules for if an action is valid or not
*/
public class Rules {
/**
* Cheks if an action is valid
* @param gameS22 The active game
* @param fromRow The row index of the desired piece
* @param fromColumn The column index of the desired piece
* @param toRow The row index of the destination
* @param toColumn The column index of the destination
* @param action the desired action
* @return boolean
*/
public static boolean checkValidAction(Game gameS22, int fromRow, int fromColumn, int toRow, int toColumn, char action) {
Piece piece1;
Piece piece2;
Boolean piece2Valid;
BoardSquare[][] boardSquares = gameS22.getBoardSquares();
if (boardSquares[fromRow][fromColumn].isEmpty()){
System.out.println("Invalid Action");
return false;
}
if(!boardSquares[fromRow][fromColumn].isEmpty()){
piece1 = boardSquares[fromRow][fromColumn].getPiece();
Boolean piece1Valid = ((piece1 != null) && (piece1.getTeamColor().equals(gameS22.getCurrentTeam().teamColor)));
if (!piece1Valid){
System.out.println("Invalid Action");
return false;
}
}
piece1 = boardSquares[fromRow][fromColumn].getPiece();
String currentTeam = gameS22.getCurrentTeam().getTeamColor();
String opposingTeam = gameS22.getOpponentTeam().getTeamColor();
Boolean fromInBounds = gameS22.getGameBoard().inBounds(fromRow, fromColumn);
Boolean toInBounds = gameS22.getGameBoard().inBounds(toRow, toColumn);
Boolean isValidMovePath = piece1.validMovePath(fromRow, fromColumn, toRow, toColumn);
Boolean isValidSpawnPath = piece1.validSpawnPath(fromRow,fromColumn,toRow,toColumn);
Boolean isValidRecruitPath = piece1.validRecruitPath(fromRow, fromColumn, toRow, toColumn);
Boolean isValidAttackPath = piece1.validAttackPath(fromRow, fromColumn, toRow, toColumn);
if (fromInBounds && toInBounds) {
if (action == 'M') {
if (boardSquares[toRow][toColumn].isEmpty() && isValidMovePath) {
return true;
}
}
if (action == 'S') {
//Modified
if (!(piece1 instanceof PieceBuzz) && !(piece1 instanceof PieceGuard) && isValidSpawnPath) {
System.out.println("the path is valid");
if (piece1 instanceof PieceMinion && !(piece1 instanceof PieceEvilMinion)){
if(boardSquares[toRow][toColumn]== gameS22.NearestEmptyCorner(fromRow,fromColumn)){
return true;
}
}
if (boardSquares[toRow][toColumn].isEmpty()) {
if (piece1 instanceof PieceEvilMinion){
return piece1.canSpawn();
}
return true;
}
}
}
if (action == 'R') {
if (!(piece1 instanceof PieceBuzz) && isValidRecruitPath) {
if(!boardSquares[toRow][toColumn].isEmpty()) {
piece2 = boardSquares[toRow][toColumn].getPiece();
piece2Valid = ((piece2 != null) && (piece2.getTeamColor().equals(gameS22.getOpponentTeam().teamColor)));
if (piece2Valid) {
return true;
}
}
}
}
if (action == 'A'&& isValidAttackPath) {
if(piece1 instanceof PieceEvilMinion && !boardSquares[toRow][toColumn].isEmpty()){
piece2 = boardSquares[toRow][toColumn].getPiece();
piece2Valid = ((piece2 != null) && (piece2.getTeamColor().equals(gameS22.getOpponentTeam().teamColor)));
if (piece2Valid || piece2 instanceof PieceMinion){
if(((PieceEvilMinion) piece1).hungry){
return true;
}
}
}
if(!(piece1 instanceof PieceMinion) && !boardSquares[toRow][toColumn].isEmpty()) {
piece2 = boardSquares[toRow][toColumn].getPiece();
piece2Valid = ((piece2 != null) && (piece2.getTeamColor().equals(gameS22.getOpponentTeam().teamColor)));
if (piece1 instanceof PieceBuzz) {
if (piece2Valid && ((PieceBuzz) piece1).workingLaser) {
return true;
}
}
if (piece1 instanceof PieceBlueHen) {
if (piece2Valid) {
return true;
}
}
// New Piece Modification
if (piece1 instanceof PieceArcher && piece2Valid){
if(!(piece1 instanceof PieceGuard) && !(piece2 instanceof PieceGuard)){
if(piece2 instanceof PieceArcher) {
((PieceArcher) piece1).setNumAttacks(0);
return true;
}
return true;
}
// New Extended Piece Modification
if(piece1 instanceof PieceGuard) {
if(((PieceGuard) piece1).getWorkingShield()) {
return true;
}
}
}
}
}
// New Action Modification
if (action == 'T'){
if (piece1 instanceof PieceGuard && ((PieceGuard) piece1).numThrows < 1){
if(((PieceGuard) piece1).validThrowSpearPath(fromRow,fromColumn,toRow,toColumn)) {
((PieceGuard) piece1).numThrows++;
return true;
}
}
}
}
System.out.println("Invalid Action");
return false;
}
}