feat: add audio
This commit is contained in:
@@ -16,11 +16,11 @@ public class SwingMain {
|
||||
Game game = new Game();
|
||||
CommandExecutor commandExecutor = new CommandExecutor(game);
|
||||
|
||||
Window window = new Window(commandExecutor, false);
|
||||
Window window = new Window(commandExecutor, true);
|
||||
commandExecutor.addListener(window);
|
||||
|
||||
AI ai = new AlphaBetaAI(commandExecutor, Color.Black, 5);
|
||||
commandExecutor.addListener(ai);
|
||||
// AI ai = new AlphaBetaAI(commandExecutor, Color.Black, 5);
|
||||
// commandExecutor.addListener(ai);
|
||||
|
||||
// AI ai2 = new AlphaBetaAI(commandExecutor, Color.White, 5);
|
||||
// commandExecutor.addListener(ai2);
|
||||
|
||||
@@ -59,7 +59,7 @@ public class GameSimulation extends GameAdaptator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMove(Move move) {
|
||||
public void onMove(Move move, boolean captured) {
|
||||
sendCommand(new MoveCommand(move));
|
||||
}
|
||||
|
||||
|
||||
@@ -75,13 +75,13 @@ public class MoveCommand extends PlayerCommand {
|
||||
}
|
||||
|
||||
if (tryPromote(game, outputSystem)) {
|
||||
outputSystem.onMove(this.move);
|
||||
outputSystem.onMove(this.move, this.deadPiece != null);
|
||||
return CommandResult.ActionNeeded;
|
||||
}
|
||||
|
||||
board.setLastMove(this.move);
|
||||
|
||||
outputSystem.onMove(this.move);
|
||||
outputSystem.onMove(this.move, this.deadPiece != null);
|
||||
|
||||
return CommandResult.Moved;
|
||||
}
|
||||
|
||||
@@ -81,8 +81,8 @@ public class AsyncGameDispatcher extends GameDispatcher {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMove(Move move) {
|
||||
asyncForEachCall((l) -> l.onMove(move));
|
||||
public void onMove(Move move, boolean captured) {
|
||||
asyncForEachCall((l) -> l.onMove(move, captured));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -32,7 +32,7 @@ public class EmptyGameDispatcher extends GameDispatcher {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMove(Move move) {
|
||||
public void onMove(Move move, boolean captured) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -38,7 +38,7 @@ public abstract class GameAdaptator implements GameListener {
|
||||
public void onGameEnd() {}
|
||||
|
||||
@Override
|
||||
public void onMove(Move move) {}
|
||||
public void onMove(Move move, boolean captured) {}
|
||||
|
||||
@Override
|
||||
public void onMoveNotAllowed(Move move) {}
|
||||
|
||||
@@ -41,8 +41,9 @@ public interface GameListener {
|
||||
* Invoked when a valid move on the board occurs
|
||||
*
|
||||
* @param move the move to be processed
|
||||
* @param captured whether the move is a result of a capture
|
||||
*/
|
||||
void onMove(Move move);
|
||||
void onMove(Move move, boolean captured);
|
||||
|
||||
/**
|
||||
* Invoked when a sent move is not allowed
|
||||
|
||||
@@ -13,8 +13,8 @@ import chess.view.AssetManager;
|
||||
public class AudioFiles {
|
||||
|
||||
private static final String baseURL = "https://images.chesscomfiles.com/chess-themes/sounds/_WAV_/default/";
|
||||
private static final String[] files = { "game-start", "game-end", "capture", "castle", "premove", "move-self",
|
||||
"move-check", "move-opponent", "promote", "notify", "tenseconds", "illegal" };
|
||||
private static final String[] files = { "game-start", "game-end", "capture", "castle", "move-self",
|
||||
"move-check", "promote", "illegal" };
|
||||
private static final String filesExtension = ".wav";
|
||||
private static final String saveDir = "audio/";
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package chess.view.audio;
|
||||
|
||||
import chess.controller.commands.PromoteCommand.PromoteType;
|
||||
import chess.controller.event.GameAdaptator;
|
||||
import chess.model.Move;
|
||||
|
||||
public class GameAudio extends GameAdaptator {
|
||||
|
||||
@@ -28,5 +30,34 @@ public class GameAudio extends GameAdaptator {
|
||||
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");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -270,7 +270,7 @@ public class Console implements GameListener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMove(Move move) {
|
||||
public void onMove(Move move, boolean captured) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -306,7 +306,7 @@ public class Window extends JFrame implements GameListener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMove(Move move) {}
|
||||
public void onMove(Move move, boolean captured) {}
|
||||
|
||||
@Override
|
||||
public void onMoveNotAllowed(Move move) {
|
||||
|
||||
Reference in New Issue
Block a user