end lab 1

This commit is contained in:
MSI-AB\antoineB 2025-04-18 17:20:00 +02:00
parent 5fafd75e4f
commit 440a02ecd4
2 changed files with 72 additions and 26 deletions

View File

@ -10,12 +10,19 @@ public class Board {
private int turnNumber; private int turnNumber;
private boolean turnWhite; private boolean turnWhite;
public Board(int colNum, int lineNum) { /*public Board(int colNum, int lineNum) {
this.width = colNum; this.width = colNum;
this.height = lineNum; this.height = lineNum;
this.pieces = new ArrayList<>(); 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() { public int getWidth() {
return width; return width;
@ -27,25 +34,53 @@ public class Board {
} }
public int getTurnNumber() { public int getTurnNumber() {
//TODO
return this.turnNumber; return this.turnNumber;
} }
public boolean isTurnWhite() { public boolean isTurnWhite() {
//TODO
return this.turnWhite; return this.turnWhite;
} }
public void setPiece(boolean isWhite, PieceType type, int x, int y) { public void setPiece(boolean isWhite, PieceType type, int x, int y) {
//TODO pieces.add(new Piece(isWhite, type, x, y));
} }
public void populateBoard() { 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() { public void cleanBoard() {
//TODO //TODO
pieces.clear();
} }
public String toString() { public String toString() {
@ -54,10 +89,7 @@ public class Board {
} }
public ArrayList<Piece> getPieces() { public ArrayList<Piece> getPieces() {
ArrayList<Piece> pieces = new ArrayList<>(); return pieces; // this refers to the instance variable
//TODO
return pieces;
} }
public void userTouch(int x, int y) { public void userTouch(int x, int y) {

View File

@ -1,21 +1,35 @@
package backend; package backend;
public class Piece { public class Piece {
private boolean isWhite;
private PieceType type;
private int x;
private int y;
public int getX() { // Constructor
return 0; 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() { // Accessors
return 0; public int getX() {
} return x;
}
public PieceType getType() { public int getY() {
return null; return y;
} }
public PieceType getType() {
return type;
}
public boolean isWhite() {
return isWhite;
}
}
public boolean isWhite() {
return false;
}
}