From db9efb80a6a5547e6b2a3b3e93550dc4768e36d9 Mon Sep 17 00:00:00 2001 From: Bastien Druillette Date: Wed, 7 May 2025 15:47:02 +0200 Subject: [PATCH] Pieces are on the board <3 --- src/backend/Board.java | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/backend/Board.java b/src/backend/Board.java index 5ec4efa..9a0fd7f 100644 --- a/src/backend/Board.java +++ b/src/backend/Board.java @@ -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 getPieces() { - ArrayList pieces = new ArrayList<>(); - //TODO - - return pieces; + ArrayList 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) {