36 lines
757 B
Java
36 lines
757 B
Java
import java.awt.*;
|
|
|
|
public class Board {
|
|
Piece[][] board;
|
|
|
|
public Board() {
|
|
board = new Piece[8][8];
|
|
for (int i = 0; i <= 7; i++) {
|
|
board[i][1] = new Pawn(i, 1, "Black");
|
|
}
|
|
for (int i = 0; i <= 7; i++) {
|
|
board[i][6] = new Pawn(i, 6, "White");
|
|
}
|
|
}
|
|
|
|
public void draw(Graphics g) {
|
|
for (Piece[] row : board) {
|
|
for (Piece p : row) {
|
|
if (p != null) p.draw(g);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static boolean inBounds(Position pos) {
|
|
return (pos.x >= 0 && pos.x <= 7) && (pos.y >= 0 && pos.y <= 7);
|
|
}
|
|
|
|
public boolean isOpen(Position pos) {
|
|
return this.getPiece(pos) == null;
|
|
}
|
|
|
|
public Piece getPiece(Position pos) {
|
|
return this.board[pos.x][pos.y];
|
|
}
|
|
}
|