mirror of
https://github.com/lov3b/Schack.git
synced 2024-11-10 07:00:11 +01:00
Turer
This commit is contained in:
parent
6710645543
commit
4f77dc0b33
@ -19,6 +19,7 @@ public class Board extends JPanel implements MouseListener {
|
||||
private LinkedHashSet<Point> validMovesToDraw = new LinkedHashSet<>();
|
||||
private Point selectedPiece = new Point();
|
||||
private Color moveableColor = new Color(255, 191, 0);
|
||||
private boolean turn = true;
|
||||
|
||||
public Board() throws IOException {
|
||||
|
||||
@ -108,6 +109,7 @@ public class Board extends JPanel implements MouseListener {
|
||||
try {
|
||||
Piece p = pieces[selectedPiece.x][selectedPiece.y];
|
||||
p.move(pieces, clicked, selectedPiece);
|
||||
turn = !turn;
|
||||
|
||||
} catch (Exception e) {
|
||||
validMovesToDraw.clear();
|
||||
@ -118,13 +120,16 @@ public class Board extends JPanel implements MouseListener {
|
||||
validMovesToDraw.clear();
|
||||
}
|
||||
|
||||
|
||||
// Om vi inte redan har valt en pjäs klickar vi på en pjäs
|
||||
if (!validMovesToDraw.contains(clicked)) {
|
||||
|
||||
try {
|
||||
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) {
|
||||
LinkedHashSet validMoves = p.validMoves(pieces);
|
||||
validMovesToDraw.addAll(validMoves);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
validMovesToDraw.clear();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user