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 windowInterface.MyInterface;
|
||||
|
||||
|
||||
public class Main {
|
||||
|
||||
|
||||
|
|
@ -17,6 +16,10 @@ public class Main {
|
|||
// launches graphical interface :
|
||||
MyInterface mjf = new MyInterface();
|
||||
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 {
|
||||
private int line;
|
||||
private int col;
|
||||
private Piece[][] board; // 2D array to hold pieces
|
||||
|
||||
public Board(int colNum, int lineNum) {
|
||||
this.col=colNum;
|
||||
this.line=lineNum;
|
||||
this.board =new Piece [colNum][lineNum];// Create the 2D board array
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
|
|
@ -30,39 +32,76 @@ public class Board {
|
|||
}
|
||||
|
||||
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() {
|
||||
//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() {
|
||||
//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() {
|
||||
//TODO
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
public ArrayList<Piece> getPieces() {
|
||||
ArrayList<Piece> pieces = new ArrayList<>();
|
||||
//TODO
|
||||
|
||||
|
||||
return pieces;
|
||||
}
|
||||
|
||||
public void userTouch(int x, int y) {
|
||||
//TODO
|
||||
|
||||
|
||||
}
|
||||
|
||||
public boolean isSelected(int x, int y) {
|
||||
//TODO
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/* saving-loading feature :*/
|
||||
|
||||
public String[] toFileRep() {
|
||||
|
|
@ -74,7 +113,7 @@ public class Board {
|
|||
//TODO
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* The following methods require more work ! */
|
||||
|
||||
public boolean isHighlighted(int x, int y) {
|
||||
|
|
@ -84,14 +123,14 @@ public class Board {
|
|||
|
||||
public void undoLastMove() {
|
||||
//TODO
|
||||
|
||||
|
||||
}
|
||||
|
||||
public Board(Board board) {
|
||||
//TODO
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void playMove(Move move) {
|
||||
//TODO
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ package backend;
|
|||
public class Piece {
|
||||
private int X;
|
||||
private int Y;
|
||||
private PieceType type;
|
||||
private boolean color;
|
||||
|
||||
public int getX() {
|
||||
return this.X;
|
||||
|
|
@ -13,11 +15,19 @@ public class Piece {
|
|||
}
|
||||
|
||||
public PieceType getType() {
|
||||
return null;
|
||||
return this.type ;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// 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