From e67106370874d1d61fd73617de55e7da5f481c1b Mon Sep 17 00:00:00 2001 From: "charles.duteil" Date: Sun, 18 May 2025 20:53:19 +0200 Subject: [PATCH] Changement en layout style chess.com --- .../src/windowInterface/JPanelChessBoard.java | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/OOP_2B1_Project/src/windowInterface/JPanelChessBoard.java b/OOP_2B1_Project/src/windowInterface/JPanelChessBoard.java index f33dad5..2817aba 100644 --- a/OOP_2B1_Project/src/windowInterface/JPanelChessBoard.java +++ b/OOP_2B1_Project/src/windowInterface/JPanelChessBoard.java @@ -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 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); } } }