Merge branch 'master' of https://gitarero.ecam.fr/jerome.bedier/OOP_1A6_Project.git
This commit is contained in:
commit
5e8632b7e3
|
|
@ -39,8 +39,16 @@ public class Board {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPiece(boolean isWhite, PieceType type, int x, int y) {
|
public void setPiece(boolean isWhite, PieceType type, int x, int y) {
|
||||||
//TODO
|
// Ensure coordinates are inside the board boundaries
|
||||||
|
// if (x < 0 || x >= width || y < 0 || y >= height) {
|
||||||
|
// System.out.println("Invalid coordinates: (" + x + ", " + y + ")");
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Create and place the new piece
|
||||||
|
board[x][y] = new Piece(isWhite, type, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void populateBoard() {
|
public void populateBoard() {
|
||||||
/*
|
/*
|
||||||
|
|
@ -84,8 +92,28 @@ public class Board {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
//TODO
|
StringBuilder sb = new StringBuilder();
|
||||||
return "";
|
for (int y = 0; y < height; y++) {
|
||||||
|
for (int x = 0; x < width; x++) {
|
||||||
|
Piece piece = board[x][y];
|
||||||
|
if (piece == null) {
|
||||||
|
sb.append(" ");
|
||||||
|
} else {
|
||||||
|
sb.append(piece.isWhite() ? "W" : "B");
|
||||||
|
switch (piece.getType()) {
|
||||||
|
case Rook: sb.append("R"); break;
|
||||||
|
case Knight: sb.append("N"); break;
|
||||||
|
case Bishop: sb.append("B"); break;
|
||||||
|
case Queen: sb.append("Q"); break;
|
||||||
|
case King: sb.append("K"); break;
|
||||||
|
case Pawn: sb.append("P"); break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (x < width - 1) sb.append(",");
|
||||||
|
}
|
||||||
|
sb.append("\n");
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<Piece> getPieces() {
|
public ArrayList<Piece> getPieces() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue