we added array list, clean board, get pieces, set piece

we started tostring and usertouch
This commit is contained in:
keshi 2025-05-06 15:48:48 +02:00
parent 550f987f8b
commit 318be7fb35
2 changed files with 21 additions and 6 deletions

View File

@ -14,6 +14,7 @@ public class Main {
// testing : // testing :
//testing the board //testing the board
Board testBoard = new Board(8, 8); Board testBoard = new Board(8, 8);
//getting the pieces on the board
testBoard.populateBoard(); testBoard.populateBoard();
System.out.println(testBoard.getWidth()); System.out.println(testBoard.getWidth());
System.out.println(testBoard.getHeight()); System.out.println(testBoard.getHeight());
@ -27,12 +28,22 @@ public class Main {
System.out.println(testPiece.isWhite()); System.out.println(testPiece.isWhite());
//getting the pieces on the board //getting the pieces on the board
System.out.println(testBoard.getPieces()); ArrayList<Piece> 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 : // launches graphical interface :
MyInterface mjf = new MyInterface(); MyInterface mjf = new MyInterface();
mjf.setVisible(true); mjf.setVisible(true);
//cleaning the board
testBoard.cleanBoard();
} }
} }

View File

@ -34,7 +34,7 @@ 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 board[x][y]=new Piece(x, y, type, isWhite );
} }
public void populateBoard() { public void populateBoard() {
@ -56,11 +56,15 @@ public class Board {
public void cleanBoard() { 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() { public String toString() { //method should be upgraded as we go to represent the full board's data as we go
//TODO
return ""; return "";
} }