-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKing.java
53 lines (42 loc) · 1.69 KB
/
King.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**************************************************************
* Functionality for each King Piece
*
* @author Richard
* @author Steven
* @version 3/13/2022
**************************************************************/
public class King extends ChessPiece {
/*************************************************************
* Default constructor calls the ChessPiece constructor
*************************************************************/
public King(Player player) {
super(player);
}
/*************************************************************
* Returns the type of chesspiece
*************************************************************/
public String type() {
return "King";
}
/*************************************************************
* Verifies that the selected space is within the king's
* ability to go to
*************************************************************/
private boolean isMovementASingleUnit(Move move, ChessPiece[][] board) {
if (Math.abs(move.fromColumn - move.toColumn) < 2
&& Math.abs(move.fromRow - move.toRow) < 2) {
return true;
}
return false;
}
/*************************************************************
* Verifies that the king can move to selected space
*************************************************************/
public boolean isValidMove(Move move, ChessPiece[][] board) {
if (!super.isValidMove(move, board))
return false;
if (!isMovementASingleUnit(move, board))
return false;
return true;
}
}