From 361f8f2d3cbd3ca7095572494d6ac2d3fb269fb1 Mon Sep 17 00:00:00 2001 From: yohanmontagne Date: Tue, 20 May 2025 22:43:25 +0200 Subject: [PATCH] Started to implement a gereying of previous case but not possible since I needed to modify Jpaneldraw --- .DS_Store | Bin 6148 -> 6148 bytes OOP_2B1_Project/.DS_Store | Bin 6148 -> 6148 bytes OOP_2B1_Project/src/.DS_Store | Bin 6148 -> 6148 bytes OOP_2B1_Project/src/backend/Board.java | 26 ++++++++++++++++++++----- OOP_2B1_Project/src/backend/Game.java | 4 +++- 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/.DS_Store b/.DS_Store index 50739aace3789d336ee4705f4280e0fe3600d83c..6c292dc55e0052f62a38cadd56d64fa26dd9d529 100644 GIT binary patch delta 98 zcmZoMXffDe$;7yQvK3RIn|O7#p`ng~v7vdbjzYDik%5kaiKS6(EhmSlvc7dte0EN5 iUVbM77%(zIXa-&=4Wqgy%Q7o%7GeI(vYCzJA3p$9%M-T% delta 69 zcmZoMXffDe$;7y0vK3RIx`t&T#qr4f*AVrf)c%gG_CtZy9@pPiGN Ym)|w{B9lC0_vVjGqO6B!ku~2NHo+2a1#(>?7i$5?kF>*}iVM?|YW5{60WJm{+IZ(QU!5hfR z1B!(MMN@$+XE2@2knNe1pPZDFpTxkxAi%)Dls-9ushV;7gK0B62R{eU a#hV{8e`lV|FXG4nRL=xbvpGU!4Ko1GUn}$g delta 123 zcmZoMXfc=|#>B)qu~2NHo+2ar#(>?7jO>$nSdu62X31gPFxqpRo1r-iqFo;&CBnayq{H`v3v7K_85meLM~JLp1^^%cAJ+f? diff --git a/OOP_2B1_Project/src/.DS_Store b/OOP_2B1_Project/src/.DS_Store index 62724e744c40a45854fbb6199cbc2c81eeffe81c..93eb05e6ceb6539bccc52c2327af35a28b4715d0 100644 GIT binary patch delta 68 zcmZoMXffCj&ce8Tas*4Ens{}!p`ng~v7vdbjzYDik%5kaiKS6(EhmSlvc7dte0EN5 YUVi7~4=nPGU7H11zcX!S`t&T#qr4f*AVrf)c%gG_CtZy9@pPiGN Ym)|w{J&QbJ_hx?9?@XK7IsWnk0KecA)c^nh diff --git a/OOP_2B1_Project/src/backend/Board.java b/OOP_2B1_Project/src/backend/Board.java index ea13b1f..c058b57 100644 --- a/OOP_2B1_Project/src/backend/Board.java +++ b/OOP_2B1_Project/src/backend/Board.java @@ -86,9 +86,9 @@ public class Board implements Cloneable { setPiece(true,PieceType.Bishop,2,7); setPiece(true,PieceType.Bishop,5,7); setPiece(false,PieceType.King,4,0); - setPiece(true,PieceType.King,4,7); + setPiece(true,PieceType.King,3,7); setPiece(false,PieceType.Queen,3,0); - setPiece(true,PieceType.Queen,3,7); + setPiece(true,PieceType.Queen,4,7); for (int i=0;i<8;i++) { setPiece(false,PieceType.Pawn,i,1); } @@ -103,6 +103,9 @@ public class Board implements Cloneable { pieces.clear(); selectedX = null; selectedY = null; + highlightedPositions.clear(); + boardHistory.clear(); + this.lastMoveSourceSquare = null; } @@ -151,6 +154,7 @@ public class Board implements Cloneable { Piece pieceAtPos = getPieceAt(x, y); if (pieceAtPos != null && pieceAtPos.isWhite() == turnIsWhite) { + this.lastMoveSourceSquare = null; selectedX = x; selectedY = y; @@ -163,6 +167,7 @@ public class Board implements Cloneable { } } else { if (selectedX == x && selectedY == y) { + this.lastMoveSourceSquare = null; selectedX = null; selectedY = null; highlightedPositions.clear(); @@ -312,6 +317,7 @@ public class Board implements Cloneable { turnNumber--; turnIsWhite = !turnIsWhite; kingCheckPos = null; + this.lastMoveSourceSquare = null; } public Board(Board board) { @@ -359,6 +365,8 @@ public class Board implements Cloneable { // Update turn info turnIsWhite = !turnIsWhite; turnNumber++; + + this.lastMoveSourceSquare = new int[] {move.getFromCol(), move.getFromRow()}; // Play move sound if enabled playMoveSound(); @@ -430,8 +438,11 @@ public class Board implements Cloneable { clonedBoard.selectedY = this.selectedY; clonedBoard.turnNumber = this.turnNumber; clonedBoard.turnIsWhite = this.turnIsWhite; - - + if (this.lastMoveSourceSquare != null) { + clonedBoard.lastMoveSourceSquare = new int[]{this.lastMoveSourceSquare[0], this.lastMoveSourceSquare[1]}; + } else { + clonedBoard.lastMoveSourceSquare = null; + } return clonedBoard; } catch (CloneNotSupportedException e) { throw new AssertionError(); // Should never happen @@ -539,5 +550,10 @@ public class Board implements Cloneable { && kingCheckPos[0] == squareX && kingCheckPos[1] == squareY); } + private int[] lastMoveSourceSquare = null; + + public boolean isLastMoveSourceSquare(int x, int y) { + return lastMoveSourceSquare != null && lastMoveSourceSquare[0] == x && lastMoveSourceSquare[1] == y; +} + } - diff --git a/OOP_2B1_Project/src/backend/Game.java b/OOP_2B1_Project/src/backend/Game.java index d4da752..0d8e57c 100644 --- a/OOP_2B1_Project/src/backend/Game.java +++ b/OOP_2B1_Project/src/backend/Game.java @@ -115,5 +115,7 @@ public class Game extends Thread { public boolean isKingCheckSquare(int squareX, int squareY) { return board.isKingCheckSquare(squareX, squareY); } - + public boolean isLastMoveSourceSquare(int x, int y) { + return board.isLastMoveSourceSquare(x, y); +} }