mirror of
https://github.com/lov3b/Schack.git
synced 2025-01-18 21:00:11 +01:00
gör getCastleMove mer tydlig
This commit is contained in:
parent
9d1916ad17
commit
d5244cea94
@ -146,12 +146,12 @@ public class Board extends JPanel implements MouseListener {
|
||||
continue;
|
||||
}
|
||||
if (attacked.supremeRuler) {
|
||||
validMovesToDraw.clear();
|
||||
getParent().repaint();
|
||||
// Kolla ifall vi är i schackmatt
|
||||
if (weCanMove) {
|
||||
JOptionPane.showMessageDialog(this, "Du står i schack");
|
||||
} else {
|
||||
validMovesToDraw.clear();
|
||||
getParent().repaint();
|
||||
int choise = JOptionPane.showConfirmDialog(this, "Schackmatt\nVill du starta om?");
|
||||
if (choise == JOptionPane.YES_OPTION) {
|
||||
restartGame();
|
||||
|
@ -11,9 +11,10 @@ public final class King extends PieceKnownIfMoved {
|
||||
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()) {
|
||||
return;
|
||||
return possibleCastling;
|
||||
}
|
||||
|
||||
// Vänster
|
||||
@ -27,7 +28,7 @@ public final class King extends PieceKnownIfMoved {
|
||||
Piece p = pieces[loopX][this.position.y];
|
||||
if (p != null) {
|
||||
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];
|
||||
if (p != null) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
return possibleCastling;
|
||||
|
||||
}
|
||||
|
||||
@ -101,7 +103,7 @@ public final class King extends PieceKnownIfMoved {
|
||||
}
|
||||
|
||||
}
|
||||
addCastlingIfCan(pieces, movable, position, position);
|
||||
movable.addAll(getCastlingIfPossible(pieces));
|
||||
return movable;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user