diff --git a/OOP_1A2_Project/bin/.gitignore b/OOP_1A2_Project/bin/.gitignore new file mode 100644 index 0000000..5c7ebe3 --- /dev/null +++ b/OOP_1A2_Project/bin/.gitignore @@ -0,0 +1,2 @@ +/backend/ +/windowInterface/ diff --git a/OOP_1A2_Project/movesound.wav b/OOP_1A2_Project/movesound.wav new file mode 100644 index 0000000..0d3477e Binary files /dev/null and b/OOP_1A2_Project/movesound.wav differ diff --git a/OOP_1A2_Project/src/backend/Sound.java b/OOP_1A2_Project/src/backend/Sound.java new file mode 100644 index 0000000..c854b4c --- /dev/null +++ b/OOP_1A2_Project/src/backend/Sound.java @@ -0,0 +1,59 @@ +package backend; + + +import javax.sound.sampled.AudioInputStream; +import javax.sound.sampled.AudioSystem; +import javax.sound.sampled.Clip; +import javax.sound.sampled.LineUnavailableException; +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 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); + AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(soundFile); + moveSound = AudioSystem.getClip(); + moveSound.open(audioInputStream); + } catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) { + System.err.println("Error loading sound: " + SOUND_FILE_PATH + " - " + e.getMessage()); + } + } + + public void playMoveSound() { + if (moveSound != null) { + // Stop the clip if it's already playing + if (moveSound.isRunning()) { + moveSound.stop(); + } + // Reset clip to beginning + moveSound.setFramePosition(0); + // Play the sound + moveSound.start(); + } + } + + + public void cleanup() { + if (moveSound != null) { + moveSound.close(); + } + } +} \ No newline at end of file diff --git a/OOP_1A2_Project/src/windowInterface/move-self.wav b/OOP_1A2_Project/src/windowInterface/move-self.wav new file mode 100644 index 0000000..0d3477e Binary files /dev/null and b/OOP_1A2_Project/src/windowInterface/move-self.wav differ diff --git a/OOP_1A2_Project/src/windowInterface/movesound.wav b/OOP_1A2_Project/src/windowInterface/movesound.wav new file mode 100644 index 0000000..0d3477e Binary files /dev/null and b/OOP_1A2_Project/src/windowInterface/movesound.wav differ