no error in methods but pieces do not appear on the board yet
This commit is contained in:
parent
e5a6c33f2b
commit
4c53382718
|
|
@ -4,7 +4,6 @@ import backend.Piece;
|
||||||
import backend.PieceType;
|
import backend.PieceType;
|
||||||
import windowInterface.MyInterface;
|
import windowInterface.MyInterface;
|
||||||
|
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -17,6 +16,10 @@ public class Main {
|
||||||
// launches graphical interface :
|
// launches graphical interface :
|
||||||
MyInterface mjf = new MyInterface();
|
MyInterface mjf = new MyInterface();
|
||||||
mjf.setVisible(true);
|
mjf.setVisible(true);
|
||||||
|
|
||||||
|
Piece test = new Piece(true, PieceType.Pawn, 1, 1);
|
||||||
|
System.out.println(test.isWhite());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,12 @@ import java.util.ArrayList;
|
||||||
public class Board {
|
public class Board {
|
||||||
private int line;
|
private int line;
|
||||||
private int col;
|
private int col;
|
||||||
|
private Piece[][] board; // 2D array to hold pieces
|
||||||
|
|
||||||
public Board(int colNum, int lineNum) {
|
public Board(int colNum, int lineNum) {
|
||||||
this.col=colNum;
|
this.col=colNum;
|
||||||
this.line=lineNum;
|
this.line=lineNum;
|
||||||
|
this.board =new Piece [colNum][lineNum];// Create the 2D board array
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getWidth() {
|
public int getWidth() {
|
||||||
|
|
@ -30,15 +32,52 @@ public class Board {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPiece(boolean isWhite, PieceType type, int x, int y) {
|
public void setPiece(boolean isWhite, PieceType type, int x, int y) {
|
||||||
//TODO
|
//TODO datastructure treeset
|
||||||
|
// Create a new Piece object with the provided attributes
|
||||||
|
Piece piece =new Piece (isWhite, type,x,y);
|
||||||
|
|
||||||
|
// Place the piece on the board at the specified position
|
||||||
|
if (x >= 0 && x < col && y >= 0 && y < line) {
|
||||||
|
board[y][x] = piece;
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
System.out.println("Invalid position");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void populateBoard() {
|
public void populateBoard() {
|
||||||
//TODO
|
PieceType[] backRow = {
|
||||||
|
PieceType.Rook, PieceType.Knight, PieceType.Bishop,
|
||||||
|
PieceType.Queen, PieceType.King, PieceType.Bishop,
|
||||||
|
PieceType.Knight, PieceType.Rook
|
||||||
|
};
|
||||||
|
|
||||||
|
// place black pieces (false = black)
|
||||||
|
for (int x=0;x<8;x++) {
|
||||||
|
// Row 0: black major pieces
|
||||||
|
setPiece(false,backRow[x],x,0);
|
||||||
|
// Row 1: black pawns
|
||||||
|
setPiece(false, PieceType.Pawn,x,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Place white pieces (true = white)
|
||||||
|
for (int x = 0; x < 8; x++) {
|
||||||
|
// Row 6: white pawns
|
||||||
|
setPiece(true, PieceType.Pawn, x, 6);
|
||||||
|
// Row 7: white major pieces
|
||||||
|
setPiece(true, backRow[x], x, 7);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cleanBoard() {
|
public void cleanBoard() {
|
||||||
//TODO
|
// Iterate over each row and column and set the board position to null
|
||||||
|
for (int y = 0; y < line; y++) {
|
||||||
|
for (int x = 0; x < col; x++) {
|
||||||
|
board[y][x] = null; // Remove the piece
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println("Board cleaned. All pieces removed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@ package backend;
|
||||||
public class Piece {
|
public class Piece {
|
||||||
private int X;
|
private int X;
|
||||||
private int Y;
|
private int Y;
|
||||||
|
private PieceType type;
|
||||||
|
private boolean color;
|
||||||
|
|
||||||
public int getX() {
|
public int getX() {
|
||||||
return this.X;
|
return this.X;
|
||||||
|
|
@ -13,11 +15,19 @@ public class Piece {
|
||||||
}
|
}
|
||||||
|
|
||||||
public PieceType getType() {
|
public PieceType getType() {
|
||||||
return null;
|
return this.type ;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isWhite() {
|
public boolean isWhite() {
|
||||||
return false;
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
// constructor
|
||||||
|
public Piece (boolean colorP, PieceType typeP, int xP, int yP) {
|
||||||
|
this.color=colorP;
|
||||||
|
this.type=typeP;
|
||||||
|
this.X=xP;
|
||||||
|
this.Y=yP;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,4 +25,8 @@ public enum PieceType {
|
||||||
return PieceType.Queen;
|
return PieceType.Queen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PieceType type = PieceType.Pawn;
|
||||||
|
// int n = type.ordinal();
|
||||||
|
// gives the value of the enum list index corresponding to called piece
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue