62 lines
1.8 KiB
Java
62 lines
1.8 KiB
Java
import java.awt.*;
|
|
import java.awt.geom.Area;
|
|
import java.awt.geom.Ellipse2D;
|
|
import java.awt.geom.Path2D;
|
|
|
|
/**
|
|
* Queen piece class
|
|
*/
|
|
public class Queen extends APiece {
|
|
|
|
/**
|
|
* Create new Queen piece
|
|
* @param player player
|
|
* @param x piece's X location
|
|
* @param y piece's Y location
|
|
*/
|
|
public Queen(Player player, int x, int y) {
|
|
super(player, x, y);
|
|
}
|
|
|
|
/**
|
|
* Paint the Queen piece
|
|
* @param g2 Graphics2D
|
|
*/
|
|
@Override
|
|
public void paint(Graphics2D g2) {
|
|
|
|
double[] xObject1 = new double[]{18, 27, 34, 43, 50, 57, 66, 73, 82, 70, 70, 30, 30};
|
|
double[] yObject1 = new double[]{27, 33, 26, 33, 26, 33, 26, 33, 27, 52, 58, 58, 52};
|
|
|
|
double[] xObjectClip = new double[]{27, 73, 73, 66, 57, 50, 43, 34, 27};
|
|
double[] yObjectClip = new double[]{0, 0, 28, 21, 28, 21, 28, 21, 28};
|
|
|
|
Path2D objectClip = getObject(xObjectClip, yObjectClip);
|
|
Ellipse2D ellipse = getEllipse(30, 6, 40, 40);
|
|
Ellipse2D ellipse2 = getEllipse(44, 0, 12, 12);
|
|
Area intersection = new Area(ellipse);
|
|
intersection.intersect(new Area(objectClip));
|
|
|
|
paintObjects(g2, new Shape[]{getStand(), getObject(xObject1, yObject1), ellipse2, intersection});
|
|
|
|
}
|
|
|
|
/**
|
|
* Get Queen'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[] directions = new int[]{-1, 0, 1};
|
|
for (int xDirection : directions) {
|
|
for (int yDirection : directions) {
|
|
if(yDirection != xDirection || yDirection != 0) tracePath(moves, xDirection, yDirection);
|
|
}
|
|
}
|
|
return moves;
|
|
}
|
|
|
|
}
|