king check sound (still small problems)

This commit is contained in:
samuelsmith 2025-05-08 14:49:12 +02:00
parent b494861f8d
commit a4db7193e2
1 changed files with 7 additions and 2 deletions

View File

@ -3,6 +3,9 @@ package backend;
import java.util.ArrayList; import java.util.ArrayList;
public class KingCheck { public class KingCheck {
private boolean opponentWasInCheck = false;
private SoundEffect soundEffect = new SoundEffect();
private boolean soundShouldPlay = true;
public ArrayList<ArrayList<Boolean>> getLegalMoves(Piece piece, ArrayList<ArrayList<Piece>> board, Move lastMove) { public ArrayList<ArrayList<Boolean>> getLegalMoves(Piece piece, ArrayList<ArrayList<Piece>> board, Move lastMove) {
ArrayList<ArrayList<Boolean>> rawMoves = piece.getPossibleMoves(board,lastMove); ArrayList<ArrayList<Boolean>> rawMoves = piece.getPossibleMoves(board,lastMove);
@ -53,12 +56,14 @@ public class KingCheck {
if (p != null && p.isWhite() != isWhiteTurn) { if (p != null && p.isWhite() != isWhiteTurn) {
ArrayList<ArrayList<Boolean>> moves = p.getPossibleMoves(board); ArrayList<ArrayList<Boolean>> moves = p.getPossibleMoves(board);
if (moves.get(kingY).get(kingX)) { if (moves.get(kingY).get(kingX)) {
return true; // King can be captured if (soundShouldPlay){
soundEffect.aiSound();
soundShouldPlay=false;
}
} }
} }
} }
} }
return false; // King is safe return false; // King is safe
} }