clean board

This commit is contained in:
User 2025-05-07 16:02:33 +02:00
parent 6beffc0b94
commit 93251fd76a
1 changed files with 106 additions and 112 deletions

View File

@ -4,126 +4,120 @@ import java.util.ArrayList;
public class Board { public class Board {
public int width; public int width;
public int height; public int height;
private Piece[][] board; private Piece[][] board;
public Board(int colNum, int lineNum) { public Board(int colNum, int lineNum) {
//TODO this.width = colNum;
this.width = colNum; this.height = lineNum;
this.height = lineNum; this.board = new Piece[width][height];
this.board= new Piece[width][height]; }
}
public int getWidth() {
public int getWidth() { return width;
//TODO }
return width;
}
public int getHeight() {
return height;
public int getHeight() { }
//TODO
return height;
}
public int getTurnNumber() { public int getTurnNumber() {
//TODO return 0;
return 0; }
}
public boolean isTurnWhite() { public boolean isTurnWhite() {
//TODO return false;
return false; }
}
public void setPiece(boolean isWhite, PieceType type, int x, int y) { public void setPiece(boolean isWhite, PieceType type, int x, int y) {
if (x >= 0 && x < width && y >= 0 && y < height) { if (x >= 0 && x < width && y >= 0 && y < height) {
board[y][x] = new Piece(x, y, isWhite, type); board[x][y] = new Piece(isWhite, type, x, y);
} }
} }
//TODO TEST
public void populateBoard() { public void populateBoard() {
cleanBoard(); cleanBoard();
for (int x = 0; x < 8; x++) { // White pawns
setPiece(true, PieceType.Pawn, x, 1); 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); // Black pawns
} for (int x = 0; x < 8; x++) {
PieceType[] value = {PieceType.Rook, PieceType.Knight, PieceType.Bishop, PieceType.Queen, PieceType.King, PieceType.Bishop, PieceType.Knight, PieceType.Rook}; setPiece(false, PieceType.Pawn, x, 6);
for (int x = 0; x < 8; x++) { }
setPiece(true, value[x], x, 0);
} PieceType[] backRow = {
for (int x = 0; x < 8; x++) { PieceType.Rook, PieceType.Knight, PieceType.Bishop,
setPiece(false, value[x], x, 7); PieceType.Queen, PieceType.King, PieceType.Bishop,
} } PieceType.Knight, PieceType.Rook
};
public void cleanBoard() {
//TODO // White back row
} for (int x = 0; x < 8; x++) {
setPiece(true, backRow[x], x, 0);
public String toString() { }
//TODO // Black back row
return "board"; for (int x = 0; x < 8; x++) {
} setPiece(false, backRow[x], x, 7);
}
public ArrayList<Piece> getPieces() { }
ArrayList<Piece> pieces = new ArrayList<>();
for (int y = 0; y < height; y++) { public void cleanBoard() {
for (int x = 0; x < width; x++) { for (int x = 0; x < width; x++) {
if (board[y][x] != null) { for (int y = 0; y < height; y++) {
pieces.add(board[y][x]); board[x][y] = null;
} }
} }
} }
return pieces;
} public String toString() {
return "board";
}
public ArrayList<Piece> getPieces() {
ArrayList<Piece> pieces = new ArrayList<>();
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
if (board[x][y] != null) {
pieces.add(board[x][y]);
}
}
}
return pieces;
}
public void userTouch(int x, int y) { public void userTouch(int x, int y) {
//TODO // TODO
}
}
public boolean isSelected(int x, int y) { public boolean isSelected(int x, int y) {
//TODO return false;
return false; }
}
/* saving-loading feature */
/* saving-loading feature :*/ public String[] toFileRep() {
return null;
}
public String[] toFileRep() { public Board(String[] array) {
//TODO // TODO
return null; }
}
/* The following methods require more work */
public boolean isHighlighted(int x, int y) {
return false;
}
public Board(String[] array) { public void undoLastMove() {
//TODO // TODO
}
}
/* The following methods require more work ! */
public boolean isHighlighted(int x, int y) {
//TODO
return false;
}
public void undoLastMove() {
//TODO
}
public Board(Board board) {
//TODO
}
public void playMove(Move move) {
//TODO
}
public Board(Board board) {
// TODO
}
public void playMove(Move move) {
// TODO
}
} }