package chess.view.audio; import chess.controller.commands.PromoteCommand.PromoteType; import chess.controller.event.GameAdapter; import chess.model.Coordinate; import chess.model.Move; /** * Class to handle audio events in the game. */ public class GameAudio extends GameAdapter { 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, Coordinate coordinate) { playSound("promote"); } @Override public void onCastling(boolean bigCastling, Move kingMove, Move rookMove) { playSound("castle"); } }