-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChessPieceKing.java
45 lines (37 loc) · 1.13 KB
/
ChessPieceKing.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
/**
* This class represents the King chess piece.
*/
package main;
import java.awt.Color;
import java.util.ArrayList;
import java.util.List;
import javax.swing.ImageIcon;
public class ChessPieceKing extends ChessPiece
{
/**
* STANDARD JAVA CONVENTION
*/
private static final long serialVersionUID = 1L;
public ChessPieceKing(Color color, ImageIcon representation, int x, int y)
{
super(color, representation, x, y, "X");
ImageIcon image;
//Used to update piece, based on color and actual piece
if (color.equals(Color.BLACK)){
image = new ImageIcon( getClass().getResource("/resources/ChessPieces/blackKing.png") );
this.representation = image;
}else{
image = new ImageIcon( getClass().getResource("/resources/ChessPieces/whiteKing.png") );
this.representation = image;
}
}
@Override
public List<ChessSquare> getPath(ChessBoard board, int x, int y)
{
List<ChessSquare> path = new ArrayList<ChessSquare>();
//Kings can only move one square adjacent to their current position at a time
if (Math.abs(this.x - x) <=1 && Math.abs(this.y - y) <= 1)
path.add(board.getChessSquare(x, y));
return path;
}
}