I added the sound

This commit is contained in:
romca 2025-05-21 11:56:44 +02:00
parent ebcda9c623
commit 93e9c71855
3 changed files with 13 additions and 3 deletions

View File

@ -59,7 +59,7 @@ public class Board {
Piece p = pieces.get(i); Piece p = pieces.get(i);
if (p.getX() == x && p.getY() == y) { if (p.getX() == x && p.getY() == y) {
pieces.remove(i); pieces.remove(i);
break; i = pieces.size();
} }
} }
Piece newPiece = new Piece(x, y, type, isWhite); Piece newPiece = new Piece(x, y, type, isWhite);
@ -72,7 +72,7 @@ public class Board {
Piece p = pieces.get(i); Piece p = pieces.get(i);
if (p.getX() == x && p.getY() == y) { if (p.getX() == x && p.getY() == y) {
pieces.remove(i); pieces.remove(i);
break; i = pieces.size();
} }
} }
} }
@ -189,6 +189,10 @@ public class Board {
if (move.isValid()) { if (move.isValid()) {
move.execute(); move.execute();
// Play the move sound
Sound.getInstance().playMoveSound();
// Check for checkmate // Check for checkmate
if (move.putsOpponentInCheckmate()) { if (move.putsOpponentInCheckmate()) {
System.out.println("Checkmate! " + (isWhiteTurn ? "Black" : "White") + " wins!"); System.out.println("Checkmate! " + (isWhiteTurn ? "Black" : "White") + " wins!");
@ -256,7 +260,9 @@ public class Board {
} }
for (int y = 0; y < height; y++) { for (int y = 0; y < height; y++) {
if (y >= array.length) break; if (y >= array.length) {
y = height;
}else {
String line = array[y]; String line = array[y];
String[] squares = line.split(","); String[] squares = line.split(",");
@ -274,6 +280,7 @@ public class Board {
pieces.add(new Piece(x, y, type, isWhite)); pieces.add(new Piece(x, y, type, isWhite));
} }
} }
}
if (array.length > height) { if (array.length > height) {
String turnInfo = array[height]; String turnInfo = array[height];
@ -360,6 +367,9 @@ public class Board {
public void playMove(Move move) { public void playMove(Move move) {
if (move.isValid() && !move.putsOwnKingInCheck()) { if (move.isValid() && !move.putsOwnKingInCheck()) {
move.execute(); move.execute();
// Play the move sound
Sound.getInstance().playMoveSound();
} }
} }
} }