pieces on board

This commit is contained in:
chloe 2025-05-07 15:53:11 +02:00
parent 7fb7335ac8
commit 6beffc0b94
1 changed files with 33 additions and 16 deletions

View File

@ -6,14 +6,13 @@ public class Board {
public int width; public int width;
public int height; public int height;
public int TurnNumber; private Piece[][] board;
public Board(int colNum, int lineNum) { public Board(int colNum, int lineNum) {
//TODO //TODO
this.width = colNum; this.width = colNum;
this.height = lineNum; this.height = lineNum;
this.TurnNumber = 0; this.board= new Piece[width][height];
} }
public int getWidth() { public int getWidth() {
@ -30,7 +29,7 @@ public class Board {
public int getTurnNumber() { public int getTurnNumber() {
//TODO //TODO
return TurnNumber; return 0;
} }
public boolean isTurnWhite() { public boolean isTurnWhite() {
@ -39,15 +38,28 @@ 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 if (x >= 0 && x < width && y >= 0 && y < height) {
board[y][x] = new Piece(x, y, isWhite, type);
}
} }
//TODO TEST
public void populateBoard() { public void populateBoard() {
//TODO cleanBoard();
for (int x = 0; x < 8; x++) {
} setPiece(true, PieceType.Pawn, x, 1);
}
for (int x = 0; x < 8; x++) {
setPiece(false, PieceType.Pawn, x, 6);
}
PieceType[] value = {PieceType.Rook, PieceType.Knight, PieceType.Bishop, PieceType.Queen, PieceType.King, PieceType.Bishop, PieceType.Knight, PieceType.Rook};
for (int x = 0; x < 8; x++) {
setPiece(true, value[x], x, 0);
}
for (int x = 0; x < 8; x++) {
setPiece(false, value[x], x, 7);
} }
public void cleanBoard() { public void cleanBoard() {
//TODO //TODO
@ -59,10 +71,15 @@ public class Board {
} }
public ArrayList<Piece> getPieces() { public ArrayList<Piece> getPieces() {
ArrayList<Piece> pieces = new ArrayList<>(); ArrayList<Piece> pieces = new ArrayList<>();
//TODO for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
return pieces; if (board[y][x] != null) {
pieces.add(board[y][x]);
}
}
}
return pieces;
} }
public void userTouch(int x, int y) { public void userTouch(int x, int y) {
@ -109,4 +126,4 @@ public class Board {
} }
} }