This commit is contained in:
2025-04-10 10:56:59 +02:00
parent e8e79a1e9e
commit 4b84a30e07

View File

@@ -1,6 +1,7 @@
package chess.view.simplerender;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
@@ -137,7 +138,19 @@ public class Window extends JFrame implements OutputSystem {
}
}
private void clearPreviews() {
for (int y = 0; y < 8; y++) {
for (int x = 0; x < 8; x++) {
JLabel cell = this.cells[x][y];
cell.paintComponents(getGraphics());
}
}
}
private boolean previewMoves(int x, int y) {
clearPreviews();
GetAllowedMovesCommand movesCommand = new GetAllowedMovesCommand(new Coordinate(x, y));
if (sendCommand(movesCommand) == CommandResult.NotAllowed)
return false;
@@ -148,7 +161,9 @@ public class Window extends JFrame implements OutputSystem {
for (Coordinate destCoord : allowedMoves) {
JLabel cell = this.cells[destCoord.getX()][destCoord.getY()];
cell.setBackground(Color.CYAN);
Graphics g = cell.getGraphics();
g.setColor(new Color(128, 128, 128, 128));
g.fillOval(25, 25, 50, 50);
}
return true;
}
@@ -171,6 +186,7 @@ public class Window extends JFrame implements OutputSystem {
private void onCellClicked(int x, int y) {
clearMoves();
clearPreviews();
if (this.lastClick == null) {
if (isCellEmpty(x, y))
return;
@@ -181,6 +197,7 @@ public class Window extends JFrame implements OutputSystem {
}
if (!this.lastClick.equals(new Coordinate(x, y))) {
Move move = new Move(lastClick, new Coordinate(x, y));
if (sendCommand(new MoveCommand(move)) == CommandResult.NotAllowed) {
drawInvalid(move);
}