Kungen går nu finare med funktion

This commit is contained in:
k1ntas 2022-03-29 14:58:21 +02:00
parent 4f4a4e2293
commit b17a3436a9

View File

@ -7,7 +7,6 @@ import java.util.LinkedHashSet;
public final class King extends PieceKnownIfMoved { public final class King extends PieceKnownIfMoved {
public King(boolean isWhite, Point startingPosition) throws IOException { public King(boolean isWhite, Point startingPosition) throws IOException {
super(isWhite, startingPosition); super(isWhite, startingPosition);
setPieceIcon("King"); setPieceIcon("King");
@ -31,29 +30,15 @@ public final class King extends PieceKnownIfMoved {
if (loopY == 0 && loopX == 0) { if (loopY == 0 && loopX == 0) {
continue; continue;
} }
Point pos = new Point(this.position.x + loopX, this.position.y + loopY); boolean shouldBreak = addMovesIfCan(new Point(this.position.x + loopX, this.position.y + loopY), movable, pieces);
if (shouldBreak) {
// Instead of checking index and null, try-catch break;
try {
Piece p = pieces[pos.x][pos.y];
System.out.println(p);
// If this piece is the same team as ours, skip
if (p.isWhite == this.isWhite) {
continue;
}
movable.add(pos);
} catch (NullPointerException npe) {
// This is an empty spot
movable.add(pos);
} catch (Exception e) {
// This means that the player is at the edge
} }
} }
} }
return movable; return movable;
} }
@Override @Override