Improved coverage maps & Queen loop bugfix
This commit is contained in:
parent
830d53f615
commit
bb9c4a9467
|
@ -203,7 +203,7 @@ public abstract class AbstractPiece implements IPiece {
|
|||
if(x == this.x && y == this.y) return;
|
||||
if(x < 0 || x >= moves.length || y < 0 || y >= moves.length) return;
|
||||
IPiece piece = chessboard.getPiece(new PiecePosition(x, y));
|
||||
if(piece != null && player == piece.getPlayer()) return;
|
||||
if(piece != null && piece != chessboard.getFloatingPiece() && player == piece.getPlayer()) return;
|
||||
moves[y][x] = true;
|
||||
}
|
||||
|
||||
|
@ -231,7 +231,8 @@ public abstract class AbstractPiece implements IPiece {
|
|||
int j = y + yDirection;
|
||||
while(i >= 0 && i < moves.length && j >= 0 && j < moves.length) {
|
||||
setPossibleMove(moves, i, j);
|
||||
if(chessboard.getPiece(new PiecePosition(i, j)) != null) break;
|
||||
IPiece piece = chessboard.getPiece(new PiecePosition(i, j));
|
||||
if(piece != null && piece != chessboard.getFloatingPiece()) break;
|
||||
i += xDirection;
|
||||
j += yDirection;
|
||||
}
|
||||
|
|
|
@ -305,7 +305,7 @@ public class Chessboard extends JPanel {
|
|||
boolean[][] player2Area = new boolean[SQUARE_COUNT][SQUARE_COUNT];
|
||||
for (IPiece[] pieces2 : pieces) {
|
||||
for (IPiece piece : pieces2) {
|
||||
if(piece != null) {
|
||||
if(piece != null && piece != floating) {
|
||||
if(piece.getPlayer() == player1) mergeCoverageAreas(player1Area, piece.getPossibleMoves(true));
|
||||
if(piece.getPlayer() == player2) mergeCoverageAreas(player2Area, piece.getPossibleMoves(true));
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ public class ChessboardMouseAdapter extends MouseAdapter {
|
|||
if (piece != null) {
|
||||
if(piece.getPlayer() != c.getActivePlayer()) return;
|
||||
c.grabPiece(pos);
|
||||
c.generateCoverageAreas();
|
||||
double totalScale = c.pieceScale * c.boardScale;
|
||||
piece.setOverride(me.getX() - 50 * totalScale, me.getY() - 50 * totalScale);
|
||||
c.repaint();
|
||||
|
|
|
@ -47,7 +47,7 @@ public class Queen extends AbstractPiece {
|
|||
int[] directions = new int[]{-1, 0, 1};
|
||||
for (int xDirection : directions) {
|
||||
for (int yDirection : directions) {
|
||||
tracePath(moves, xDirection, yDirection);
|
||||
if(yDirection != xDirection || yDirection != 0) tracePath(moves, xDirection, yDirection);
|
||||
}
|
||||
}
|
||||
return moves;
|
||||
|
|
Loading…
Reference in a new issue