From 318be7fb357935ffd6e6d4aa14462b553fd9d480 Mon Sep 17 00:00:00 2001 From: keshi Date: Tue, 6 May 2025 15:48:48 +0200 Subject: [PATCH] we added array list, clean board, get pieces, set piece we started tostring and usertouch --- src/Main.java | 15 +++++++++++++-- src/backend/Board.java | 12 ++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/Main.java b/src/Main.java index 15b2c2c..4f0590a 100644 --- a/src/Main.java +++ b/src/Main.java @@ -14,6 +14,7 @@ public class Main { // testing : //testing the board Board testBoard = new Board(8, 8); + //getting the pieces on the board testBoard.populateBoard(); System.out.println(testBoard.getWidth()); System.out.println(testBoard.getHeight()); @@ -27,12 +28,22 @@ public class Main { System.out.println(testPiece.isWhite()); //getting the pieces on the board - System.out.println(testBoard.getPieces()); - + ArrayList allPieces=testBoard.getPieces(); + for (Piece piece:allPieces) { + System.out.println((piece.isWhite() ? "White ":"Black ")+ piece.getType().getSummary()+" located at "+ piece.getX()+ "," + piece.getY()); + } + + //adding new piece to the board + testBoard.setPiece(true, PieceType.Bishop, 4, 7); + testBoard.toString(); + // launches graphical interface : MyInterface mjf = new MyInterface(); mjf.setVisible(true); + + //cleaning the board + testBoard.cleanBoard(); } } diff --git a/src/backend/Board.java b/src/backend/Board.java index cc0d38b..467fa72 100644 --- a/src/backend/Board.java +++ b/src/backend/Board.java @@ -34,7 +34,7 @@ public class Board { } public void setPiece(boolean isWhite, PieceType type, int x, int y) { - //TODO + board[x][y]=new Piece(x, y, type, isWhite ); } public void populateBoard() { @@ -56,11 +56,15 @@ public class Board { public void cleanBoard() { - //TODO + for(int y=0; y<8;y++) { + for(int x=0; x<8; x++) { + board[x][y]=null; + } + } } - public String toString() { - //TODO + public String toString() { //method should be upgraded as we go to represent the full board's data as we go + return ""; }