-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQueen.java
32 lines (28 loc) · 1.09 KB
/
Queen.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
package Chess;
public class Queen extends Piece{
public Queen(int color, Square location) {
super(color,location);
}
@Override
public boolean canMove(String to) {
boolean validMove = false;
Square targetLocation = location.getBoard().getSquareAt(to);
Square [] between = location.getBoard().getSquaresBetween(location,targetLocation);
// Queen can move only horizontal, vertical or diagonal. If player trying to move with different shape, it will return false.
if(this.location.isAtSameColumn(targetLocation) || this.location.isAtSameRow(targetLocation) || this.location.isAtSameDiagonal(targetLocation)){
for (Square square : between){
validMove = square.isEmpty();
}
if(!validMove){
if(targetLocation.getPiece() != null && targetLocation.getPiece().isEnemy(this))
validMove = true;
}
return validMove;
}
return false;
}
@Override
public String toString() {
return color == 0 ? "Q":"q";
}
}