Pieces are on the board <3

This commit is contained in:
Bastien Druillette 2025-05-07 15:47:02 +02:00
parent 0738c9ded9
commit db9efb80a6
1 changed files with 16 additions and 6 deletions

View File

@ -6,12 +6,13 @@ public class Board {
public int width;
public int height;
private Piece[][] board;
public Board(int colNum, int lineNum) {
//TODO
this.width = colNum;
this.height = lineNum;
this.board= new Piece[width][height];
}
public int getWidth() {
@ -37,8 +38,12 @@ public class Board {
}
public void setPiece(boolean isWhite, PieceType type, int x, int y) {
if (x >= 0 && x < width && y >= 0 && y < height) {
board[y][x] = new Piece(x, y, isWhite, type);
}
}
//TODO TEST
}
public void populateBoard() {
cleanBoard();
@ -66,10 +71,15 @@ public class Board {
}
public ArrayList<Piece> getPieces() {
ArrayList<Piece> pieces = new ArrayList<>();
//TODO
return pieces;
ArrayList<Piece> pieces = new ArrayList<>();
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
if (board[y][x] != null) {
pieces.add(board[y][x]);
}
}
}
return pieces;
}
public void userTouch(int x, int y) {