Chess/src/Rook.java
2023-05-06 22:54:26 +02:00

49 lines
1.3 KiB
Java

import java.awt.*;
/**
* Rook piece class
*/
public class Rook extends APiece {
/**
* Create new Rook piece
* @param player player
* @param x piece's X location
* @param y piece's Y location
*/
public Rook(Player player, int x, int y) {
super(player, x, y);
}
/**
* Paint the Rook piece
* @param g2 Graphics2D
*/
@Override
public void paint(Graphics2D g2) {
double[] xObject1 = new double[]{17, 30, 30, 38, 38, 62, 62, 70, 70, 83, 83, 70, 30, 17};
double[] yObject1 = new double[]{10, 10, 21, 21, 10, 10, 21, 21, 10, 10, 46, 58, 58, 46};
paintObjects(g2, new Shape[]{getStand(), getObject(xObject1, yObject1)});
}
/**
* Get Rook'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];
int[] xDirections = new int[]{1, 0, -1, 0};
int[] yDirections = new int[]{0, 1, 0, -1};
for (int i = 0; i < xDirections.length; i++) {
tracePath(moves, xDirections[i], yDirections[i]);
}
return moves;
}
}