remove game signals
This commit is contained in:
@@ -1,20 +1,14 @@
|
||||
package chess.model;
|
||||
|
||||
import chess.model.pieces.Pawn;
|
||||
import common.Signal0;
|
||||
import common.Signal1;
|
||||
|
||||
public class Game {
|
||||
private final ChessBoard board;
|
||||
private Color playerTurn;
|
||||
|
||||
public final Signal1<Coordinate> OnPromote = new Signal1<>();
|
||||
public final Signal1<Color> OnWin = new Signal1<>();
|
||||
public final Signal1<Color> OnPlayerTurn = new Signal1<>();
|
||||
|
||||
public final Signal0 OnCheck = new Signal0();
|
||||
public final Signal0 OnMat = new Signal0();
|
||||
public final Signal0 OnPat = new Signal0();
|
||||
public enum GameStatus {
|
||||
Check, CheckMate, OnGoing, Pat;
|
||||
}
|
||||
|
||||
public Game(ChessBoard board) {
|
||||
this.board = board;
|
||||
@@ -30,12 +24,10 @@ public class Game {
|
||||
|
||||
public void resetPlayerTurn() {
|
||||
this.playerTurn = Color.White;
|
||||
this.OnPlayerTurn.emit(playerTurn);
|
||||
}
|
||||
|
||||
public void switchPlayerTurn() {
|
||||
playerTurn = Color.getEnemy(playerTurn);
|
||||
this.OnPlayerTurn.emit(playerTurn);
|
||||
}
|
||||
|
||||
public boolean checkPromotion(Coordinate pieceCoords) {
|
||||
@@ -52,31 +44,22 @@ public class Game {
|
||||
if (destY != enemyLine)
|
||||
return false;
|
||||
|
||||
this.OnPromote.emit(pieceCoords);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return true if game should end
|
||||
*/
|
||||
public boolean checkGameStatus() {
|
||||
public GameStatus checkGameStatus() {
|
||||
final Color enemy = Color.getEnemy(getPlayerTurn());
|
||||
|
||||
if (this.board.isKingInCheck(enemy)) {
|
||||
if (this.board.hasAllowedMoves(enemy)) {
|
||||
this.OnCheck.emit();
|
||||
} else {
|
||||
this.OnMat.emit();
|
||||
this.OnWin.emit(getPlayerTurn());
|
||||
return true;
|
||||
}
|
||||
} else if (!board.hasAllowedMoves(enemy)) {
|
||||
this.OnPat.emit();
|
||||
return true;
|
||||
}
|
||||
if (this.board.isKingInCheck(enemy))
|
||||
if (this.board.hasAllowedMoves(enemy))
|
||||
return GameStatus.Check;
|
||||
else
|
||||
return GameStatus.CheckMate;
|
||||
|
||||
return false;
|
||||
if (!board.hasAllowedMoves(enemy))
|
||||
return GameStatus.Pat;
|
||||
|
||||
return GameStatus.OnGoing;
|
||||
}
|
||||
|
||||
public boolean pawnShouldBePromoted() {
|
||||
|
||||
Reference in New Issue
Block a user