added captures, movement, legalmoves hover, and basics of game

This commit is contained in:
CT
2026-05-07 20:32:42 -05:00
parent a70b84f991
commit 7a1844c06a
10 changed files with 100 additions and 9 deletions

View File

@@ -26,6 +26,28 @@ public class Board {
board = new Piece[8][8];
}
public void capture(Piece capturing, Piece captured) {
board[capturing.pos.x][capturing.pos.y] = null;
board[captured.pos.x][captured.pos.y] = capturing;
capturing.pos.x = captured.pos.x;
capturing.pos.y = captured.pos.y;
}
public void move(Piece p, Position posi) {
board[p.pos.x][p.pos.y] = null;
board[posi.x][posi.y] = p;
p.pos = posi;
if (p instanceof Pawn) {
((Pawn) p).hasMoved = true;
}
if (p instanceof King) {
((King) p).hasMoved = true;
}
if (p instanceof Rook) {
((Rook) p).hasMoved = true;
}
}
public void draw(Graphics g) {
for (Piece[] row : board) {
for (Piece p : row) {
@@ -43,11 +65,17 @@ public class Board {
}
public Piece getPiece(Position pos) {
return this.board[pos.x][pos.y];
if (inBounds(pos)) {
return this.board[pos.x][pos.y];
}
return null;
}
public Piece getPiece(int x, int y) {
return this.board[x][y];
if (inBounds(new Position(x, y))) {
return this.board[x][y];
}
return null;
}
public void setPiece(int x, int y, Piece p) {