refactor OutputSystem
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package chess.controller.commands;
|
||||
|
||||
import chess.controller.OutputSystem;
|
||||
import chess.controller.PlayerCommand;
|
||||
import chess.controller.event.GameListener;
|
||||
import chess.model.ChessBoard;
|
||||
import chess.model.Color;
|
||||
import chess.model.Coordinate;
|
||||
@@ -19,7 +19,7 @@ public class CastlingCommand extends PlayerCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(Game game, OutputSystem outputSystem) {
|
||||
public CommandResult execute(Game game, GameListener outputSystem) {
|
||||
final ChessBoard board = game.getBoard();
|
||||
|
||||
// we must promote the pending pawn before
|
||||
@@ -53,7 +53,7 @@ public class CastlingCommand extends PlayerCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CommandResult undoImpl(Game game, OutputSystem outputSystem) {
|
||||
protected CommandResult undoImpl(Game game, GameListener outputSystem) {
|
||||
game.getBoard().undoMove(this.kingMove, null);
|
||||
game.getBoard().undoMove(this.rookMove, null);
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import chess.controller.Command;
|
||||
import chess.controller.OutputSystem;
|
||||
import chess.controller.event.GameListener;
|
||||
import chess.model.ChessBoard;
|
||||
import chess.model.Coordinate;
|
||||
import chess.model.Game;
|
||||
@@ -21,7 +21,7 @@ public class GetAllowedMovesPieceCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(Game game, OutputSystem outputSystem) {
|
||||
public CommandResult execute(Game game, GameListener outputSystem) {
|
||||
final ChessBoard board = game.getBoard();
|
||||
Piece piece = board.pieceAt(start);
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package chess.controller.commands;
|
||||
|
||||
import chess.controller.Command;
|
||||
import chess.controller.OutputSystem;
|
||||
import chess.controller.event.GameListener;
|
||||
import chess.model.Coordinate;
|
||||
import chess.model.Game;
|
||||
import chess.model.Piece;
|
||||
@@ -17,7 +17,7 @@ public class GetPieceAtCommand extends Command{
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(Game game, OutputSystem outputSystem) {
|
||||
public CommandResult execute(Game game, GameListener outputSystem) {
|
||||
if (!pieceCoords.isValid())
|
||||
return CommandResult.NotAllowed;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package chess.controller.commands;
|
||||
import java.util.List;
|
||||
|
||||
import chess.controller.Command;
|
||||
import chess.controller.OutputSystem;
|
||||
import chess.controller.event.GameListener;
|
||||
import chess.model.Game;
|
||||
import chess.model.Move;
|
||||
|
||||
@@ -12,7 +12,7 @@ public class GetPlayerMovesCommand extends Command {
|
||||
private List<Move> moves;
|
||||
|
||||
@Override
|
||||
public CommandResult execute(Game game, OutputSystem outputSystem) {
|
||||
public CommandResult execute(Game game, GameListener outputSystem) {
|
||||
this.moves = game.getBoard().getAllowedMoves(game.getPlayerTurn());
|
||||
return CommandResult.NotMoved;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package chess.controller.commands;
|
||||
|
||||
import chess.controller.OutputSystem;
|
||||
import chess.controller.PlayerCommand;
|
||||
import chess.controller.event.GameListener;
|
||||
import chess.model.ChessBoard;
|
||||
import chess.model.Coordinate;
|
||||
import chess.model.Game;
|
||||
@@ -24,7 +24,7 @@ public class MoveCommand extends PlayerCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(Game game, OutputSystem outputSystem) {
|
||||
public CommandResult execute(Game game, GameListener outputSystem) {
|
||||
final ChessBoard board = game.getBoard();
|
||||
|
||||
// we must promote the pending pawn before
|
||||
@@ -58,7 +58,7 @@ public class MoveCommand extends PlayerCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CommandResult undoImpl(Game game, OutputSystem outputSystem) {
|
||||
protected CommandResult undoImpl(Game game, GameListener outputSystem) {
|
||||
final ChessBoard board = game.getBoard();
|
||||
|
||||
board.undoMove(move, deadPiece);
|
||||
@@ -66,11 +66,11 @@ public class MoveCommand extends PlayerCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postExec(Game game, OutputSystem outputSystem) {
|
||||
public void postExec(Game game, GameListener outputSystem) {
|
||||
tryPromote(game, outputSystem);
|
||||
}
|
||||
|
||||
private void tryPromote(Game game, OutputSystem outputSystem) {
|
||||
private void tryPromote(Game game, GameListener outputSystem) {
|
||||
Coordinate pawnPos = game.getBoard().pawnPromotePosition();
|
||||
|
||||
if (pawnPos == null)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package chess.controller.commands;
|
||||
|
||||
import chess.controller.Command;
|
||||
import chess.controller.OutputSystem;
|
||||
import chess.controller.event.GameListener;
|
||||
import chess.model.ChessBoard;
|
||||
import chess.model.Color;
|
||||
import chess.model.Coordinate;
|
||||
@@ -14,7 +14,7 @@ import chess.model.pieces.Queen;
|
||||
import chess.model.pieces.Rook;
|
||||
|
||||
public class NewGameCommand extends Command {
|
||||
public CommandResult execute(Game game, OutputSystem outputSystem) {
|
||||
public CommandResult execute(Game game, GameListener outputSystem) {
|
||||
final ChessBoard board = game.getBoard();
|
||||
|
||||
board.clearBoard();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package chess.controller.commands;
|
||||
|
||||
import chess.controller.OutputSystem;
|
||||
import chess.controller.PlayerCommand;
|
||||
import chess.controller.event.GameListener;
|
||||
import chess.model.ChessBoard;
|
||||
import chess.model.Color;
|
||||
import chess.model.Coordinate;
|
||||
@@ -33,7 +33,7 @@ public class PromoteCommand extends PlayerCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(Game game, OutputSystem outputSystem) {
|
||||
public CommandResult execute(Game game, GameListener outputSystem) {
|
||||
final ChessBoard board = game.getBoard();
|
||||
|
||||
this.pieceCoords = board.pawnPromotePosition();
|
||||
@@ -78,7 +78,7 @@ public class PromoteCommand extends PlayerCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CommandResult undoImpl(Game game, OutputSystem outputSystem) {
|
||||
protected CommandResult undoImpl(Game game, GameListener outputSystem) {
|
||||
final ChessBoard board = game.getBoard();
|
||||
|
||||
Piece promoted = board.pieceAt(this.pieceCoords);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package chess.controller.commands;
|
||||
|
||||
import chess.controller.Command;
|
||||
import chess.controller.OutputSystem;
|
||||
import chess.controller.event.GameListener;
|
||||
import chess.model.Color;
|
||||
import chess.model.Game;
|
||||
|
||||
@@ -14,7 +14,7 @@ public class SurrenderCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(Game game, OutputSystem outputSystem) {
|
||||
public CommandResult execute(Game game, GameListener outputSystem) {
|
||||
outputSystem.hasSurrendered(player);
|
||||
outputSystem.winnerIs(Color.getEnemy(player));
|
||||
return CommandResult.NotMoved;
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package chess.controller.commands;
|
||||
|
||||
import chess.controller.Command;
|
||||
import chess.controller.OutputSystem;
|
||||
import chess.controller.PlayerCommand;
|
||||
import chess.controller.event.GameListener;
|
||||
import chess.model.Game;
|
||||
|
||||
public class UndoCommand extends Command{
|
||||
|
||||
@Override
|
||||
public CommandResult execute(Game game, OutputSystem outputSystem) {
|
||||
public CommandResult execute(Game game, GameListener outputSystem) {
|
||||
PlayerCommand lastAction = game.getLastAction();
|
||||
if (lastAction == null)
|
||||
return CommandResult.NotAllowed;
|
||||
|
||||
Reference in New Issue
Block a user