mirror of
https://github.com/lov3b/Schack.git
synced 2025-01-18 12:50:10 +01:00
Fint arv
This commit is contained in:
parent
45d4f0e80c
commit
ba366b1e16
@ -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 + '}';
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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 på 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 gå 2 steg eller inte
|
||||
hasMoved = true;
|
||||
super.move(pieces, toMove, selected);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Pawn{" + "position=" + position + ", isWhite=" + isWhite + '}';
|
||||
|
25
src/schack/PieceKnownIfMoved.java
Normal file
25
src/schack/PieceKnownIfMoved.java
Normal 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;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user