gör getCastleMove mer tydlig

This commit is contained in:
loveb 2022-05-12 08:36:19 +02:00
parent 9d1916ad17
commit d5244cea94
2 changed files with 9 additions and 7 deletions

View File

@ -146,12 +146,12 @@ public class Board extends JPanel implements MouseListener {
continue; continue;
} }
if (attacked.supremeRuler) { if (attacked.supremeRuler) {
validMovesToDraw.clear();
getParent().repaint();
// Kolla ifall vi är i schackmatt // Kolla ifall vi är i schackmatt
if (weCanMove) { if (weCanMove) {
JOptionPane.showMessageDialog(this, "Du står i schack"); JOptionPane.showMessageDialog(this, "Du står i schack");
} else { } else {
validMovesToDraw.clear();
getParent().repaint();
int choise = JOptionPane.showConfirmDialog(this, "Schackmatt\nVill du starta om?"); int choise = JOptionPane.showConfirmDialog(this, "Schackmatt\nVill du starta om?");
if (choise == JOptionPane.YES_OPTION) { if (choise == JOptionPane.YES_OPTION) {
restartGame(); restartGame();

View File

@ -11,9 +11,10 @@ public final class King extends PieceKnownIfMoved {
supremeRuler = true; supremeRuler = true;
} }
private void addCastlingIfCan(Piece[][] pieces, ArrayList<Point> movable, Point toMove, Point selected) { private ArrayList<Point> getCastlingIfPossible(Piece[][] pieces) {
ArrayList<Point> possibleCastling = new ArrayList<>();
if (isMoved()) { if (isMoved()) {
return; return possibleCastling;
} }
// Vänster // Vänster
@ -27,7 +28,7 @@ public final class King extends PieceKnownIfMoved {
Piece p = pieces[loopX][this.position.y]; Piece p = pieces[loopX][this.position.y];
if (p != null) { if (p != null) {
if (!p.isMoved()) { if (!p.isMoved()) {
movable.add(new Point(2, this.position.y)); possibleCastling.add(new Point(2, this.position.y));
} }
} }
} }
@ -48,7 +49,7 @@ public final class King extends PieceKnownIfMoved {
Piece p = pieces[loopX][this.position.y]; Piece p = pieces[loopX][this.position.y];
if (p != null) { if (p != null) {
if (!p.isMoved()) { if (!p.isMoved()) {
movable.add(new Point(6, this.position.y)); possibleCastling.add(new Point(6, this.position.y));
} }
} }
} }
@ -58,6 +59,7 @@ public final class King extends PieceKnownIfMoved {
nothingInBetween = false; nothingInBetween = false;
} }
} }
return possibleCastling;
} }
@ -101,7 +103,7 @@ public final class King extends PieceKnownIfMoved {
} }
} }
addCastlingIfCan(pieces, movable, position, position); movable.addAll(getCastlingIfPossible(pieces));
return movable; return movable;
} }