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

62 lines
1.7 KiB
Java

import java.awt.*;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
/**
* Bishop piece class
*/
public class Bishop extends APiece {
/**
* Create new Bishop piece
* @param player player
* @param x piece's X location
* @param y piece's Y location
*/
public Bishop(Player player, int x, int y) {
super(player, x, y);
}
/**
* Paint the Bishop piece
* @param g2 Graphics2D
*/
@Override
public void paint(Graphics2D g2) {
double[] xObject1 = new double[]{50, 75, 70, 70, 30, 30, 25};
double[] yObject1 = new double[]{0, 21, 57, 64, 64, 57, 21};
double[] xObjectSubtract = new double[]{47, 53, 53, 62, 62, 53, 53, 47, 47, 38, 38, 47};
double[] yObjectSubtract = new double[]{19, 19, 28, 28, 34, 34, 48, 48, 34, 34, 28, 28};
Ellipse2D ellipse = getEllipse(18, 11.412, 64, 51);
Area area = new Area(getStand());
area.add(new Area(getObject(xObject1, yObject1)));
area.add(new Area(ellipse));
area.subtract(new Area(getObject(xObjectSubtract, yObjectSubtract)));
paintObjects(g2, new Shape[]{area});
}
/**
* Get Bishop's possible moves
* @param attack force the attack mode
* @return two-dimensional array of possible moves
*/
@Override
public boolean[][] getPossibleMoves(boolean attack) {
boolean[][] moves = new boolean[chessboard.SQUARE_COUNT][chessboard.SQUARE_COUNT];
int[] directions = new int[]{-1, 1};
for (int xDirection : directions) {
for (int yDirection : directions) {
tracePath(moves, xDirection, yDirection);
}
}
return moves;
}
}