diff --git a/src/backend/Board.java b/src/backend/Board.java index 4fb4e4d..304b537 100644 --- a/src/backend/Board.java +++ b/src/backend/Board.java @@ -10,12 +10,19 @@ public class Board { private int turnNumber; private boolean turnWhite; - public Board(int colNum, int lineNum) { + /*public Board(int colNum, int lineNum) { this.width = colNum; this.height = lineNum; this.pieces = new ArrayList<>(); } - + */ + public Board(int colNum, int lineNum) { + this.width = colNum; + this.height = lineNum; + this.pieces = new ArrayList<>(); + this.turnNumber = 0; + this.turnWhite = true; // White starts first in chess + } public int getWidth() { return width; @@ -27,25 +34,53 @@ public class Board { } public int getTurnNumber() { - //TODO + return this.turnNumber; } public boolean isTurnWhite() { - //TODO + return this.turnWhite; } public void setPiece(boolean isWhite, PieceType type, int x, int y) { - //TODO + pieces.add(new Piece(isWhite, type, x, y)); } public void populateBoard() { - //TODO + cleanBoard(); // make sure it's empty first + + // Place white pawns + for (int x = 0; x < 8; x++) { + setPiece(true, PieceType.Pawn, x, 1); + } + + // Place black pawns + for (int x = 0; x < 8; x++) { + setPiece(false, PieceType.Pawn, x, 6); + } + + // Back rows (R, N, B, Q, K, B, N, R) + PieceType[] backRow = { + PieceType.Rook, PieceType.Knight, PieceType.Bishop, PieceType.Queen, + PieceType.King, PieceType.Bishop, PieceType.Knight, PieceType.Rook + }; + + // White back row + for (int x = 0; x < 8; x++) { + setPiece(true, backRow[x], x, 0); + } + + // Black back row + for (int x = 0; x < 8; x++) { + setPiece(false, backRow[x], x, 7); + } } + public void cleanBoard() { //TODO + pieces.clear(); } public String toString() { @@ -54,10 +89,7 @@ public class Board { } public ArrayList getPieces() { - ArrayList pieces = new ArrayList<>(); - //TODO - - return pieces; + return pieces; // this refers to the instance variable } public void userTouch(int x, int y) { diff --git a/src/backend/Piece.java b/src/backend/Piece.java index ffa88bb..ad6360f 100644 --- a/src/backend/Piece.java +++ b/src/backend/Piece.java @@ -1,21 +1,35 @@ package backend; public class Piece { + private boolean isWhite; + private PieceType type; + private int x; + private int y; - public int getX() { - return 0; - } + // Constructor + public Piece(boolean isWhite, PieceType type, int x, int y) { + this.isWhite = isWhite; + this.type = type; + this.x = x; + this.y = y; + } - public int getY() { - return 0; - } - - public PieceType getType() { - return null; - } - - public boolean isWhite() { - return false; - } - -} + // Accessors + public int getX() { + return x; + } + + public int getY() { + return y; + } + + public PieceType getType() { + return type; + } + + public boolean isWhite() { + return isWhite; + } + } + +