Add TODO Knight class, make Piece abstract
This commit is contained in:
parent
1f578b0770
commit
45f7544151
3 changed files with 20 additions and 14 deletions
|
@ -40,11 +40,10 @@ public class Board {
|
|||
board = new Piece[BOARD_SIZE][BOARD_SIZE];
|
||||
|
||||
// Initialize pieces
|
||||
for (int y = 0; y < 2; y++)
|
||||
for (int x = 0; x < BOARD_SIZE; x++) {
|
||||
set(x, y, new Piece(true));
|
||||
set(x, y + BOARD_SIZE - 2, new Piece(false));
|
||||
}
|
||||
set(1, 0, new Knight(true));
|
||||
set(6, 0, new Knight(true));
|
||||
set(1, 7, new Knight(false));
|
||||
set(6, 7, new Knight(false));
|
||||
}
|
||||
|
||||
public boolean outOfBounds(int x, int y) {
|
||||
|
|
14
src/Knight.java
Normal file
14
src/Knight.java
Normal file
|
@ -0,0 +1,14 @@
|
|||
import java.util.ArrayList;
|
||||
|
||||
public class Knight extends Piece {
|
||||
public Knight(boolean black) {
|
||||
super(black);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<BoardCoordinate> getPossibleMoves(BoardCoordinate position) {
|
||||
ArrayList<BoardCoordinate> possibleMoves = new ArrayList<>();
|
||||
possibleMoves.add(new BoardCoordinate(position.x, position.y - 1)); // to up
|
||||
return possibleMoves;
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Piece {
|
||||
public abstract class Piece {
|
||||
// Width and height of placeholder rectangle graphic
|
||||
public static final int DIMENSION = 32;
|
||||
public boolean black;
|
||||
|
@ -13,14 +13,7 @@ public class Piece {
|
|||
this.black = black;
|
||||
}
|
||||
|
||||
public ArrayList<BoardCoordinate> getPossibleMoves(BoardCoordinate position) {
|
||||
ArrayList<BoardCoordinate> possibleMoves = new ArrayList<>();
|
||||
possibleMoves.add(new BoardCoordinate(position.x - 1, position.y)); // to left
|
||||
possibleMoves.add(new BoardCoordinate(position.x + 1, position.y)); // to right
|
||||
possibleMoves.add(new BoardCoordinate(position.x, position.y - 1)); // to up
|
||||
possibleMoves.add(new BoardCoordinate(position.x, position.y + 1)); // to down
|
||||
return possibleMoves;
|
||||
}
|
||||
public abstract ArrayList<BoardCoordinate> getPossibleMoves(BoardCoordinate position);
|
||||
|
||||
public ArrayList<BoardCoordinate> getLegalMoves(BoardCoordinate position, Board board) {
|
||||
ArrayList<BoardCoordinate> legalMoves = getPossibleMoves(position);
|
||||
|
|
Reference in a new issue