change String color into boolean isWhite
This commit is contained in:
parent
83d9d29225
commit
3768cf24de
|
|
@ -14,7 +14,7 @@ public class Main {
|
|||
testBoard.populateBoard();
|
||||
System.out.println(testBoard.toString());
|
||||
|
||||
Piece testPiece = new Piece(1,2,"black",PieceType.Pawn);
|
||||
Piece testPiece = new Piece(1,2,false,PieceType.Pawn);
|
||||
System.out.println(testPiece.getType());
|
||||
System.out.println(testPiece.getX());
|
||||
System.out.println(testPiece.getY());
|
||||
|
|
@ -24,7 +24,7 @@ public class Main {
|
|||
// launches graphical interface :
|
||||
MyInterface mjf = new MyInterface();
|
||||
mjf.setVisible(true);
|
||||
//test push
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,11 +5,13 @@ import java.util.ArrayList;
|
|||
public class Board {
|
||||
private int colNum;
|
||||
private int lineNum;
|
||||
private int turnNumber;
|
||||
private boolean isWhiteTurn;
|
||||
ArrayList<Piece> pieces = new ArrayList<>();
|
||||
|
||||
public Board(int colNum, int lineNum) {
|
||||
this.colNum=colNum;
|
||||
this.lineNum=lineNum;
|
||||
this.lineNum=lineNum;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
|
|
@ -21,17 +23,16 @@ public class Board {
|
|||
}
|
||||
|
||||
public int getTurnNumber() {
|
||||
//TODO
|
||||
return 0;
|
||||
return this.turnNumber;
|
||||
}
|
||||
|
||||
public boolean isTurnWhite() {
|
||||
//TODO
|
||||
return false;
|
||||
return this.isWhiteTurn;
|
||||
}
|
||||
|
||||
public void setPiece(boolean isWhite, PieceType type, int x, int y) {
|
||||
//TODO
|
||||
Piece newPiece = new Piece(x, y, isWhite, type);
|
||||
pieces.add(newPiece);
|
||||
}
|
||||
|
||||
public void populateBoard() {
|
||||
|
|
@ -39,66 +40,72 @@ public class Board {
|
|||
for(int x=0;x<8;x++) {
|
||||
if(x==0||x==7) {
|
||||
if (y==0) {
|
||||
pieces.add(new Piece(x,y,"black", PieceType.Rook));
|
||||
pieces.add(new Piece(x,y,false, PieceType.Rook));
|
||||
}
|
||||
if (y==7) {
|
||||
pieces.add(new Piece(x,y,"white", PieceType.Rook));
|
||||
pieces.add(new Piece(x,y,true, PieceType.Rook));
|
||||
}
|
||||
}
|
||||
if(x==1||x==6) {
|
||||
if (y==0) {
|
||||
pieces.add(new Piece(x,y,"black", PieceType.Knight));
|
||||
pieces.add(new Piece(x,y,false, PieceType.Knight));
|
||||
}
|
||||
if (y==7) {
|
||||
pieces.add(new Piece(x,y,"white", PieceType.Knight));
|
||||
pieces.add(new Piece(x,y,true, PieceType.Knight));
|
||||
}
|
||||
}
|
||||
if(x==2||x==5) {
|
||||
if (y==0) {
|
||||
pieces.add(new Piece(x,y,"black", PieceType.Bishop));
|
||||
pieces.add(new Piece(x,y,false, PieceType.Bishop));
|
||||
}
|
||||
if (y==7) {
|
||||
pieces.add(new Piece(x,y,"white", PieceType.Bishop));
|
||||
pieces.add(new Piece(x,y,true, PieceType.Bishop));
|
||||
}
|
||||
}
|
||||
if(x==3) {
|
||||
if (y==0) {
|
||||
pieces.add(new Piece(x,y,"black", PieceType.Queen));
|
||||
pieces.add(new Piece(x,y,false, PieceType.Queen));
|
||||
}
|
||||
if (y==7) {
|
||||
pieces.add(new Piece(x,y,"white", PieceType.Queen));
|
||||
pieces.add(new Piece(x,y,true, PieceType.Queen));
|
||||
}
|
||||
}
|
||||
if(x==4) {
|
||||
if (y==0) {
|
||||
pieces.add(new Piece(x,y,"black", PieceType.King));
|
||||
pieces.add(new Piece(x,y,false, PieceType.King));
|
||||
}
|
||||
if (y==7) {
|
||||
pieces.add(new Piece(x,y,"white", PieceType.King));
|
||||
pieces.add(new Piece(x,y,true, PieceType.King));
|
||||
}
|
||||
}
|
||||
if(y==1) {
|
||||
pieces.add(new Piece(x,y,"black", PieceType.Pawn));
|
||||
pieces.add(new Piece(x,y,false, PieceType.Pawn));
|
||||
}
|
||||
if(y==6) {
|
||||
pieces.add(new Piece(x,y,"white", PieceType.Pawn));
|
||||
pieces.add(new Piece(x,y,true, PieceType.Pawn));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void cleanBoard() {
|
||||
//TODO
|
||||
pieces.clear();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
//TODO
|
||||
return "";
|
||||
String result = "Turn: " + turnNumber + "\n";
|
||||
result += "Current Player: " + (isWhiteTurn ? "White" : "Black") + "\n";
|
||||
result += "Pieces on Board:\n";
|
||||
|
||||
for (Piece piece : pieces) {
|
||||
result += piece + "\n";
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public ArrayList<Piece> getPieces() {
|
||||
ArrayList<Piece> pieces = new ArrayList<>();
|
||||
|
||||
return pieces;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,31 +3,31 @@ package backend;
|
|||
public class Piece {
|
||||
private int x;
|
||||
private int y;
|
||||
private String color;
|
||||
private boolean isWhite;
|
||||
private PieceType type;
|
||||
|
||||
|
||||
public Piece(int x, int y, String color, PieceType type) {
|
||||
public Piece(int x, int y, boolean isWhite, PieceType type) {
|
||||
this.x=x;
|
||||
this.y=y;
|
||||
this.color=color;
|
||||
this.isWhite=isWhite;
|
||||
this.type=type;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
return this.x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
return this.y;
|
||||
}
|
||||
|
||||
public PieceType getType() {
|
||||
return type;
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public boolean isWhite() {
|
||||
return (color=="white");
|
||||
return this.isWhite;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue