Changement en layout style chess.com
This commit is contained in:
parent
d0847177f4
commit
e671063708
|
|
@ -39,7 +39,7 @@ public class JPanelChessBoard extends JPanel {
|
|||
selectedPieceType = PieceType.Pawn;
|
||||
pieceSelectorMode = false;
|
||||
try {
|
||||
spriteSheet = ImageIO.read(new File("pieces.png"));
|
||||
spriteSheet = ImageIO.read(new File("Pieces.png"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
@ -84,6 +84,8 @@ public class JPanelChessBoard extends JPanel {
|
|||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
this.setBackground(Color.black);
|
||||
final Color LIGHT_SQUARE = new Color(238, 238, 210);
|
||||
final Color DARK_SQUARE = new Color(118, 150, 86);
|
||||
if(pieceSelectorMode) {
|
||||
g.drawImage(
|
||||
spriteSheet,
|
||||
|
|
@ -102,35 +104,34 @@ public class JPanelChessBoard extends JPanel {
|
|||
float cellHeight = cellHeight();
|
||||
|
||||
g.setColor(Color.white);
|
||||
for(int x=0; x<myGame.getWidth(); x++) {
|
||||
for (int y=0; y<myGame.getHeight(); y++) {
|
||||
boolean isSelect = myGame.isSelected(x,y);
|
||||
boolean isHighlight = myGame.isHighlighted(x,y);
|
||||
for (int x = 0; x < myGame.getWidth(); x++) {
|
||||
for (int y = 0; y < myGame.getHeight(); y++) {
|
||||
// Check if this square is selected or highlighted
|
||||
boolean isSelect = myGame.isSelected(x, y);
|
||||
boolean isHighlight = myGame.isHighlighted(x, y);
|
||||
|
||||
if(isSelect) {
|
||||
g.setColor(Color.blue);
|
||||
}
|
||||
if(isHighlight) {
|
||||
g.setColor(Color.yellow);
|
||||
// Determine base color of the square (light vs dark)
|
||||
// (x + y) % 2 == 0 => light square; 1 => dark square
|
||||
Color squareColor = ((x + y) % 2 == 0) ? LIGHT_SQUARE : DARK_SQUARE;
|
||||
|
||||
// If the square is selected or highlighted, override base color
|
||||
if (isSelect) {
|
||||
squareColor = Color.blue;
|
||||
} else if (isHighlight) {
|
||||
squareColor = Color.yellow;
|
||||
}
|
||||
|
||||
// Fill either dark squares or new color if selected/highlighted
|
||||
if((x + y) % 2 == 1 || isSelect || isHighlight) {
|
||||
g.fillRect(
|
||||
Math.round(x*cellWidth),
|
||||
Math.round(y*cellHeight),
|
||||
Math.round(cellWidth),
|
||||
Math.round(cellHeight)
|
||||
);
|
||||
}
|
||||
// Draw the square
|
||||
g.setColor(squareColor);
|
||||
g.fillRect(
|
||||
Math.round(x * cellWidth),
|
||||
Math.round(y * cellHeight),
|
||||
Math.round(cellWidth),
|
||||
Math.round(cellHeight)
|
||||
);
|
||||
|
||||
// Restore to white if we changed the color
|
||||
if(isHighlight || isSelect) {
|
||||
g.setColor(Color.white);
|
||||
}
|
||||
|
||||
// Check if King is in check at (x, y)
|
||||
if(myGame.isKingCheckSquare(x, y)) {
|
||||
// If the king is in check here, overlay a red tint
|
||||
if (myGame.isKingCheckSquare(x, y)) {
|
||||
g.setColor(new Color(255, 0, 0, 120)); // Red overlay
|
||||
g.fillRect(
|
||||
Math.round(x * cellWidth),
|
||||
|
|
@ -138,7 +139,6 @@ public class JPanelChessBoard extends JPanel {
|
|||
Math.round(cellWidth),
|
||||
Math.round(cellHeight)
|
||||
);
|
||||
g.setColor(Color.white);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue