This commit is contained in:
loveb 2022-03-24 09:09:59 +01:00
parent 45d4f0e80c
commit ba366b1e16
3 changed files with 28 additions and 17 deletions

View File

@ -5,9 +5,8 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashSet;
public final class King extends Piece {
public final class King extends PieceKnownIfMoved {
boolean eglibleForCastling = true;
public King(boolean isWhite, Point startingPosition) throws IOException {
super(isWhite, startingPosition);
@ -59,7 +58,7 @@ public final class King extends Piece {
@Override
public String toString() {
return "Piece{" + "eglibleForCastling=" + eglibleForCastling + "position=" + position + ", isWhite=" + isWhite + '}';
return "Piece{" + "hasMoved=" + hasMoved + "position=" + position + ", isWhite=" + isWhite + '}';
}
}

View File

@ -4,19 +4,13 @@ import java.awt.Point;
import java.io.IOException;
import java.util.LinkedHashSet;
public class Pawn extends Piece {
private boolean hasMoved = false;
public class Pawn extends PieceKnownIfMoved {
public Pawn(boolean isWhite, Point startingPosition) throws IOException {
super(isWhite, startingPosition);
setPieceIcon("Pawn");
}
Pawn(boolean isWhite) {
super(isWhite);
}
@Override
public LinkedHashSet<Point> validMoves(Piece[][] pieces) {
// TODO: Lösa bugg där bunder kanterna inte kan röra sig
@ -94,13 +88,6 @@ public class Pawn extends Piece {
}
@Override
public void move(Piece[][] pieces, Point toMove, Point selected) {
// Detta är för att veta ifall vi kan 2 steg eller inte
hasMoved = true;
super.move(pieces, toMove, selected);
}
@Override
public String toString() {
return "Pawn{" + "position=" + position + ", isWhite=" + isWhite + '}';

View File

@ -0,0 +1,25 @@
package schack;
import java.awt.Point;
import java.io.IOException;
import java.util.ArrayList;
public abstract class PieceKnownIfMoved extends Piece {
protected boolean hasMoved = false;
public PieceKnownIfMoved(boolean isWhite, Point startingPosition) throws IOException {
super(isWhite, startingPosition);
}
public boolean isSeen(ArrayList<Piece> pieces) {
return true;
}
@Override
public void move(Piece[][] pieces, Point toMove, Point selected) {
super.move(pieces, toMove, selected);
hasMoved = true;
}
}