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