change board to cells
This commit is contained in:
@@ -3,70 +3,65 @@ package chess.model;
|
|||||||
import chess.model.pieces.*;
|
import chess.model.pieces.*;
|
||||||
|
|
||||||
public class Board {
|
public class Board {
|
||||||
private final Cell[][] board;
|
private final Cell[][] cells;
|
||||||
private static final int WHITE = 0;
|
private static final int WHITE = 0;
|
||||||
private static final int BLACK = 1;
|
private static final int BLACK = 1;
|
||||||
|
|
||||||
public Board(int size){
|
public Board(int size) {
|
||||||
board = new Cell[size][size];
|
cells = new Cell[size][size];
|
||||||
for (int y = 0; y < size; y++) {
|
for (int y = 0; y < size; y++) {
|
||||||
for (int x = 0; x < size; x++) {
|
for (int x = 0; x < size; x++) {
|
||||||
board[y][x] = new Cell();
|
cells[y][x] = new Cell();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setPieces();
|
setPieces();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Board(){
|
public Board() {
|
||||||
this(8);
|
this(8);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Cell getCell(Coordinates coordinates){
|
public Cell getCell(Coordinates coordinates) {
|
||||||
return board[coordinates.getX()][coordinates.getY()];
|
return cells[coordinates.getX()][coordinates.getY()];
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSize(){
|
public int getSize() {
|
||||||
return board.length;
|
return cells.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPieces() throws Error {
|
public void setPieces() throws Error {
|
||||||
if (this.getSize() == 8) {
|
if (this.getSize() == 8) {
|
||||||
setPiecesSize8();
|
setPiecesSize8();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
throw new Error("Oops. This isn't implemented yet.");
|
throw new Error("Oops. This isn't implemented yet.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPiecesSize8(){
|
public void setPiecesSize8() {
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
board[i][1].setPiece(new Pawn(BLACK, this, board[i][1]));
|
cells[i][1].setPiece(new Pawn(BLACK, this, cells[i][1]));
|
||||||
board[i][6].setPiece(new Pawn(WHITE, this, board[i][6]));
|
cells[i][6].setPiece(new Pawn(WHITE, this, cells[i][6]));
|
||||||
if (i==0 || i==7) {
|
|
||||||
board[i][0].setPiece(new Rook(BLACK, this, board[i][0]));
|
|
||||||
board[i][7].setPiece(new Rook(WHITE, this, board[i][7]));
|
|
||||||
}
|
|
||||||
if (i==1 || i==6) {
|
|
||||||
board[i][0].setPiece(new Knight(BLACK, this, board[i][0]));
|
|
||||||
board[i][7].setPiece(new Knight(WHITE, this, board[i][7]));
|
|
||||||
}
|
|
||||||
if (i==2 || i==5) {
|
|
||||||
board[i][0].setPiece(new Bishop(BLACK, this, board[i][0]));
|
|
||||||
board[i][7].setPiece(new Bishop(WHITE, this, board[i][7]));
|
|
||||||
}
|
|
||||||
if (i==3) {
|
|
||||||
board[i][0].setPiece(new Queen(BLACK, this, board[i][0]));
|
|
||||||
board[i][7].setPiece(new Queen(WHITE, this, board[i][7]));
|
|
||||||
}
|
|
||||||
if (i==4) {
|
|
||||||
board[i][0].setPiece(new King(BLACK, this, board[i][0]));
|
|
||||||
board[i][7].setPiece(new King(WHITE, this, board[i][7]));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i <= 7; i += 7) {
|
||||||
|
cells[i][0].setPiece(new Rook(BLACK, this, cells[i][0]));
|
||||||
|
cells[i][7].setPiece(new Rook(WHITE, this, cells[i][7]));
|
||||||
|
}
|
||||||
|
for (int i = 1; i <= 6; i += 5) {
|
||||||
|
cells[i][0].setPiece(new Knight(BLACK, this, cells[i][0]));
|
||||||
|
cells[i][7].setPiece(new Knight(WHITE, this, cells[i][7]));
|
||||||
|
}
|
||||||
|
for (int i = 2; i <= 5; i += 3) {
|
||||||
|
cells[i][0].setPiece(new Bishop(BLACK, this, cells[i][0]));
|
||||||
|
cells[i][7].setPiece(new Bishop(WHITE, this, cells[i][7]));
|
||||||
|
}
|
||||||
|
cells[3][0].setPiece(new Queen(BLACK, this, cells[3][0]));
|
||||||
|
cells[3][7].setPiece(new Queen(WHITE, this, cells[3][7]));
|
||||||
|
cells[4][0].setPiece(new King(BLACK, this, cells[4][0]));
|
||||||
|
cells[4][7].setPiece(new King(WHITE, this, cells[4][7]));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Piece getPiece(Coordinates coordinates){
|
public Piece getPiece(Coordinates coordinates) {
|
||||||
return getCell(coordinates).getPiece();
|
return getCell(coordinates).getPiece();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,8 +73,9 @@ public class Board {
|
|||||||
movingPiece.setPosition(arrivalCell);
|
movingPiece.setPosition(arrivalCell);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Cell getRelativePosition(Coordinates coordinates, MovePattern mp){
|
public Cell getRelativePosition(Coordinates coordinates) {
|
||||||
// todo
|
// todo
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user