From b3a381346435e6ee301a0d14739f783ecd981f64 Mon Sep 17 00:00:00 2001 From: Romain Murphy Date: Thu, 8 May 2025 15:43:53 +0200 Subject: [PATCH 1/9] re --- OOP_2B1_Project/src/backend/KingCheck.java | 1 + 1 file changed, 1 insertion(+) diff --git a/OOP_2B1_Project/src/backend/KingCheck.java b/OOP_2B1_Project/src/backend/KingCheck.java index bfc08ed..85a7cd2 100644 --- a/OOP_2B1_Project/src/backend/KingCheck.java +++ b/OOP_2B1_Project/src/backend/KingCheck.java @@ -60,6 +60,7 @@ public class KingCheck { soundEffect.aiSound(); soundShouldPlay=false; } + return true; // King can be captured } } } From 89dc810d43119ee7021843a31fbaddf9688acf3d Mon Sep 17 00:00:00 2001 From: Romain Murphy Date: Thu, 8 May 2025 16:58:24 +0200 Subject: [PATCH 2/9] changed waiting screen --- OOP_2B1_Project/src/Main.java | 2 +- .../src/windowInterface/JPanelChessBoard.java | 10 +++++++++- .../{ => src/windowInterface}/image_OOP.png | Bin 3 files changed, 10 insertions(+), 2 deletions(-) rename OOP_2B1_Project/{ => src/windowInterface}/image_OOP.png (100%) diff --git a/OOP_2B1_Project/src/Main.java b/OOP_2B1_Project/src/Main.java index 68d3915..e7b754b 100644 --- a/OOP_2B1_Project/src/Main.java +++ b/OOP_2B1_Project/src/Main.java @@ -16,7 +16,7 @@ public class Main { // launches graphical interface : MyInterface mjf = new MyInterface(); - mjf.introduction(); +// mjf.introduction(); mjf.setVisible(true); } diff --git a/OOP_2B1_Project/src/windowInterface/JPanelChessBoard.java b/OOP_2B1_Project/src/windowInterface/JPanelChessBoard.java index be8fe4e..5a0de44 100644 --- a/OOP_2B1_Project/src/windowInterface/JPanelChessBoard.java +++ b/OOP_2B1_Project/src/windowInterface/JPanelChessBoard.java @@ -10,6 +10,7 @@ import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; +import javax.swing.ImageIcon; import javax.swing.JPanel; import backend.Game; @@ -30,6 +31,8 @@ public class JPanelChessBoard extends JPanel { private boolean selectedPieceIsWhite; private PieceType selectedPieceType; private boolean pieceAdderMode; + private Image backgroundImage; + public JPanelChessBoard(MyInterface itf) { super(); @@ -38,6 +41,7 @@ public class JPanelChessBoard extends JPanel { selectedPieceIsWhite = true; selectedPieceType = PieceType.Pawn; pieceSelectorMode = false; + backgroundImage = new ImageIcon(getClass().getResource("image_OOP.png")).getImage(); try { spriteSheet = ImageIO.read(new File("pieces/newPieces.png")); @@ -81,7 +85,8 @@ public class JPanelChessBoard extends JPanel { @Override protected void paintComponent(Graphics g) { super.paintComponent(g); - this.setBackground(new Color(238,236,208)); + g.drawImage(backgroundImage, 0, 0, getWidth(), getHeight(), this); +// this.setBackground(new Color(238,236,208)); if(pieceSelectorMode) { g.drawImage( spriteSheet, @@ -95,6 +100,9 @@ public class JPanelChessBoard extends JPanel { } if (myGame != null) { // Draw Interface from state of simulator + g.setColor(new Color(238, 236, 208)); // Your default color + g.fillRect(0, 0, getWidth(), getHeight()); + repaint(); float cellWidth = cellWidth(); float cellHeight = cellHeight(); diff --git a/OOP_2B1_Project/image_OOP.png b/OOP_2B1_Project/src/windowInterface/image_OOP.png similarity index 100% rename from OOP_2B1_Project/image_OOP.png rename to OOP_2B1_Project/src/windowInterface/image_OOP.png From 7ec9b00a4474b0e70251412f2df66c2513f70525 Mon Sep 17 00:00:00 2001 From: Romain Murphy Date: Fri, 9 May 2025 14:59:19 +0200 Subject: [PATCH 3/9] timer reset --- OOP_2B1_Project/src/windowInterface/MyInterface.java | 4 ++-- OOP_2B1_Project/src/windowInterface/TimerManager.java | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/OOP_2B1_Project/src/windowInterface/MyInterface.java b/OOP_2B1_Project/src/windowInterface/MyInterface.java index f7185c0..0ffcd00 100644 --- a/OOP_2B1_Project/src/windowInterface/MyInterface.java +++ b/OOP_2B1_Project/src/windowInterface/MyInterface.java @@ -180,7 +180,7 @@ public class MyInterface extends JFrame { game.setDefaultSetup(); if (timerManager == null) timerManager = new TimerManager(whiteTimerLabel, blackTimerLabel, () -> gameOverByTimeout(), time); - timerManager.reset(); + timerManager.reset(time); timerManager.start(true); // white starts } public void clickButtonAdder() { @@ -236,7 +236,7 @@ public class MyInterface extends JFrame { game.setAutoPlayerDepth(depth); if (timerManager == null) timerManager = new TimerManager(whiteTimerLabel, blackTimerLabel, () -> gameOverByTimeout(), time); - timerManager.reset(); + timerManager.reset(time); timerManager.start(game.getTurnColor()); game.start(); // this.repaint(); diff --git a/OOP_2B1_Project/src/windowInterface/TimerManager.java b/OOP_2B1_Project/src/windowInterface/TimerManager.java index bd2cab6..de66404 100644 --- a/OOP_2B1_Project/src/windowInterface/TimerManager.java +++ b/OOP_2B1_Project/src/windowInterface/TimerManager.java @@ -60,7 +60,9 @@ public class TimerManager { timer.stop(); } -public void reset() { +public void reset(int time) { + whiteSeconds = time; + blackSeconds = time; updateLabel(whiteLabel, whiteSeconds); updateLabel(blackLabel, blackSeconds); } From 2132234667748248fcd1e3d54257e793513ec2cb Mon Sep 17 00:00:00 2001 From: Romain Murphy Date: Fri, 9 May 2025 15:05:54 +0200 Subject: [PATCH 4/9] timer start when you touch a piece for the first time --- OOP_2B1_Project/src/backend/Board.java | 7 ++++++- OOP_2B1_Project/src/backend/Game.java | 3 +++ OOP_2B1_Project/src/windowInterface/MyInterface.java | 6 ++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/OOP_2B1_Project/src/backend/Board.java b/OOP_2B1_Project/src/backend/Board.java index 4001626..e7aae1f 100644 --- a/OOP_2B1_Project/src/backend/Board.java +++ b/OOP_2B1_Project/src/backend/Board.java @@ -20,6 +20,7 @@ public class Board { private ArrayList> possibleMoves = new ArrayList<>(); private LinkedList boardHistory = new LinkedList<>(); public boolean timerSwitch = false; + public boolean timerStart = true; public Board(int colNum, int lineNum) { this.width = colNum; @@ -214,6 +215,7 @@ public class Board { public void userTouch(int x, int y) { if ((this.select == false && board.get(y).get(x) != null && this.board.get(y).get(x).isWhite() == turnColor) || (select == true && board.get(y).get(x) != null && board.get(y).get(x).isWhite() == board.get(ym).get(xm).isWhite())) { + timerStart = false; this.xm = x; this.ym = y; select = true; @@ -407,7 +409,10 @@ public class Board { public void setTimerSwitch(boolean timerSwitch) { this.timerSwitch = timerSwitch; } - + + public boolean getTimerStart() { + return timerStart; + } } ///// diff --git a/OOP_2B1_Project/src/backend/Game.java b/OOP_2B1_Project/src/backend/Game.java index 8ad525c..1885f05 100644 --- a/OOP_2B1_Project/src/backend/Game.java +++ b/OOP_2B1_Project/src/backend/Game.java @@ -65,6 +65,9 @@ public class Game extends Thread { System.out.println("Click out of bounds"); return; } + if (board.getTimerStart()) { + mjf.startTimer(board.isTurnColor()); + } if(!isAITurn()) { if (aiPlayer.getAllLegalMoves(board.getBoard(), board.isTurnWhite(),board.getLastMove()).size() != 0){ board.userTouch(x, y); diff --git a/OOP_2B1_Project/src/windowInterface/MyInterface.java b/OOP_2B1_Project/src/windowInterface/MyInterface.java index 0ffcd00..91b3632 100644 --- a/OOP_2B1_Project/src/windowInterface/MyInterface.java +++ b/OOP_2B1_Project/src/windowInterface/MyInterface.java @@ -181,7 +181,6 @@ public class MyInterface extends JFrame { if (timerManager == null) timerManager = new TimerManager(whiteTimerLabel, blackTimerLabel, () -> gameOverByTimeout(), time); timerManager.reset(time); - timerManager.start(true); // white starts } public void clickButtonAdder() { panelDraw.toggleAdderMode(); @@ -376,7 +375,10 @@ public class MyInterface extends JFrame { return 1; } - + + public void startTimer(boolean isWhite) { + timerManager.start(isWhite); + } public void gameOverByTimeout() { From 6b0bf026c8930692de11d6932550df758e924c3b Mon Sep 17 00:00:00 2001 From: Romain Murphy Date: Fri, 9 May 2025 15:08:15 +0200 Subject: [PATCH 5/9] small change --- OOP_2B1_Project/src/windowInterface/MyInterface.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OOP_2B1_Project/src/windowInterface/MyInterface.java b/OOP_2B1_Project/src/windowInterface/MyInterface.java index 91b3632..b7fd538 100644 --- a/OOP_2B1_Project/src/windowInterface/MyInterface.java +++ b/OOP_2B1_Project/src/windowInterface/MyInterface.java @@ -236,7 +236,7 @@ public class MyInterface extends JFrame { if (timerManager == null) timerManager = new TimerManager(whiteTimerLabel, blackTimerLabel, () -> gameOverByTimeout(), time); timerManager.reset(time); - timerManager.start(game.getTurnColor()); +// timerManager.start(game.getTurnColor()); game.start(); // this.repaint(); // update(game.getTurnNumber(), game.getTurnColor()); From a6aebf2432c7f841413da6f1863cfb7eda10b05e Mon Sep 17 00:00:00 2001 From: gabrielshiraishi Date: Mon, 12 May 2025 09:22:49 +0200 Subject: [PATCH 6/9] J'ai elargi le JFrame pcq on pouvait pas voir le timer des blacks --- OOP_2B1_Project/src/windowInterface/MyInterface.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OOP_2B1_Project/src/windowInterface/MyInterface.java b/OOP_2B1_Project/src/windowInterface/MyInterface.java index b7fd538..bb13336 100644 --- a/OOP_2B1_Project/src/windowInterface/MyInterface.java +++ b/OOP_2B1_Project/src/windowInterface/MyInterface.java @@ -56,7 +56,7 @@ public class MyInterface extends JFrame { */ public MyInterface() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - setBounds(10, 10, 650, 650); + setBounds(10, 10, 800, 800); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); contentPane.setLayout(new BorderLayout(0, 0)); From c0102b71161146ae902b54a61f1c83d6bc81ebba Mon Sep 17 00:00:00 2001 From: gabrielshiraishi Date: Mon, 12 May 2025 10:22:36 +0200 Subject: [PATCH 7/9] Option game over --- .../src/windowInterface/MyInterface.java | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/OOP_2B1_Project/src/windowInterface/MyInterface.java b/OOP_2B1_Project/src/windowInterface/MyInterface.java index bb13336..7b17413 100644 --- a/OOP_2B1_Project/src/windowInterface/MyInterface.java +++ b/OOP_2B1_Project/src/windowInterface/MyInterface.java @@ -51,10 +51,18 @@ public class MyInterface extends JFrame { private JLabel whiteTimerLabel; private JLabel blackTimerLabel; public TimerManager timerManager; + + + /** * Create the frame. */ public MyInterface() { + + + + + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(10, 10, 800, 800); contentPane = new JPanel(); @@ -295,11 +303,25 @@ public class MyInterface extends JFrame { } public void showGameOverMessage(String message) { - JOptionPane.showMessageDialog(this, message, "Game Over", JOptionPane.INFORMATION_MESSAGE); - game.toggleAI(false); + game.toggleAI(false); game.toggleAI(true); chckbxWhiteAI.setSelected(false); chckbxBlackAI.setSelected(false); + Object[] options = {"YES", "NO"}; + int choice = JOptionPane.showOptionDialog(this, "GAME OVER \nDo you want to exit? ", + "Game Over", + JOptionPane.DEFAULT_OPTION, + JOptionPane.QUESTION_MESSAGE, + null, + options, + options[1] // default: Medium + ); + switch (choice) { + case 0: System.exit(0);; // Easy + case 1: ; // Medium + + } + } private int askDifficulty() { @@ -326,8 +348,8 @@ public class MyInterface extends JFrame { Object[] options = {"1 min", "2 Min", "5 Min", "10 Min"}; int choice = JOptionPane.showOptionDialog( this, - "Select Difficulty Level:", - "Difficulty", + "Select the duration of the game:", + "Duration", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, From d64e2962c91aebad4a713669153d5cf5e9c69086 Mon Sep 17 00:00:00 2001 From: gabrielshiraishi Date: Mon, 12 May 2025 10:55:18 +0200 Subject: [PATCH 8/9] Number and Letter on the board --- .../src/windowInterface/JPanelChessBoard.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/OOP_2B1_Project/src/windowInterface/JPanelChessBoard.java b/OOP_2B1_Project/src/windowInterface/JPanelChessBoard.java index 5a0de44..260f5cb 100644 --- a/OOP_2B1_Project/src/windowInterface/JPanelChessBoard.java +++ b/OOP_2B1_Project/src/windowInterface/JPanelChessBoard.java @@ -101,7 +101,7 @@ public class JPanelChessBoard extends JPanel { if (myGame != null) { // Draw Interface from state of simulator g.setColor(new Color(238, 236, 208)); // Your default color - g.fillRect(0, 0, getWidth(), getHeight()); + g.fillRect(0, 0, getWidth()+1, getHeight()+1); repaint(); float cellWidth = cellWidth(); float cellHeight = cellHeight(); @@ -149,6 +149,22 @@ public class JPanelChessBoard extends JPanel { for (Piece piece : myGame.getPieces()) { drawPiece(g,piece); } + g.setColor(Color.BLACK); + + + for (int x = 0; x < myGame.getWidth(); x++) { + char letter = (char) ('a' + x); + int xLetter = Math.round(x * cellWidth() + cellWidth() / 2) - 4; + int yLetter = getHeight() - 5; + g.drawString(String.valueOf(letter), xLetter, yLetter); + } + + for (int y = 0; y < myGame.getHeight(); y++) { + int number = myGame.getHeight() - y; + int xNumber = 5; + int yNumber = Math.round(y * cellHeight() + cellHeight() / 2) + 5; + g.drawString(String.valueOf(number), xNumber, yNumber); + } } } From 1df06a10686f94bf114fe5e86cefc9d8014c1d1e Mon Sep 17 00:00:00 2001 From: gabrielshiraishi Date: Mon, 12 May 2025 11:20:38 +0200 Subject: [PATCH 9/9] Add of restart option for the start a new game --- OOP_2B1_Project/src/windowInterface/MyInterface.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/OOP_2B1_Project/src/windowInterface/MyInterface.java b/OOP_2B1_Project/src/windowInterface/MyInterface.java index 7b17413..6d32ca3 100644 --- a/OOP_2B1_Project/src/windowInterface/MyInterface.java +++ b/OOP_2B1_Project/src/windowInterface/MyInterface.java @@ -307,18 +307,21 @@ public class MyInterface extends JFrame { game.toggleAI(true); chckbxWhiteAI.setSelected(false); chckbxBlackAI.setSelected(false); - Object[] options = {"YES", "NO"}; + Object[] options = {"YES", "NO", "Start a new game"}; int choice = JOptionPane.showOptionDialog(this, "GAME OVER \nDo you want to exit? ", "Game Over", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, - options[1] // default: Medium + options[1] // default: NO ); switch (choice) { - case 0: System.exit(0);; // Easy - case 1: ; // Medium + case 0: System.exit(0); // exit + case 1: ; + case 2: clicButtonStart(); + break; + default: ; }