mirror of
https://github.com/lov3b/Schack.git
synced 2025-01-18 21:00:11 +01:00
Kungen går nu finare med funktion
This commit is contained in:
parent
4f4a4e2293
commit
b17a3436a9
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user