added sound effects (capture and moving piece)
This commit is contained in:
parent
ddbc1cba4b
commit
d6c376ab27
Binary file not shown.
Binary file not shown.
|
|
@ -7,6 +7,7 @@ import javax.swing.JOptionPane;
|
|||
|
||||
public class Board {
|
||||
private KingCheck kingCheck = new KingCheck();
|
||||
private SoundEffect soundEffect = new SoundEffect();
|
||||
private int width = 8;
|
||||
private int height = 8;
|
||||
private ArrayList<ArrayList<Piece>> board = new ArrayList<>();
|
||||
|
|
@ -162,6 +163,11 @@ public class Board {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (board.get(y).get(x) != null) {
|
||||
soundEffect.captureSound();
|
||||
} else {
|
||||
soundEffect.movingSound();
|
||||
}
|
||||
board.get(this.ym).set(this.xm,null);
|
||||
this.setPiece(x,y,pieceToMove.getType(),pieceToMove.isWhite());
|
||||
Piece movedPiece = this.getPiece(x, y);
|
||||
|
|
@ -344,7 +350,11 @@ public class Board {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (board.get(y).get(x) != null) {
|
||||
soundEffect.captureSound();
|
||||
} else {
|
||||
soundEffect.movingSound();
|
||||
}
|
||||
this.setPiece(x,y,pieceToMove.getType(),pieceToMove.isWhite());
|
||||
Piece movedPiece = this.getPiece(x, y);
|
||||
if (movedPiece != null) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
package backend;
|
||||
import javax.sound.sampled.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class SoundEffect {
|
||||
public void captureSound() {
|
||||
|
||||
try {
|
||||
File file = new File("capture.wav");
|
||||
AudioInputStream audioStream = AudioSystem.getAudioInputStream(file);
|
||||
Clip clip = AudioSystem.getClip();
|
||||
clip.open(audioStream);
|
||||
clip.start();
|
||||
} catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public void movingSound() {
|
||||
|
||||
try {
|
||||
File file = new File("move-self.wav");
|
||||
AudioInputStream audioStream = AudioSystem.getAudioInputStream(file);
|
||||
Clip clip = AudioSystem.getClip();
|
||||
clip.open(audioStream);
|
||||
clip.start();
|
||||
} catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue