highlight marche
This commit is contained in:
parent
f5c67f6d81
commit
8788aaae85
|
|
@ -14,4 +14,15 @@
|
|||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</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>
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ public class Board {
|
|||
public int ym;
|
||||
public int turnNumber;
|
||||
public boolean turnColor;
|
||||
public ArrayList<ArrayList<Boolean>> possibleMoves = new ArrayList<>();
|
||||
public Board(int colNum, int lineNum) {
|
||||
this.width = colNum;
|
||||
this.height = lineNum;
|
||||
|
|
@ -18,10 +19,13 @@ public class Board {
|
|||
int cols = 8;
|
||||
for (int i = 0; i < rows; i++) {
|
||||
ArrayList<Piece> row = new ArrayList<>();
|
||||
ArrayList<Boolean> rowB = new ArrayList<>();
|
||||
for (int j = 0; j < cols; j++) {
|
||||
row.add(null); // Fill with null
|
||||
rowB.add(false);
|
||||
}
|
||||
this.board.add(row);
|
||||
this.possibleMoves.add(rowB);
|
||||
}
|
||||
this.turnNumber = 0;
|
||||
this.turnColor = true;
|
||||
|
|
@ -111,9 +115,11 @@ public class Board {
|
|||
}
|
||||
|
||||
public void movePiece(int x, int y) {
|
||||
Piece pieceToMove = this.board.get(this.ym).get(this.xm);
|
||||
this.setPiece(x,y,pieceToMove.getType(),pieceToMove.isWhite());
|
||||
board.get(this.ym).set(this.xm,null);
|
||||
if (select) {
|
||||
Piece pieceToMove = this.board.get(this.ym).get(this.xm);
|
||||
this.setPiece(x,y,pieceToMove.getType(),pieceToMove.isWhite());
|
||||
board.get(this.ym).set(this.xm,null);
|
||||
}
|
||||
}
|
||||
|
||||
public void userTouch(int x, int y) {
|
||||
|
|
@ -121,6 +127,7 @@ public class Board {
|
|||
this.xm = x;
|
||||
this.ym = y;
|
||||
select = true;
|
||||
possibleMoves = board.get(y).get(x).getPossibleMoves(board);
|
||||
}
|
||||
else if (select == true && this.xm != x || this.ym != y){
|
||||
this.movePiece(x, y);
|
||||
|
|
@ -129,6 +136,7 @@ public class Board {
|
|||
// System.out.println(this.toString()); // Debug
|
||||
this.turnColor = !this.turnColor;
|
||||
} else {
|
||||
// System.out.println("a"); // debug
|
||||
select = false;
|
||||
}
|
||||
}
|
||||
|
|
@ -155,8 +163,12 @@ public class Board {
|
|||
/* The following methods require more work ! */
|
||||
|
||||
public boolean isHighlighted(int x, int y) {
|
||||
//TODO
|
||||
return false;
|
||||
boolean toBeReturned;
|
||||
if (select) {
|
||||
toBeReturned = possibleMoves.get(y).get(x);
|
||||
}
|
||||
else { toBeReturned = false;}
|
||||
return toBeReturned;
|
||||
}
|
||||
|
||||
public void undoLastMove() {
|
||||
|
|
|
|||
|
|
@ -24,14 +24,14 @@ public class Pawn extends Piece {
|
|||
|
||||
// Move forward
|
||||
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);
|
||||
|
||||
// Two steps forward
|
||||
// int doubleY = y + 2 * direction;
|
||||
// if (y == startRow && board.get(doubleY).get(x) == null) {
|
||||
// moves.get(doubleY).set(x, true);
|
||||
// }
|
||||
int doubleY = y + 2 * direction;
|
||||
if (y == startRow && board.get(doubleY).get(x) == null) {
|
||||
moves.get(doubleY).set(x, true);
|
||||
}
|
||||
}
|
||||
|
||||
// Captures
|
||||
|
|
|
|||
Loading…
Reference in New Issue