isHighlighted + nv fonction qui output les moves possibles (j'ai fait
que le pion)
This commit is contained in:
parent
b01ceb96f5
commit
74b7ea7053
|
|
@ -11,6 +11,7 @@ public class Board {
|
|||
private int y;
|
||||
private int turns;
|
||||
private boolean whiteTurn;
|
||||
private boolean metPiece;
|
||||
|
||||
public Board(int colNum, int lineNum) {
|
||||
this.colNum = colNum;
|
||||
|
|
@ -20,6 +21,7 @@ public class Board {
|
|||
y = -1;
|
||||
turns = 0;
|
||||
whiteTurn = true;
|
||||
metPiece = false;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
|
|
@ -139,10 +141,12 @@ public class Board {
|
|||
if (this.x == x && this.y == y) {
|
||||
this.x = -1;
|
||||
this.y = -1;
|
||||
metPiece = false;
|
||||
}
|
||||
else if (board[this.y][this.x] == null) {
|
||||
this.x = -1;
|
||||
this.y = -1;
|
||||
metPiece = false;
|
||||
}
|
||||
else {
|
||||
board[this.y][this.x].setX(x);
|
||||
|
|
@ -152,6 +156,7 @@ public class Board {
|
|||
turns += 1;
|
||||
this.x = -1;
|
||||
this.y = -1;
|
||||
metPiece = false;
|
||||
if (whiteTurn == true) {
|
||||
whiteTurn = false;
|
||||
}
|
||||
|
|
@ -166,6 +171,96 @@ public class Board {
|
|||
}
|
||||
}
|
||||
|
||||
public ArrayList<int[]> getMove(PieceType type, boolean isWhite, int x, int y) {
|
||||
ArrayList<int[]> moves = new ArrayList<>();
|
||||
int i = x;
|
||||
int j = y;
|
||||
int[] arr;
|
||||
|
||||
if (type == PieceType.Rook) {
|
||||
|
||||
}
|
||||
else if (type == PieceType.Knight) {
|
||||
//moves.add(new int[] {i, j});
|
||||
}
|
||||
else if (type == PieceType.Bishop) {
|
||||
//moves.add(new int[] {i, j});
|
||||
}
|
||||
else if (type == PieceType.Queen) {
|
||||
//moves.add(new int[] {i, j});
|
||||
}
|
||||
else if (type == PieceType.King) {
|
||||
//moves.add(new int[] {i, j});
|
||||
}
|
||||
else {
|
||||
if (isWhite == false) {
|
||||
if (y == 1) {
|
||||
if (board[j+1][i] == null) {
|
||||
moves.add(new int[] {i, j+1});
|
||||
if (board[j+2][i] == null) {
|
||||
moves.add(new int[] {i, j+2});
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (board[j+1][i] == null) {
|
||||
moves.add(new int[] {i, j+1});
|
||||
}
|
||||
}
|
||||
if (x != 7) {
|
||||
if (board[j+1][i+1] != null) {
|
||||
moves.add(new int[] {i+1, j+1});
|
||||
}
|
||||
}
|
||||
if (x != 0) {
|
||||
if (board[j+1][i-1] != null) {
|
||||
moves.add(new int[] {i-1, j+1});
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (y == 6) {
|
||||
if (board[j-1][i] == null) {
|
||||
moves.add(new int[] {i, j-1});
|
||||
if (board[j-2][i] == null) {
|
||||
moves.add(new int[] {i, j-2});
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (board[j-1][i] == null) {
|
||||
moves.add(new int[] {i, j-1});
|
||||
}
|
||||
}
|
||||
if (x != 7) {
|
||||
if (board[j-1][i+1] != null) {
|
||||
moves.add(new int[] {i+1, j-1});
|
||||
}
|
||||
}
|
||||
if (x != 0) {
|
||||
if (board[j-1][i-1] != null) {
|
||||
moves.add(new int[] {i-1, j-1});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*while (metPiece == false && i < 8 && j < 8) {
|
||||
if (x == i && y == j) {
|
||||
if (board[j][i] != null) {
|
||||
metPiece = true;
|
||||
}
|
||||
moves.add(new int[] {i, j});
|
||||
}
|
||||
else if (x != this.x && y == this.y) {
|
||||
if (board[y][x] != null) {
|
||||
metPiece = true;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
return moves;
|
||||
}
|
||||
|
||||
public boolean isSelected(int x, int y) {
|
||||
if (this.x != -1 && this.y != -1) {
|
||||
if (this.x == x && this.y == y) {
|
||||
|
|
@ -196,7 +291,15 @@ public class Board {
|
|||
/* The following methods require more work ! */
|
||||
|
||||
public boolean isHighlighted(int x, int y) {
|
||||
//TODO
|
||||
if (this.x != -1 && this.y != -1) {
|
||||
ArrayList<int[]> moves = this.getMove(board[this.y][this.x].getType(), board[this.y][this.x].isWhite(), this.x, this.y);
|
||||
for (int i = 0; i < moves.size(); i++) {
|
||||
int[] coordinates = moves.get(i);
|
||||
if (x == coordinates[0] && y == coordinates[1]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue