everything done until setPiece, the board showcases the piece
This commit is contained in:
parent
4c53382718
commit
13914dd390
|
|
@ -47,6 +47,8 @@ public class Board {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void populateBoard() {
|
public void populateBoard() {
|
||||||
|
// Puts the board in its default configuration
|
||||||
|
// adding all necessary pieces at the expected starting locations
|
||||||
PieceType[] backRow = {
|
PieceType[] backRow = {
|
||||||
PieceType.Rook, PieceType.Knight, PieceType.Bishop,
|
PieceType.Rook, PieceType.Knight, PieceType.Bishop,
|
||||||
PieceType.Queen, PieceType.King, PieceType.Bishop,
|
PieceType.Queen, PieceType.King, PieceType.Bishop,
|
||||||
|
|
@ -71,6 +73,7 @@ public class Board {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cleanBoard() {
|
public void cleanBoard() {
|
||||||
|
// removes all pieces from the board, readying it to add pieces for a new game
|
||||||
// Iterate over each row and column and set the board position to null
|
// Iterate over each row and column and set the board position to null
|
||||||
for (int y = 0; y < line; y++) {
|
for (int y = 0; y < line; y++) {
|
||||||
for (int x = 0; x < col; x++) {
|
for (int x = 0; x < col; x++) {
|
||||||
|
|
@ -81,15 +84,40 @@ public class Board {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
//TODO
|
// Returns a string representation of the board's current state
|
||||||
return "";
|
StringBuilder boardString = new StringBuilder(); // To construct the string representation
|
||||||
|
|
||||||
|
// Iterate through each row and column to build the string
|
||||||
|
for (int row = 0; row < line; row++) {
|
||||||
|
for (int col = 0; col < this.col; col++) {
|
||||||
|
Piece piece = board[row][col];
|
||||||
|
if (piece != null) {
|
||||||
|
boardString.append(piece.getType().getSummary()); // append the piece symbol
|
||||||
|
} else {
|
||||||
|
boardString.append("."); // the dot symbolizes empty space
|
||||||
|
}
|
||||||
|
if (col < this.col - 1) {
|
||||||
|
boardString.append(" "); // add space between columns
|
||||||
|
}
|
||||||
|
}
|
||||||
|
boardString.append("\n"); // new line after each row
|
||||||
|
}
|
||||||
|
|
||||||
|
return boardString.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<Piece> getPieces() {
|
public ArrayList<Piece> getPieces() {
|
||||||
ArrayList<Piece> pieces = new ArrayList<>();
|
ArrayList<Piece> pieces = new ArrayList<>();
|
||||||
//TODO
|
// Iterate through the 2D array to gather all non-null pieces
|
||||||
|
for (int y = 0; y < line; y++) {
|
||||||
return pieces;
|
for (int x = 0; x < col; x++) {
|
||||||
|
Piece piece = board[y][x];
|
||||||
|
if (piece != null) {
|
||||||
|
pieces.add(piece); // Add the piece to the list if it's not null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return pieces; // return the list or array of pieces
|
||||||
}
|
}
|
||||||
|
|
||||||
public void userTouch(int x, int y) {
|
public void userTouch(int x, int y) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue