refactor game

This commit is contained in:
2025-04-03 22:15:50 +02:00
parent 0d72e015f1
commit 55774b4605

View File

@@ -52,9 +52,8 @@ public class Game {
if (destY != enemyLine) if (destY != enemyLine)
return false; return false;
OnPromote.emit(pieceCoords); this.OnPromote.emit(pieceCoords);
return true; return true;
} }
/** /**
@@ -62,22 +61,21 @@ public class Game {
* @return true if game should end * @return true if game should end
*/ */
public boolean checkGameStatus() { public boolean checkGameStatus() {
final ChessBoard board = getBoard();
final Color enemy = Color.getEnemy(getPlayerTurn()); final Color enemy = Color.getEnemy(getPlayerTurn());
if (board.isKingInCheck(enemy)) { if (this.board.isKingInCheck(enemy)) {
if (board.hasAllowedMoves(enemy)) { if (this.board.hasAllowedMoves(enemy)) {
OnCheck.emit(); this.OnCheck.emit();
} else { } else {
OnMat.emit(); this.OnMat.emit();
OnWin.emit(getPlayerTurn()); this.OnWin.emit(getPlayerTurn());
return true; return true;
} }
} else if (!board.hasAllowedMoves(enemy)) { } else if (!board.hasAllowedMoves(enemy)) {
OnPat.emit(); this.OnPat.emit();
return true; return true;
} }
return false; return false;
} }
@@ -91,7 +89,7 @@ public class Game {
int enemyLineY = color == Color.White ? 0 : 7; int enemyLineY = color == Color.White ? 0 : 7;
for (int x = 0; x < Coordinate.VALUE_MAX; x++) { for (int x = 0; x < Coordinate.VALUE_MAX; x++) {
if(checkPromotion(new Coordinate(x, enemyLineY))) if (checkPromotion(new Coordinate(x, enemyLineY)))
return true; return true;
} }