mirror of
https://github.com/lov3b/Schack.git
synced 2025-04-18 20:30:12 +02:00
48 lines
1.6 KiB
Java
48 lines
1.6 KiB
Java
package schack;
|
|
|
|
import java.awt.Point;
|
|
import java.io.IOException;
|
|
import java.util.LinkedHashSet;
|
|
|
|
public class Horse extends Piece {
|
|
|
|
public Horse(boolean isWhite, boolean isLeft, Point startingPosition) throws IOException {
|
|
super(isWhite, startingPosition);
|
|
setPieceIcon("Horse");
|
|
}
|
|
|
|
@Override
|
|
public LinkedHashSet<Point> validMoves(Piece[][] pieces, boolean isSelected) {
|
|
LinkedHashSet<Point> movable = new LinkedHashSet<>();
|
|
|
|
// Postitioner att checka
|
|
Point[] positions = {
|
|
// Snett höger uppåt
|
|
new Point(this.position.x + 1, this.position.y - 2),
|
|
// Snett höger neråt
|
|
new Point(this.position.x + 1, this.position.y + 2),
|
|
// Långt höger åt sidan uppåt
|
|
new Point(this.position.x + 2, this.position.y - 1),
|
|
// Långt höger åt sidan neråt
|
|
new Point(this.position.x + 2, this.position.y + 1),
|
|
// Snett vänster uppåt
|
|
new Point(this.position.x - 1, this.position.y - 2),
|
|
// Snett vänster neråt
|
|
new Point(this.position.x - 1, this.position.y + 2),
|
|
// Långt vänster åt sidan uppåt
|
|
new Point(this.position.x - 2, this.position.y - 1),
|
|
// Långt vänster åt sidan neråt
|
|
new Point(this.position.x - 2, this.position.y + 1)
|
|
};
|
|
|
|
for (Point pos : positions) {
|
|
// Ifall en är blockerad så ska vi inte sluta kolla
|
|
addMovesIfCan(pos, movable, pieces, isSelected);
|
|
}
|
|
|
|
return movable;
|
|
|
|
}
|
|
|
|
}
|