Updated version
This commit is contained in:
parent
3fe2c6f3b6
commit
550f987f8b
|
|
@ -1,3 +1,5 @@
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import backend.Board;
|
import backend.Board;
|
||||||
import backend.Move;
|
import backend.Move;
|
||||||
import backend.Piece;
|
import backend.Piece;
|
||||||
|
|
@ -10,10 +12,24 @@ public class Main {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// testing :
|
// testing :
|
||||||
|
//testing the board
|
||||||
Board testBoard = new Board(8, 8);
|
Board testBoard = new Board(8, 8);
|
||||||
testBoard.populateBoard();
|
testBoard.populateBoard();
|
||||||
|
System.out.println(testBoard.getWidth());
|
||||||
|
System.out.println(testBoard.getHeight());
|
||||||
System.out.println(testBoard.toString());
|
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 :
|
// launches graphical interface :
|
||||||
MyInterface mjf = new MyInterface();
|
MyInterface mjf = new MyInterface();
|
||||||
mjf.setVisible(true);
|
mjf.setVisible(true);
|
||||||
|
|
|
||||||
|
|
@ -3,19 +3,24 @@ package backend;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class Board {
|
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) {
|
public Board(int colNum, int lineNum) {
|
||||||
//TODO
|
this.width=colNum;
|
||||||
|
this.height=lineNum;
|
||||||
|
this.board= new Piece[width][height];
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getWidth() {
|
public int getWidth() {
|
||||||
//TODO
|
//TODO
|
||||||
return 0;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getHeight() {
|
public int getHeight() {
|
||||||
//TODO
|
//TODO
|
||||||
return 0;
|
return height;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getTurnNumber() {
|
public int getTurnNumber() {
|
||||||
|
|
@ -33,9 +38,23 @@ public class Board {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void populateBoard() {
|
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() {
|
public void cleanBoard() {
|
||||||
//TODO
|
//TODO
|
||||||
}
|
}
|
||||||
|
|
@ -47,8 +66,13 @@ public class Board {
|
||||||
|
|
||||||
public ArrayList<Piece> getPieces() {
|
public ArrayList<Piece> getPieces() {
|
||||||
ArrayList<Piece> pieces = new ArrayList<>();
|
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;
|
return pieces;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -97,3 +121,4 @@ public class Board {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,32 @@
|
||||||
package backend;
|
package backend;
|
||||||
|
|
||||||
public class Piece {
|
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() {
|
public int getX() {
|
||||||
return 0;
|
return x_coor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getY() {
|
public int getY() {
|
||||||
return 0;
|
return y_coor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PieceType getType() {
|
public PieceType getType() {
|
||||||
return null;
|
return piece;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isWhite() {
|
public boolean isWhite() {
|
||||||
return false;
|
return white;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue