diff --git a/OOP_1A2_Project/bin/.gitignore b/OOP_1A2_Project/bin/.gitignore index ac72981..6d0c385 100644 --- a/OOP_1A2_Project/bin/.gitignore +++ b/OOP_1A2_Project/bin/.gitignore @@ -1,2 +1 @@ -/windowInterface/ /backend/ diff --git a/OOP_1A2_Project/bin/backend/Board.class b/OOP_1A2_Project/bin/backend/Board.class index b542ca7..afa6e69 100644 Binary files a/OOP_1A2_Project/bin/backend/Board.class and b/OOP_1A2_Project/bin/backend/Board.class differ diff --git a/OOP_1A2_Project/bin/windowInterface/move-self.wav b/OOP_1A2_Project/bin/windowInterface/move-self.wav new file mode 100644 index 0000000..0d3477e Binary files /dev/null and b/OOP_1A2_Project/bin/windowInterface/move-self.wav differ diff --git a/OOP_1A2_Project/bin/windowInterface/movesound.wav b/OOP_1A2_Project/bin/windowInterface/movesound.wav new file mode 100644 index 0000000..0d3477e Binary files /dev/null and b/OOP_1A2_Project/bin/windowInterface/movesound.wav differ diff --git a/OOP_1A2_Project/src/backend/Board.java b/OOP_1A2_Project/src/backend/Board.java index 0c55eae..000669f 100644 --- a/OOP_1A2_Project/src/backend/Board.java +++ b/OOP_1A2_Project/src/backend/Board.java @@ -17,6 +17,9 @@ public class Board { private Integer selectedX = null; private Integer selectedY = null; + // Add Sound instance + private Sound sound; + public Board(int colNum, int lineNum) { this.width = colNum; this.height = lineNum; @@ -25,6 +28,7 @@ public class Board { this.pieces = new ArrayList<>(); this.highlightedPositions = new ArrayList<>(); this.boardHistory = new ArrayList<>(); + this.sound = new Sound(); // Initialize Sound instance } public int getWidth() { @@ -175,7 +179,7 @@ public class Board { if (move.isValid()) { move.execute(); - Sound.getInstance().playMoveSound(); + sound.playMoveSound(); // Use instance method if (move.putsOpponentInCheckmate()) { System.out.println("Checkmate! " + (isWhiteTurn ? "Black" : "White") + " wins!"); @@ -234,6 +238,7 @@ public class Board { this.height = 8; this.pieces = new ArrayList<>(); this.boardHistory = new ArrayList<>(); + this.sound = new Sound(); // Initialize Sound instance for (int y = 0; y < height; y++) { if (y >= array.length) { @@ -314,6 +319,9 @@ public class Board { // Initialize board history for copy constructor this.boardHistory = new ArrayList<>(); + + // Initialize Sound instance (don't copy the sound instance) + this.sound = new Sound(); } private void clearHighlights() { @@ -346,8 +354,8 @@ public class Board { move.execute(); - // Play the move sound - Sound.getInstance().playMoveSound(); + // Play the move sound using instance method + sound.playMoveSound(); } } @@ -386,4 +394,11 @@ public class Board { public boolean canUndo() { return !boardHistory.isEmpty(); } + + // Add cleanup method to properly dispose of sound resources + public void cleanup() { + if (sound != null) { + sound.cleanup(); + } + } } \ No newline at end of file diff --git a/OOP_1A2_Project/src/backend/Sound.java b/OOP_1A2_Project/src/backend/Sound.java index c854b4c..641017d 100644 --- a/OOP_1A2_Project/src/backend/Sound.java +++ b/OOP_1A2_Project/src/backend/Sound.java @@ -1,6 +1,5 @@ package backend; - import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.Clip; @@ -9,23 +8,14 @@ import javax.sound.sampled.UnsupportedAudioFileException; import java.io.File; import java.io.IOException; - public class Sound { - private static Sound instance; private Clip moveSound; - private static final String SOUND_FILE_PATH = "movesound.wav"; + private final String SOUND_FILE_PATH = "movesound.wav"; - private Sound() { + public Sound() { loadSound(); } - public static Sound getInstance() { - if (instance == null) { - instance = new Sound(); - } - return instance; - } - private void loadSound() { try { File soundFile = new File(SOUND_FILE_PATH); @@ -49,7 +39,6 @@ public class Sound { moveSound.start(); } } - public void cleanup() { if (moveSound != null) {