64 lines
1.2 KiB
Java
64 lines
1.2 KiB
Java
package chess.view.audio;
|
|
|
|
import chess.controller.commands.PromoteCommand.PromoteType;
|
|
import chess.controller.event.GameAdaptator;
|
|
import chess.model.Move;
|
|
|
|
public class GameAudio extends GameAdaptator {
|
|
|
|
private final boolean functional;
|
|
|
|
public GameAudio() {
|
|
this.functional = AudioFiles.initFiles();
|
|
if(!this.functional){
|
|
System.err.println("[GameAudio] Failed to initialize audio files. Aborting ...");
|
|
}
|
|
}
|
|
|
|
private void playSound(String soundName) {
|
|
if (!this.functional)
|
|
return;
|
|
AudioPlayer.playSound(AudioFiles.getAudio(soundName));
|
|
}
|
|
|
|
@Override
|
|
public void onGameStart() {
|
|
playSound("game-start");
|
|
}
|
|
|
|
@Override
|
|
public void onGameEnd() {
|
|
playSound("game-end");
|
|
}
|
|
|
|
@Override
|
|
public void onMoveNotAllowed(Move move) {
|
|
playSound("illegal");
|
|
}
|
|
|
|
@Override
|
|
public void onMove(Move move, boolean captured) {
|
|
if (captured) {
|
|
playSound("capture");
|
|
return;
|
|
}
|
|
playSound("move-self");
|
|
}
|
|
|
|
@Override
|
|
public void onKingInCheck() {
|
|
playSound("move-check");
|
|
}
|
|
|
|
@Override
|
|
public void onPawnPromoted(PromoteType promotion) {
|
|
playSound("promote");
|
|
}
|
|
|
|
@Override
|
|
public void onCastling(boolean bigCastling) {
|
|
playSound("castle");
|
|
}
|
|
|
|
}
|