mirror of
https://github.com/lov3b/Schack.git
synced 2025-01-18 21:00:11 +01:00
We did the clear thing
This commit is contained in:
parent
9097a966f0
commit
f070ae87a4
@ -82,6 +82,7 @@ public class Board extends JPanel implements MouseListener {
|
||||
g2.fillOval(point.x * SIZE_OF_TILE, point.y * SIZE_OF_TILE, SIZE_OF_TILE, SIZE_OF_TILE);
|
||||
}
|
||||
});
|
||||
|
||||
// Draw piece
|
||||
Arrays.stream(pieces).forEach(pieceArr -> Arrays.stream(pieceArr).forEach(piece -> {
|
||||
if (piece != null) {
|
||||
@ -171,32 +172,46 @@ public class Board extends JPanel implements MouseListener {
|
||||
|
||||
// Ifall vi har tryckt på en pjäs och sedan ska gå dit
|
||||
if (validMovesToDraw.contains(clicked)) {
|
||||
|
||||
System.out.println("1");
|
||||
try {
|
||||
Piece p = pieces[selectedPiece.x][selectedPiece.y];
|
||||
System.out.println("2");
|
||||
p.move(pieces, clicked, selectedPiece);
|
||||
validMovesToDraw.clear();
|
||||
System.out.println("came here");
|
||||
System.out.println("3");
|
||||
|
||||
System.out.println("4");
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
validMovesToDraw.clear();
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
System.out.println("5");
|
||||
selectedPiece = new Point(clicked);
|
||||
System.out.println("6");
|
||||
validMovesToDraw.clear();
|
||||
System.out.println("7");
|
||||
|
||||
}
|
||||
|
||||
System.out.println("X: " + mouseCoordinateX + ", Y: " + mouseCoordinateY);
|
||||
try {
|
||||
Piece p = pieces[mouseCoordinateX][mouseCoordinateY];
|
||||
LinkedHashSet validMoves = p.validMoves(pieces);
|
||||
System.out.println("valid moves " + validMoves);
|
||||
validMovesToDraw.addAll(validMoves);
|
||||
System.out.println("valid moves to draw " + validMovesToDraw);
|
||||
if (!validMovesToDraw.contains(clicked)) {
|
||||
System.out.println("8");
|
||||
try {
|
||||
Piece p = pieces[mouseCoordinateX][mouseCoordinateY];
|
||||
System.out.println("9");
|
||||
LinkedHashSet validMoves = p.validMoves(pieces);
|
||||
System.out.println("10");
|
||||
validMovesToDraw.addAll(validMoves);
|
||||
System.out.println("11");
|
||||
|
||||
} catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
System.out.println("12");
|
||||
validMovesToDraw.clear();
|
||||
System.out.println("13");
|
||||
}
|
||||
} else{
|
||||
validMovesToDraw.clear();
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ public class Queen extends Piece {
|
||||
public Queen(boolean isWhite, Point point) throws IOException {
|
||||
super(isWhite, point);
|
||||
setPieceIcon("Queen");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public LinkedHashSet<Point> validMoves(Piece[][] pieces) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user