diff --git a/OOP_2B1_Project/src/windowInterface/JPanelChessBoard.java b/OOP_2B1_Project/src/windowInterface/JPanelChessBoard.java index 2f99f63..be8fe4e 100644 --- a/OOP_2B1_Project/src/windowInterface/JPanelChessBoard.java +++ b/OOP_2B1_Project/src/windowInterface/JPanelChessBoard.java @@ -40,7 +40,7 @@ public class JPanelChessBoard extends JPanel { pieceSelectorMode = false; try { - spriteSheet = ImageIO.read(new File("newPieces.png")); + spriteSheet = ImageIO.read(new File("pieces/newPieces.png")); } catch (IOException e) { e.printStackTrace(); } diff --git a/OOP_2B1_Project/src/windowInterface/MyInterface.java b/OOP_2B1_Project/src/windowInterface/MyInterface.java index c152742..b7b40b0 100644 --- a/OOP_2B1_Project/src/windowInterface/MyInterface.java +++ b/OOP_2B1_Project/src/windowInterface/MyInterface.java @@ -1,5 +1,5 @@ package windowInterface; -import backend.SoundEffect; + import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.GridLayout; @@ -35,6 +35,7 @@ import javax.swing.JCheckBox; import javax.swing.*; import java.awt.*; + public class MyInterface extends JFrame { private static final long serialVersionUID = -6840815447618468846L; @@ -47,8 +48,9 @@ public class MyInterface extends JFrame { private JLabel actionLabel; private JCheckBox chckbxBlackAI; private JCheckBox chckbxWhiteAI; - private SoundEffect soundEffect = new SoundEffect(); - + private JLabel whiteTimerLabel; + private JLabel blackTimerLabel; + public TimerManager timerManager; /** * Create the frame. */ @@ -142,6 +144,11 @@ public class MyInterface extends JFrame { panelDraw = new JPanelChessBoard(this); contentPane.add(panelDraw, BorderLayout.CENTER); + + whiteTimerLabel = new JLabel("White: X"); + blackTimerLabel = new JLabel("Black: X"); + panelTop.add(whiteTimerLabel); + panelTop.add(blackTimerLabel); } public void setStepBanner(String s) { @@ -169,9 +176,13 @@ public class MyInterface extends JFrame { this.instantiateSimu(); int introduction = introduction(); int depth = askDifficulty(); - int time=askTime(); + int time = askTime(); game.setAutoPlayerDepth(depth); game.setDefaultSetup(); + if (timerManager == null) + timerManager = new TimerManager(whiteTimerLabel, blackTimerLabel, () -> gameOverByTimeout(), time); + timerManager.reset(); + timerManager.start(true); // white starts } public void clickButtonAdder() { panelDraw.toggleAdderMode(); @@ -199,7 +210,6 @@ public class MyInterface extends JFrame { } else { game.toggleAI(isWhite); } - soundEffect.aiSound(); } public void clicLoadFileButton() { @@ -223,7 +233,12 @@ public class MyInterface extends JFrame { panelDraw.setGame(game); int depth = askDifficulty(); + int time = askTime(); game.setAutoPlayerDepth(depth); + if (timerManager == null) + timerManager = new TimerManager(whiteTimerLabel, blackTimerLabel, () -> gameOverByTimeout(), time); + timerManager.reset(); + timerManager.start(game.getTurnColor()); game.start(); // this.repaint(); // update(game.getTurnNumber(), game.getTurnColor()); @@ -323,11 +338,11 @@ public class MyInterface extends JFrame { ); switch (choice) { - case 0: return 1; // 1 min - case 1: return 2; // 2 min - case 2: return 3; // 5 min - case 3: return 4;// 10 min - default: return 4; // 10 min + case 0: return 60; // 1 min + case 1: return 120; // 2 min + case 2: return 300; // 5 min + case 3: return 600;// 10 min + default: return 600; // 10 min } } private int introduction() { @@ -363,4 +378,10 @@ public class MyInterface extends JFrame { return 1; } + + + public void gameOverByTimeout() { + // disable board input, show message + // JOptionPane.showMessageDialog(this, "Time's up! The game is over."); + } }