diff --git a/app/src/main/java/chess/view/DDDrender/DDDView.java b/app/src/main/java/chess/view/DDDrender/DDDView.java index 3588f62..36f31be 100644 --- a/app/src/main/java/chess/view/DDDrender/DDDView.java +++ b/app/src/main/java/chess/view/DDDrender/DDDView.java @@ -52,6 +52,16 @@ public class DDDView extends GameAdaptator implements GameListener { // Invoked when a cell is clicked private void onCellClick(Coordinate coordinate) { if (this.click == null){ // case: first click + GetAllowedMovesPieceCommand movesCommand = new GetAllowedMovesPieceCommand(coordinate); + if (sendCommand(movesCommand) == CommandResult.NotAllowed) { // case: invalid piece to move + System.out.println("Nothing to do here."); + return; + } + List allowedMoves = movesCommand.getDestinations(); + if (allowedMoves.isEmpty()) { // case: no movement possible for piece + System.out.println("This piece cannot be moved at the moment."); + return; + } setClick(coordinate); previewMoves(coordinate); System.out.println("First click on " + coordinate); @@ -60,12 +70,14 @@ public class DDDView extends GameAdaptator implements GameListener { // case: second click GetAllowedMovesPieceCommand movesCommand = new GetAllowedMovesPieceCommand(this.click); if (sendCommand(movesCommand) == CommandResult.NotAllowed) { // case: invalid piece to move + cancelPreview(this.click); System.out.println("Nothing to do here."); cancelClick(); return; } List allowedMoves = movesCommand.getDestinations(); if (allowedMoves.isEmpty()) { // case: no movement possible for piece + cancelPreview(this.click); System.out.println("This piece cannot be moved at the moment."); cancelClick(); return; @@ -85,19 +97,20 @@ public class DDDView extends GameAdaptator implements GameListener { return; } System.out.println("Cancelling click."); // case: cancelling previous click - cancelPreview(this.click); cancelClick(); } private void previewMoves(Coordinate coordinate){ - this.boardEntity.setCellColor(coordinate, new Vector3f(1, 0, 0)); Piece p = pieceAt(coordinate); - if (p == null) + if (p == null) { return; - this.world.getPiece(coordinate).setColor(new Vector3f(1, 0, 0)); + } GetAllowedMovesPieceCommand movesCommand = new GetAllowedMovesPieceCommand(coordinate); - if (sendCommand(movesCommand) == CommandResult.NotAllowed) + if (sendCommand(movesCommand) == CommandResult.NotAllowed) { return; + } + this.boardEntity.setCellColor(coordinate, new Vector3f(1, 0, 0)); + this.world.getPiece(coordinate).setColor(new Vector3f(1, 0, 0)); List allowedMoves = movesCommand.getDestinations(); if (allowedMoves.isEmpty()) return;