mirror of
https://github.com/lov3b/Schack.git
synced 2024-11-10 07:00:11 +01:00
shcakc no werk men man man får inte gå in i schackl
This commit is contained in:
parent
c3f85f0128
commit
29df86030c
@ -10,6 +10,7 @@ import java.awt.event.MouseListener;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashSet;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class Board extends JPanel implements MouseListener {
|
||||
@ -128,7 +129,7 @@ public class Board extends JPanel implements MouseListener {
|
||||
Piece p = pieces[mouseCoordinateX][mouseCoordinateY];
|
||||
|
||||
// Kolla endast ifall vi kan röra på pjäsen om det är samma färg som den tur vi är på
|
||||
if (p.isWhite() == turn||developerMode) {
|
||||
if (p.isWhite() == turn || developerMode) {
|
||||
|
||||
LinkedHashSet<Point> blackAttacks = new LinkedHashSet<>();
|
||||
LinkedHashSet<Point> whiteAttacks = new LinkedHashSet<>();
|
||||
@ -150,8 +151,24 @@ public class Board extends JPanel implements MouseListener {
|
||||
}
|
||||
|
||||
LinkedHashSet validMoves = p.validMoves(pieces);
|
||||
|
||||
// Funkar
|
||||
if (p.supremeRuler) {
|
||||
validMoves.removeAll(turn ? blackAttacks : whiteAttacks);
|
||||
}
|
||||
// Funkar inte
|
||||
for (Point attack : turn ? whiteAttacks : blackAttacks) {
|
||||
Piece attacked = pieces[attack.x][attack.x];
|
||||
if (attacked == null) {
|
||||
continue;
|
||||
}
|
||||
if (attacked.supremeRuler) {
|
||||
JOptionPane.showMessageDialog(this, "Du står i schack");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
validMovesToDraw.addAll(validMoves);
|
||||
validMovesToDraw.addAll(blackAttacks);
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
@ -10,6 +10,7 @@ public final class King extends PieceKnownIfMoved {
|
||||
public King(boolean isWhite, Point startingPosition) throws IOException {
|
||||
super(isWhite, startingPosition);
|
||||
setPieceIcon("King");
|
||||
supremeRuler= true;
|
||||
}
|
||||
|
||||
public boolean isSeen(ArrayList<Piece> pieces) {
|
||||
|
@ -12,6 +12,8 @@ public abstract class Piece {
|
||||
|
||||
public Point position;
|
||||
public boolean white;
|
||||
/** SPECIAL RULÖES APPLY TO THE KING, (ITS GOOD TO BE THE KING:)*/
|
||||
public boolean supremeRuler= false;
|
||||
protected BufferedImage icon;
|
||||
|
||||
public Piece(boolean white, Point startingPosition) throws IOException {
|
||||
|
Loading…
Reference in New Issue
Block a user