lots of things
This commit is contained in:
37
app/src/main/java/chess/io/CommandExecutor.java
Normal file
37
app/src/main/java/chess/io/CommandExecutor.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package chess.io;
|
||||
|
||||
import chess.model.Game;
|
||||
|
||||
public class CommandExecutor {
|
||||
|
||||
private final Game game;
|
||||
private final OutputSystem outputSystem;
|
||||
|
||||
public CommandExecutor(Game game, OutputSystem outputSystem) {
|
||||
this.game = game;
|
||||
this.outputSystem = outputSystem;
|
||||
}
|
||||
|
||||
public CommandResult executeCommand(Command command) {
|
||||
CommandResult result = command.execute(this.game, this.outputSystem);
|
||||
if (result == CommandResult.Moved)
|
||||
alternatePlayers();
|
||||
return result;
|
||||
}
|
||||
|
||||
private void alternatePlayers() {
|
||||
this.game.switchPlayerTurn();
|
||||
this.outputSystem.playerTurn(this.game.getPlayerTurn());
|
||||
}
|
||||
|
||||
public Game getGame() {
|
||||
return game;
|
||||
}
|
||||
|
||||
public OutputSystem getOutputSystem() {
|
||||
return outputSystem;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user