Changes until setPiece()
This commit is contained in:
parent
10cd42b2c9
commit
690ee4f1dc
|
|
@ -1,10 +1,6 @@
|
||||||
import backend.Board;
|
import backend.Board;
|
||||||
import backend.Move;
|
|
||||||
import backend.Piece;
|
|
||||||
import backend.PieceType;
|
|
||||||
import windowInterface.MyInterface;
|
import windowInterface.MyInterface;
|
||||||
|
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -13,6 +9,7 @@ public class Main {
|
||||||
Board testBoard = new Board(8, 8);
|
Board testBoard = new Board(8, 8);
|
||||||
testBoard.populateBoard();
|
testBoard.populateBoard();
|
||||||
System.out.println(testBoard.toString());
|
System.out.println(testBoard.toString());
|
||||||
|
System.out.println(testBoard.getWidth() + "*" + testBoard.getHeight());
|
||||||
|
|
||||||
// launches graphical interface :
|
// launches graphical interface :
|
||||||
MyInterface mjf = new MyInterface();
|
MyInterface mjf = new MyInterface();
|
||||||
|
|
|
||||||
|
|
@ -4,51 +4,109 @@ import java.util.ArrayList;
|
||||||
|
|
||||||
public class Board {
|
public class Board {
|
||||||
|
|
||||||
public Board(int colNum, int lineNum) {
|
private int colNum;
|
||||||
|
private int lineNum;
|
||||||
|
private Piece[][] board;
|
||||||
|
private int turnNumber = 0;
|
||||||
|
private boolean isWhiteTurn = true;
|
||||||
|
|
||||||
|
public Board(int colNum, int lineNum) {
|
||||||
|
this.colNum = colNum;
|
||||||
|
this.lineNum = lineNum;
|
||||||
|
this.board = new Piece[lineNum][colNum];
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getWidth() {
|
public int getWidth() {
|
||||||
//TODO
|
return colNum;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getHeight() {
|
public int getHeight() {
|
||||||
//TODO
|
return lineNum;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getTurnNumber() {
|
public int getTurnNumber() {
|
||||||
//TODO
|
return turnNumber;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isTurnWhite() {
|
public boolean isTurnWhite() {
|
||||||
//TODO
|
return isWhiteTurn;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPiece(boolean isWhite, PieceType type, int x, int y) {
|
public void setPiece(boolean isWhite, PieceType type, int x, int y) {
|
||||||
//TODO
|
board[y][x] = new Piece(x,y,type, isWhite);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void populateBoard() {
|
public void populateBoard() {
|
||||||
//TODO
|
cleanBoard(); // Start with an empty board
|
||||||
|
|
||||||
|
// Pawns
|
||||||
|
for (int x = 0; x < getWidth(); x++) {
|
||||||
|
setPiece(false, PieceType.Pawn, x, 1); // Black pawns
|
||||||
|
setPiece(true, PieceType.Pawn, x, 6); // White pawns
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rooks
|
||||||
|
setPiece(false, PieceType.Rook, 0, 0);
|
||||||
|
setPiece(false, PieceType.Rook, 7, 0);
|
||||||
|
setPiece(true, PieceType.Rook, 0, 7);
|
||||||
|
setPiece(true, PieceType.Rook, 7, 7);
|
||||||
|
|
||||||
|
// Knights
|
||||||
|
setPiece(false, PieceType.Knight, 1, 0);
|
||||||
|
setPiece(false, PieceType.Knight, 6, 0);
|
||||||
|
setPiece(true, PieceType.Knight, 1, 7);
|
||||||
|
setPiece(true, PieceType.Knight, 6, 7);
|
||||||
|
|
||||||
|
// Bishops
|
||||||
|
setPiece(false, PieceType.Bishop, 2, 0);
|
||||||
|
setPiece(false, PieceType.Bishop, 5, 0);
|
||||||
|
setPiece(true, PieceType.Bishop, 2, 7);
|
||||||
|
setPiece(true, PieceType.Bishop, 5, 7);
|
||||||
|
|
||||||
|
// Queens
|
||||||
|
setPiece(false, PieceType.Queen, 3, 0);
|
||||||
|
setPiece(true, PieceType.Queen, 3, 7);
|
||||||
|
|
||||||
|
// Kings
|
||||||
|
setPiece(false, PieceType.King, 4, 0);
|
||||||
|
setPiece(true, PieceType.King, 4, 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cleanBoard() {
|
public void cleanBoard() {
|
||||||
//TODO
|
for (int y = 0; y < getHeight(); y++) {
|
||||||
|
for (int x = 0; x < getWidth(); x++) {
|
||||||
|
board[y][x] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
//TODO
|
StringBuilder sb = new StringBuilder();
|
||||||
return "";
|
for (int y = 0; y < getHeight(); y++) {
|
||||||
|
for (int x = 0; x < getWidth(); x++) {
|
||||||
|
Piece piece = board[y][x];
|
||||||
|
if (piece == null) {
|
||||||
|
sb.append(". ");
|
||||||
|
} else {
|
||||||
|
String symbol = piece.getType().getSummary();
|
||||||
|
sb.append(piece.isWhite() ? symbol.toUpperCase() : symbol.toLowerCase()).append(" ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sb.append("\n");
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<Piece> getPieces() {
|
public ArrayList<Piece> getPieces() {
|
||||||
ArrayList<Piece> pieces = new ArrayList<>();
|
ArrayList<Piece> pieces = new ArrayList<>();
|
||||||
//TODO
|
for (int y = 0; y < getHeight(); y++) {
|
||||||
|
for (int x = 0; x < getWidth(); x++) {
|
||||||
|
if (board[y][x] != null) {
|
||||||
|
pieces.add(board[y][x]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return pieces;
|
return pieces;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue