Updated version

This commit is contained in:
keshi 2025-04-10 11:37:52 +02:00
parent 3fe2c6f3b6
commit 550f987f8b
3 changed files with 63 additions and 11 deletions

View File

@ -1,3 +1,5 @@
import java.util.ArrayList;
import backend.Board;
import backend.Move;
import backend.Piece;
@ -10,10 +12,24 @@ public class Main {
public static void main(String[] args) {
// testing :
//testing the board
Board testBoard = new Board(8, 8);
testBoard.populateBoard();
System.out.println(testBoard.getWidth());
System.out.println(testBoard.getHeight());
System.out.println(testBoard.toString());
//testing the pieces coordinates, colour and type
Piece testPiece= new Piece(1,2, PieceType.Rook, false);
System.out.println(testPiece.getX());
System.out.println(testPiece.getY());
System.out.println(testPiece.getType());
System.out.println(testPiece.isWhite());
//getting the pieces on the board
System.out.println(testBoard.getPieces());
// launches graphical interface :
MyInterface mjf = new MyInterface();
mjf.setVisible(true);

View File

@ -3,19 +3,24 @@ package backend;
import java.util.ArrayList;
public class Board {
private int width;
private int height;
private Piece[][] board;//creating an array for the coordinates of the board
public Board(int colNum, int lineNum) {
//TODO
this.width=colNum;
this.height=lineNum;
this.board= new Piece[width][height];
}
public int getWidth() {
//TODO
return 0;
return width;
}
public int getHeight() {
//TODO
return 0;
return height;
}
public int getTurnNumber() {
@ -33,9 +38,23 @@ public class Board {
}
public void populateBoard() {
//TODO
PieceType[] values= PieceType.values();
//Pawn, Rook, Knight, Bishop, Queen, King
PieceType[] backRowPieces= {values[1], values[2], values[3], values[4], values[5], values[3], values[2], values[1]};
//row 2 and 7 using only pawns
for(int x=0; x<8; x++) {
board[x][1]= new Piece(x,1,values[0], false);
board[x][6]= new Piece(x,6,values[0], true);
}
//row 1 and 8 using other pieces
for(int x=0; x<8; x++ ) {
board[x][0]= new Piece(x, 0, backRowPieces[x], false);
board[x][7]= new Piece(x, 7, backRowPieces[x], true);
}
}
public void cleanBoard() {
//TODO
}
@ -47,8 +66,13 @@ public class Board {
public ArrayList<Piece> getPieces() {
ArrayList<Piece> pieces = new ArrayList<>();
//TODO
for(int y=0; y<8; y++) {
for(int x=0; x<8; x++) {
if(board[x][y] != null) {
pieces.add(board[x][y]);
}
}
}
return pieces;
}
@ -97,3 +121,4 @@ public class Board {
}
}

View File

@ -1,21 +1,32 @@
package backend;
public class Piece {
private int x_coor;
private int y_coor;
private PieceType piece;
private boolean white;
public Piece(int x, int y, PieceType laPiece, boolean isWhite) {
this.x_coor=x;
this.y_coor=y;
this.piece=laPiece;
this.white=isWhite;
}
public int getX() {
return 0;
return x_coor;
}
public int getY() {
return 0;
return y_coor;
}
public PieceType getType() {
return null;
return piece;
}
public boolean isWhite() {
return false;
return white;
}
}