50 lines
1.2 KiB
Java
50 lines
1.2 KiB
Java
import java.awt.*;
|
|
|
|
/**
|
|
* Knight piece class
|
|
*/
|
|
public class Knight extends APiece {
|
|
|
|
/**
|
|
* Create new Knight piece
|
|
* @param player player
|
|
* @param x piece's X location
|
|
* @param y piece's Y location
|
|
*/
|
|
public Knight(Player player, int x, int y) {
|
|
super(player, x, y);
|
|
}
|
|
|
|
/**
|
|
* Paint the Knight piece
|
|
* @param g2 Graphics2D
|
|
*/
|
|
@Override
|
|
public void paint(Graphics2D g2) {
|
|
|
|
double[] xObject1 = new double[]{21, 62, 82, 82, 70, 30, 30, 44, 41, 30, 15, 14, 28};
|
|
double[] yObject1 = new double[]{0, 0, 18, 44, 58, 58, 50, 33, 30, 43, 43, 31, 10};
|
|
|
|
paintObjects(g2, new Shape[]{getStand(), getObject(xObject1, yObject1)});
|
|
|
|
}
|
|
|
|
/**
|
|
* Get Knight's possible moves
|
|
* @param attack force the attack mode
|
|
* @return two-dimensional array of moves
|
|
*/
|
|
@Override
|
|
public boolean[][] getPossibleMoves(boolean attack) {
|
|
boolean[][] moves = new boolean[chessboard.SQUARE_COUNT][chessboard.SQUARE_COUNT];
|
|
for (int i : new int[]{-1, 1}) {
|
|
for (int j : new int[]{-2, 2}) {
|
|
setPossibleMove(moves, x+i, y+j);
|
|
setPossibleMove(moves, x+j, y+i);
|
|
}
|
|
}
|
|
return moves;
|
|
}
|
|
|
|
}
|