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 King(boolean isWhite, Point startingPosition) throws IOException {
super(isWhite, startingPosition);
setPieceIcon("King");
@ -31,29 +30,15 @@ public final class King extends PieceKnownIfMoved {
if (loopY == 0 && loopX == 0) {
continue;
}
Point pos = new Point(this.position.x + loopX, this.position.y + loopY);
// Instead of checking index and null, try-catch
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;
boolean shouldBreak = addMovesIfCan(new Point(this.position.x + loopX, this.position.y + loopY), movable, pieces);
if (shouldBreak) {
break;
}
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;
}
@Override