added captures, movement, legalmoves hover, and basics of game
This commit is contained in:
32
Board.java
32
Board.java
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user