to stringggg
This commit is contained in:
parent
93251fd76a
commit
a05d192a18
|
|
@ -32,7 +32,7 @@ public class Board {
|
|||
|
||||
public void setPiece(boolean isWhite, PieceType type, int x, int y) {
|
||||
if (x >= 0 && x < width && y >= 0 && y < height) {
|
||||
board[x][y] = new Piece(isWhite, type, x, y);
|
||||
board[x][y] = new Piece(x, y, isWhite, type);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -72,8 +72,30 @@ public class Board {
|
|||
}
|
||||
|
||||
public String toString() {
|
||||
return "board";
|
||||
}
|
||||
StringBuilder stringboard= new StringBuilder();
|
||||
for (int row = height - 1; row >= 0; row--) {
|
||||
|
||||
for (int column = 0; column < width; column++) {
|
||||
Piece piece = board[row][column];
|
||||
if (piece == null) {
|
||||
stringboard.append(". ");
|
||||
} else {
|
||||
char sym = piece.getType().name().charAt(0);
|
||||
stringboard.append(piece.isWhite() ? sym : Character.toLowerCase(sym))
|
||||
.append(' ');
|
||||
}
|
||||
}
|
||||
stringboard.append("\n");
|
||||
}
|
||||
stringboard.append(" ");
|
||||
for (int x = 0; x < width; x++) {
|
||||
stringboard.append((char)('a' + x)).append(' ');
|
||||
}
|
||||
stringboard.append("\n");
|
||||
stringboard.append("Turn: ").append(isTurnWhite() ? "White" : "Black");
|
||||
return stringboard.toString();
|
||||
}
|
||||
|
||||
|
||||
public ArrayList<Piece> getPieces() {
|
||||
ArrayList<Piece> pieces = new ArrayList<>();
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ public class Piece {
|
|||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue