diff --git a/src/backend/Board.java b/src/backend/Board.java index b493aee..6bd2c0b 100644 --- a/src/backend/Board.java +++ b/src/backend/Board.java @@ -15,7 +15,11 @@ public class Board { private boolean pawnDoubleStep; private int xCoordinatePawn; private int yCoordinatePawn; +//<<<<<<< HEAD private boolean enPassant; +//======= + private boolean isGameOver = false;//flag for when a king is checkmate and no moves can be made anymore +//>>>>>>> branch 'master' of https://gitarero.ecam.fr/louise.berteloot/OOP_2A5_Project.git private ArrayList previousStates; @@ -129,6 +133,7 @@ public class Board { public void cleanBoard() { pieces.clear(); + isGameOver=false;//when board reset, moves can be made again bc not game over anymore } public String toString() { @@ -159,6 +164,10 @@ public class Board { } public void userTouch(int x, int y) { + if (isGameOver==true) {//if game is over, any attempt to select/move a piece should be ignored + System.out.println("Checkmate! Can't move pieces anymore.");//says game over + return; + } System.out.println("userTouch triggered at: " + x + ", " + y); Piece selectedPiece = getPieceAt(selectedX, selectedY); @@ -237,7 +246,8 @@ public class Board { rook.setX(5);//moves the rook to the square to the left of the king rook.setMoved(true);//the rook has been moved once so wont be used for castling anymore } - } else {//king moves to the left this time (queen side castling) + } + else {//king moves to the left this time (queen side castling) Piece rook = getPieceAt(0, row);//selects the rook on the left if (rook != null) { rook.setX(3);//moves rook to the right of the king @@ -262,6 +272,7 @@ public class Board { if (isCheckmate(isWhite)) { System.out.println((isWhite ? "White" : "Black") + " is in checkmate!"); + isGameOver=true;//if checkmate, flags the game as over by setting boolean on true } } }