diff --git a/exterminate.wav b/exterminate.wav new file mode 100644 index 0000000..365dfb5 Binary files /dev/null and b/exterminate.wav differ diff --git a/src/backend/Board.java b/src/backend/Board.java index e8a2eb0..2cac4db 100644 --- a/src/backend/Board.java +++ b/src/backend/Board.java @@ -570,6 +570,7 @@ public class Board { public boolean isKingInCheck(boolean isWhite) { // First, find the king's position Piece king = findKing(isWhite); + SoundPlayer soundPlayer = new SoundPlayer(); if (king == null) { // If king not found (shouldn't happen in a valid chess game) @@ -595,6 +596,7 @@ public class Board { // Check if any move can capture the king for (Move move : moves) { if (move.getToX() == kingX && move.getToY() == kingY) { + soundPlayer.playCheckSound(); return true; // King is in check } } diff --git a/src/backend/SoundPlayer.java b/src/backend/SoundPlayer.java new file mode 100644 index 0000000..5ac2c8e --- /dev/null +++ b/src/backend/SoundPlayer.java @@ -0,0 +1,20 @@ +package backend; + +import javax.sound.sampled.*; +import java.io.File; +import java.io.IOException; + +public class SoundPlayer { + public void playCheckSound() { + try { + // Replace "check.wav" with the path to your check sound file + File soundFile = new File("exterminate.wav"); + AudioInputStream audioStream = AudioSystem.getAudioInputStream(soundFile); + Clip clip = AudioSystem.getClip(); + clip.open(audioStream); + clip.start(); + } catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) { + e.printStackTrace(); + } + } +} \ No newline at end of file