mirror of
https://github.com/lov3b/Schack.git
synced 2025-01-18 12:50:10 +01:00
Rockad funkar
This commit is contained in:
parent
08d004b40b
commit
4cf3eeafbb
@ -1,4 +1,3 @@
|
||||
|
||||
package schack;
|
||||
|
||||
import java.awt.Point;
|
||||
@ -13,7 +12,7 @@ public final class King extends PieceKnownIfMoved {
|
||||
}
|
||||
|
||||
private void addCastlingIfCan(Piece[][] pieces, ArrayList<Point> movable, Point toMove, Point selected) {
|
||||
if (moved) {
|
||||
if (isMoved()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -27,23 +26,16 @@ public final class King extends PieceKnownIfMoved {
|
||||
// Check så att man bara kan göra rockad ifall tornet inte rört sig
|
||||
Piece p = pieces[loopX][this.position.y];
|
||||
if (p != null) {
|
||||
try {
|
||||
PieceKnownIfMoved PKIM = (PieceKnownIfMoved) p;
|
||||
if (!PKIM.moved) {
|
||||
movable.add(new Point(2, this.position.y));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (!p.isMoved()) {
|
||||
movable.add(new Point(2, this.position.y));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Kolla ifall det är tomt emellan kung och torn
|
||||
if (pieces[loopX][this.position.y] != null) {
|
||||
nothingInBetween = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Höger
|
||||
@ -52,7 +44,13 @@ public final class King extends PieceKnownIfMoved {
|
||||
|
||||
// Kolla ifall vi kollar tornet och inget är emellan
|
||||
if (loopX == 7 && nothingInBetween) {
|
||||
movable.add(new Point(6, this.position.y));
|
||||
// Check så att man bara kan göra rockad ifall tornet inte rört sig
|
||||
Piece p = pieces[loopX][this.position.y];
|
||||
if (p != null) {
|
||||
if (!p.isMoved()) {
|
||||
movable.add(new Point(6, this.position.y));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Kolla ifall det är tomt emellan kung och torn
|
||||
|
@ -223,4 +223,13 @@ public abstract class Piece {
|
||||
return isWhite;
|
||||
}
|
||||
|
||||
/**
|
||||
* Kompabilitet med PieceKnownIfMoved
|
||||
*
|
||||
* @return false
|
||||
*/
|
||||
public boolean isMoved() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ public abstract class PieceKnownIfMoved extends Piece {
|
||||
moved = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMoved() {
|
||||
return moved;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user