bröt ut checkAttack

This commit is contained in:
lov3b 2022-03-22 18:40:39 +01:00
parent e2faebc65c
commit 4b92c6d388

View File

@ -32,21 +32,26 @@ public class Pawn extends Piece {
} }
} }
// Logik för att ta // Kolla ifall vi kan ta någon
for (int pawnX : new int[]{-1, 1}) { for (int pawnX : new int[]{-1, 1}) {
// Position vi kollar just nu, snett upp åt höger & vänster // Position vi kollar just nu, snett upp åt höger & vänster
Point pos = new Point(this.position.x + pawnX, this.position.y + (this.isWhite ? -1 : 1)); Point pos = new Point(this.position.x + pawnX, this.position.y + (this.isWhite ? -1 : 1));
Piece p = pieces[pos.x][pos.y]; checkAttack(pos, movable, pieces);
// Ifall det är en pjäs som står här och den inte är samma färg som oss, lägg till
if (p != null && p.isWhite != this.isWhite) {
movable.add(pos);
}
} }
return movable; return movable;
} }
// Känns som det här skulle kunnat vara i validMoves, men nu är det såhär
private void checkAttack(Point pos, LinkedHashSet movable, Piece[][] pieces) {
Piece p = pieces[pos.x][pos.y];
// Ifall det är en pjäs som står här och den inte är samma färg som oss, lägg till
if (p != null && p.isWhite != this.isWhite) {
movable.add(pos);
}
}
@Override @Override
protected boolean checkMove(Point pos, LinkedHashSet movable, Piece[][] pieces) { protected boolean checkMove(Point pos, LinkedHashSet movable, Piece[][] pieces) {
// Instead of checking index and null, try-catch // Instead of checking index and null, try-catch