lots of things
This commit is contained in:
@@ -1,14 +1,8 @@
|
||||
package chess.model;
|
||||
|
||||
import chess.model.visitor.PiecePathChecker;
|
||||
import common.Signal0;
|
||||
import common.Signal1;
|
||||
|
||||
public class Game {
|
||||
private final ChessBoard board;
|
||||
|
||||
public final Signal0 OnRenderUpdate = new Signal0();
|
||||
public final Signal1<Move> OnMoveRefused = new Signal1<>();
|
||||
private Color playerTurn;
|
||||
|
||||
public Game(ChessBoard board) {
|
||||
this.board = board;
|
||||
@@ -18,14 +12,28 @@ public class Game {
|
||||
return board;
|
||||
}
|
||||
|
||||
public void tryMove(Move move) {
|
||||
boolean valid = new PiecePathChecker(board, move).isValid();
|
||||
if (!valid) {
|
||||
this.OnMoveRefused.emit(move);
|
||||
return;
|
||||
}
|
||||
this.board.applyMove(move);
|
||||
this.OnRenderUpdate.emit();
|
||||
public Color getPlayerTurn() {
|
||||
return playerTurn;
|
||||
}
|
||||
|
||||
public void resetPlayerTurn() {
|
||||
this.playerTurn = Color.White;
|
||||
}
|
||||
|
||||
public void switchPlayerTurn() {
|
||||
playerTurn = Color.getEnemy(playerTurn);
|
||||
}
|
||||
|
||||
public boolean[][] getAllowedMoves(Coordinate coordinate) {
|
||||
Piece piece = this.board.pieceAt(coordinate);
|
||||
|
||||
if (piece == null)
|
||||
return null;
|
||||
|
||||
if (piece.getColor() != getPlayerTurn())
|
||||
return null;
|
||||
|
||||
return this.board.getAllowedMoves(coordinate);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user