diff --git a/src/backend/Board.java b/src/backend/Board.java index 0e83d23..dfee22b 100644 --- a/src/backend/Board.java +++ b/src/backend/Board.java @@ -117,22 +117,12 @@ public class Board { } return pieces; - - - } public boolean isSelected(int x, int y) { return hasSelectedPiece && selectedX == x && selectedY == y; } - - - - - - - public void userTouch(int x, int y) { if (x < 0 || x >= width || y < 0 || y >= height) return; @@ -171,7 +161,7 @@ public class Board { board[selectedX][selectedY] = null; selectedPiece.setX(x); selectedPiece.setY(y); - selectedPiece.setMoved(true); // ✅ Marque la pièce comme ayant bougé + selectedPiece.setMoved(true); // Déplacement de la tour si roque diff --git a/src/windowInterface/JPanelChessBoard.java b/src/windowInterface/JPanelChessBoard.java index 78a68de..175737a 100644 --- a/src/windowInterface/JPanelChessBoard.java +++ b/src/windowInterface/JPanelChessBoard.java @@ -77,66 +77,76 @@ public class JPanelChessBoard extends JPanel { myGame = simu; } + @Override protected void paintComponent(Graphics g) { - super.paintComponent(g); - this.setBackground(Color.black); - if(pieceSelectorMode) { - g.drawImage( - spriteSheet, - 0, - 0, - Math.round(5*cellWidth()), - Math.round(2*cellHeight()), - null - ); - return; - } - if (myGame != null) { - // Draw Interface from state of simulator - float cellWidth = cellWidth(); - float cellHeight = cellHeight(); - - g.setColor(Color.white); - for(int x=0; x lines = new LinkedList(); + if (fileName.length()>0) { + try { + BufferedReader fileContent = new BufferedReader(new FileReader(fileName)); + String line = fileContent.readLine(); + int colorID = 0; + while (line != null) { + lines.add(line); + line = fileContent.readLine(); + } + loadedSim.setBoard(Arrays.stream(lines.toArray()).map(Object::toString).toArray(String[]::new)); + fileContent.close(); + } catch (Exception e) { + e.printStackTrace(); + } + game = loadedSim; + chessBoard.setGame(game); + this.repaint(); + } + } - public void setBorderBanner(String s) { - borderLabel.setText(s); - } - - public JPanelChessBoard getPanelDessin() { - return panelDraw; - } - - public void instantiateSimu() { - if(game==null) { - game = new Game(this); - panelDraw.setGame(game); - game.start(); - } - } - - public void clicButtonStart() { - this.instantiateSimu(); - game.setDefaultSetup(); - } - - public void clickButtonAdder() { - panelDraw.toggleAdderMode(); - } - public void clickButtonSelector() { - panelDraw.togglePieceSelector(); - } - - private void clicUndoButton() { - if(game == null) { - System.out.println("error : can't undo while no game present"); - } else { - game.undoLastMove(); - } - - } - public void clicAIToggle(boolean isWhite) { - if(game == null) { - System.out.println("error : can't activate AI while no game present"); - if(isWhite) { - chckbxWhiteAI.setSelected(false); - }else { - chckbxBlackAI.setSelected(false); - } - } else { - game.toggleAI(isWhite); - } - } - - public void clicLoadFileButton() { - Game loadedSim = new Game(this); - String fileName=SelectFile(); - LinkedList lines = new LinkedList(); - if (fileName.length()>0) { - try { - BufferedReader fileContent = new BufferedReader(new FileReader(fileName)); - String line = fileContent.readLine(); - int colorID = 0; - while (line != null) { - lines.add(line); - line = fileContent.readLine(); - } - loadedSim.setBoard(Arrays.stream(lines.toArray()).map(Object::toString).toArray(String[]::new)); - fileContent.close(); - } catch (Exception e) { - e.printStackTrace(); - } - game = loadedSim; - panelDraw.setGame(game); - this.repaint(); - } - } - - public void clicSaveToFileButton() { - String fileName=SelectFile(); - if (fileName.length()>0) { - String[] content = game.getFileRepresentation(); - writeFile(fileName, content); - } - } - - public String SelectFile() { - String s; - JFileChooser chooser = new JFileChooser(); - chooser.setCurrentDirectory(new java.io.File(".")); - chooser.setDialogTitle("Choose a file"); - chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); - chooser.setAcceptAllFileFilterUsed(true); - if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { - s=chooser.getSelectedFile().toString(); - } else { - System.out.println("No Selection "); - s=""; - } - return s; - } - - public void writeFile(String fileName, String[] content) { - FileWriter csvWriter; - try { - csvWriter = new FileWriter(fileName); - for (String row : content) { - csvWriter.append(row); - csvWriter.append("\n"); - } - csvWriter.flush(); - csvWriter.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - public void update(int turnCount, boolean turnIsWhite) { - turnLabel.setText("Turn : "+turnCount+", "+ (turnIsWhite?"White":"Black")); - actionLabel.setText(panelDraw.isPieceAdderMode()?"Adding Piece": - (panelDraw.isPieceSelectorMode()?"Selecting Piece to Add": - "Playing")); - this.repaint(); - } - - public void eraseLabels() { - this.setStepBanner("Turn : X"); - } - -} + public void clicSaveToFileButton() { + String fileName=SelectFile(); + if (fileName.length()>0) { + String[] content = game.getFileRepresentation(); + writeFile(fileName, content); + } + } + + public String SelectFile() { + String s; + JFileChooser chooser = new JFileChooser(); + chooser.setCurrentDirectory(new java.io.File(".")); + chooser.setDialogTitle("Choose a file"); + chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); + chooser.setAcceptAllFileFilterUsed(true); + if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { + s=chooser.getSelectedFile().toString(); + } else { + System.out.println("No Selection "); + s=""; + } + return s; + } + + public void writeFile(String fileName, String[] content) { + FileWriter csvWriter; + try { + csvWriter = new FileWriter(fileName); + for (String row : content) { + csvWriter.append(row); + csvWriter.append("\n"); + } + csvWriter.flush(); + csvWriter.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public void update(int turnCount, boolean turnIsWhite) { + turnLabel.setText("Turn : "+turnCount+", "+ (turnIsWhite?"White":"Black")); + actionLabel.setText(chessBoard.isPieceAdderMode()?"Adding Piece": + (chessBoard.isPieceSelectorMode()?"Selecting Piece to Add": + "Playing")); + this.repaint(); + } + + public void eraseLabels() { + this.setStepBanner("Turn : X"); + } +} \ No newline at end of file diff --git a/src/windowInterface/WelcomePanel.java b/src/windowInterface/WelcomePanel.java new file mode 100644 index 0000000..c4830b8 --- /dev/null +++ b/src/windowInterface/WelcomePanel.java @@ -0,0 +1,46 @@ +package windowInterface; + +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.*; + +public class WelcomePanel extends JPanel { + private JButton startButton; + private MyInterface mainInterface; + + public WelcomePanel(MyInterface mainInterface) { + this.mainInterface = mainInterface; + setLayout(new BorderLayout()); + setBackground(new Color(0, 100, 0)); // Dark green background + + // Create title label + JLabel titleLabel = new JLabel("Chess Game", SwingConstants.CENTER); + titleLabel.setFont(new Font("Serif", Font.BOLD, 48)); + titleLabel.setForeground(Color.WHITE); + titleLabel.setBorder(BorderFactory.createEmptyBorder(50, 0, 30, 0)); + + // Create subtitle label + JLabel subtitleLabel = new JLabel("Let the game begin!", SwingConstants.CENTER); + subtitleLabel.setFont(new Font("Serif", Font.ITALIC, 24)); + subtitleLabel.setForeground(new Color(234, 235, 200)); // Light green + + // Create start button + startButton = new JButton("Start Game"); + startButton.setFont(new Font("SansSerif", Font.BOLD, 18)); + startButton.setBackground(new Color(119, 149, 86)); // Dark green + startButton.setForeground(Color.WHITE); + startButton.setBorder(BorderFactory.createEmptyBorder(10, 30, 10, 30)); + startButton.addActionListener(e -> mainInterface.showGameBoard()); + + // Center panel for button + JPanel buttonPanel = new JPanel(); + buttonPanel.setOpaque(false); + buttonPanel.add(startButton); + + // Add components + add(titleLabel, BorderLayout.NORTH); + add(subtitleLabel, BorderLayout.CENTER); + add(buttonPanel, BorderLayout.SOUTH); + } +} \ No newline at end of file