dev #12

Merged
Persson-dev merged 44 commits from dev into main 2025-05-17 15:05:24 +00:00
Showing only changes of commit 39c7ebefe6 - Show all commits

View File

@@ -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<Coordinate> 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<Coordinate> 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<Coordinate> allowedMoves = movesCommand.getDestinations();
if (allowedMoves.isEmpty())
return;