highlight marche

This commit is contained in:
Romain MURPHY 2025-04-12 11:42:07 +02:00
parent f5c67f6d81
commit 8788aaae85
3 changed files with 33 additions and 10 deletions

View File

@ -14,4 +14,15 @@
<natures> <natures>
<nature>org.eclipse.jdt.core.javanature</nature> <nature>org.eclipse.jdt.core.javanature</nature>
</natures> </natures>
<filteredResources>
<filter>
<id>1744449596284</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription> </projectDescription>

View File

@ -11,6 +11,7 @@ public class Board {
public int ym; public int ym;
public int turnNumber; public int turnNumber;
public boolean turnColor; public boolean turnColor;
public ArrayList<ArrayList<Boolean>> possibleMoves = new ArrayList<>();
public Board(int colNum, int lineNum) { public Board(int colNum, int lineNum) {
this.width = colNum; this.width = colNum;
this.height = lineNum; this.height = lineNum;
@ -18,10 +19,13 @@ public class Board {
int cols = 8; int cols = 8;
for (int i = 0; i < rows; i++) { for (int i = 0; i < rows; i++) {
ArrayList<Piece> row = new ArrayList<>(); ArrayList<Piece> row = new ArrayList<>();
ArrayList<Boolean> rowB = new ArrayList<>();
for (int j = 0; j < cols; j++) { for (int j = 0; j < cols; j++) {
row.add(null); // Fill with null row.add(null); // Fill with null
rowB.add(false);
} }
this.board.add(row); this.board.add(row);
this.possibleMoves.add(rowB);
} }
this.turnNumber = 0; this.turnNumber = 0;
this.turnColor = true; this.turnColor = true;
@ -111,9 +115,11 @@ public class Board {
} }
public void movePiece(int x, int y) { public void movePiece(int x, int y) {
Piece pieceToMove = this.board.get(this.ym).get(this.xm); if (select) {
this.setPiece(x,y,pieceToMove.getType(),pieceToMove.isWhite()); Piece pieceToMove = this.board.get(this.ym).get(this.xm);
board.get(this.ym).set(this.xm,null); this.setPiece(x,y,pieceToMove.getType(),pieceToMove.isWhite());
board.get(this.ym).set(this.xm,null);
}
} }
public void userTouch(int x, int y) { public void userTouch(int x, int y) {
@ -121,6 +127,7 @@ public class Board {
this.xm = x; this.xm = x;
this.ym = y; this.ym = y;
select = true; select = true;
possibleMoves = board.get(y).get(x).getPossibleMoves(board);
} }
else if (select == true && this.xm != x || this.ym != y){ else if (select == true && this.xm != x || this.ym != y){
this.movePiece(x, y); this.movePiece(x, y);
@ -129,6 +136,7 @@ public class Board {
// System.out.println(this.toString()); // Debug // System.out.println(this.toString()); // Debug
this.turnColor = !this.turnColor; this.turnColor = !this.turnColor;
} else { } else {
// System.out.println("a"); // debug
select = false; select = false;
} }
} }
@ -155,8 +163,12 @@ public class Board {
/* The following methods require more work ! */ /* The following methods require more work ! */
public boolean isHighlighted(int x, int y) { public boolean isHighlighted(int x, int y) {
//TODO boolean toBeReturned;
return false; if (select) {
toBeReturned = possibleMoves.get(y).get(x);
}
else { toBeReturned = false;}
return toBeReturned;
} }
public void undoLastMove() { public void undoLastMove() {

View File

@ -24,14 +24,14 @@ public class Pawn extends Piece {
// Move forward // Move forward
int nextY = y + direction; int nextY = y + direction;
if (nextY >= 0 && nextY < 8) { if (nextY >= 0 && nextY < 8 && board.get(nextY).get(x) == null) {
moves.get(nextY).set(x, true); moves.get(nextY).set(x, true);
// Two steps forward // Two steps forward
// int doubleY = y + 2 * direction; int doubleY = y + 2 * direction;
// if (y == startRow && board.get(doubleY).get(x) == null) { if (y == startRow && board.get(doubleY).get(x) == null) {
// moves.get(doubleY).set(x, true); moves.get(doubleY).set(x, true);
// } }
} }
// Captures // Captures