Compare commits
2 Commits
bc16333d88
...
ee4b64f6e1
| Author | SHA1 | Date |
|---|---|---|
|
|
ee4b64f6e1 | |
|
|
42074cfe75 |
Binary file not shown.
|
|
@ -570,6 +570,7 @@ public class Board {
|
|||
public boolean isKingInCheck(boolean isWhite) {
|
||||
// First, find the king's position
|
||||
Piece king = findKing(isWhite);
|
||||
soudEffect soundPlayer = new soudEffect();
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
package backend;
|
||||
|
||||
import javax.sound.sampled.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class soudEffect {
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue