OOP_Groupe1A2_Project/OOP_1A2_Project/src/backend/Board.java

152 lines
3.2 KiB
Java

package backend;
import java.util.ArrayList;
public class Board {
private int width;
private int height;
private int turnNumber;
private boolean isWhiteTurn;
private ArrayList<Piece> pieces;
public Board(int colNum, int lineNum) {
this.width = colNum;
this.height = lineNum;
this.turnNumber = 0;
this.isWhiteTurn = true;
this.pieces = new ArrayList<>();
}
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
public int getTurnNumber() {
return turnNumber;
}
public boolean isTurnWhite() {
return isWhiteTurn;
}
public void setPiece(boolean isWhite, PieceType type, int x, int y) {
for (int i = 0; i < pieces.size(); i++) {
Piece p = pieces.get(i);
if (p.getX() == x && p.getY() == y) {
pieces.remove(i);
break;
}
}
Piece newPiece = new Piece( x, y, type,isWhite);
pieces.add(newPiece);
}
public void populateBoard() {
//TODO
cleanBoard();
PieceType pawn = PieceType.Pawn;
PieceType rook = PieceType.Rook;
PieceType knight = PieceType.Knight;
PieceType bishop = PieceType.Bishop;
PieceType queen = PieceType.Queen;
PieceType king = PieceType.King;
//all the pawns
for (int x=0; x<7; x++) {
pieces.add(new Piece(x, 1, pawn, false));
pieces.add(new Piece(x, 6, pawn, true));
}
//black pieces
pieces.add(new Piece(0, 0, rook, false));
pieces.add(new Piece(1, 0, knight, false));
pieces.add(new Piece(2, 0, bishop, false));
pieces.add(new Piece(3, 0, queen, false));
pieces.add(new Piece(4, 0, king, false));
pieces.add(new Piece(5, 0, bishop, false));
pieces.add(new Piece(6, 0, knight, false));
pieces.add(new Piece(7, 0, rook, false));
//white pieces
pieces.add(new Piece(0, 7, rook, true));
pieces.add(new Piece(1, 7, knight, true));
pieces.add(new Piece(2, 7, bishop, true));
pieces.add(new Piece(3, 7, queen, true));
pieces.add(new Piece(4, 7, king, true));
pieces.add(new Piece(5, 7, bishop, true));
pieces.add(new Piece(6, 7, knight, true));
pieces.add(new Piece(7, 7, rook, true));
}
public void cleanBoard() {
pieces.clear();
}
public String toString() {
//TODO
return "";
}
public ArrayList<Piece> getPieces() {
ArrayList<Piece> result = new ArrayList<>();
for (Piece p : this.pieces) {
result.add(p);
}
return result;
}
public void userTouch(int x, int y) {
//TODO
}
public boolean isSelected(int x, int y) {
//TODO
return false;
}
/* saving-loading feature :*/
public String[] toFileRep() {
//TODO
return null;
}
public Board(String[] array) {
//TODO
}
/* The following methods require more work ! */
public boolean isHighlighted(int x, int y) {
//TODO
return false;
}
public void undoLastMove() {
//TODO
}
public Board(Board board) {
//TODO
}
public void playMove(Move move) {
//TODO
}
}