Files
chess/Board.java

36 lines
765 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][2] = new Pawn(i + 1, 2, "Black");
}
for (int i = 0; i <= 7; i++) {
board[i][7] = new Pawn(i + 1, 7, "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];
}
}