movement added
This commit is contained in:
parent
59431ad622
commit
416a9c2ed7
|
|
@ -6,7 +6,11 @@ public class Board {
|
|||
public int width;
|
||||
public int height;
|
||||
public ArrayList<ArrayList<Piece>> board = new ArrayList<>();
|
||||
private int selectPosition = 0;
|
||||
public boolean select = false;
|
||||
public int xm;
|
||||
public int ym;
|
||||
public int turnNumber;
|
||||
public boolean turnColor;
|
||||
public Board(int colNum, int lineNum) {
|
||||
this.width = colNum;
|
||||
this.height = lineNum;
|
||||
|
|
@ -19,6 +23,8 @@ public class Board {
|
|||
}
|
||||
this.board.add(row);
|
||||
}
|
||||
this.turnNumber = 0;
|
||||
this.turnColor = true;
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -31,13 +37,11 @@ public class Board {
|
|||
}
|
||||
|
||||
public int getTurnNumber() {
|
||||
//TODO
|
||||
return 0;
|
||||
return this.turnNumber;
|
||||
}
|
||||
|
||||
public boolean isTurnWhite() {
|
||||
//TODO
|
||||
return false;
|
||||
return this.turnColor;
|
||||
}
|
||||
|
||||
public void setPiece(int x, int y, PieceType type, boolean isWhite) {
|
||||
|
|
@ -76,7 +80,16 @@ public class Board {
|
|||
}
|
||||
|
||||
public void cleanBoard() {
|
||||
//TODO
|
||||
int rows = 8;
|
||||
int cols = 8;
|
||||
for (int i = 0; i < rows; i++) {
|
||||
ArrayList<Piece> row = new ArrayList<>();
|
||||
for (int j = 0; j < cols; j++) {
|
||||
row.add(null); // Fill with null
|
||||
}
|
||||
this.board.add(row);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -97,24 +110,37 @@ public class Board {
|
|||
}
|
||||
|
||||
public Piece getPiece(int x, int y) {
|
||||
return board.get(x).get(y);
|
||||
return board.get(y).get(x);
|
||||
}
|
||||
|
||||
public void movePiece(int x, int y) {
|
||||
Piece pieceToMove = this.board.get(this.ym).get(this.xm);
|
||||
this.setPiece(x,y,pieceToMove.getType(),pieceToMove.isWhite());
|
||||
board.get(this.ym).set(this.xm,null);
|
||||
}
|
||||
|
||||
public void userTouch(int x, int y) {
|
||||
Piece pieceToMove = new Piece();
|
||||
while (this.selectPosition < 2) {
|
||||
if (this.selectPosition == 0) {
|
||||
pieceToMove = this.getPiece(y,x);
|
||||
} else if (this.selectPosition == 1) {
|
||||
this.setPiece(x, y, pieceToMove.getType(), pieceToMove.isWhite());
|
||||
if (this.select == false && board.get(y).get(x) != null) {
|
||||
this.xm = x;
|
||||
this.ym = y;
|
||||
select = true;
|
||||
}
|
||||
else if (select == true && this.xm != x || this.ym != y){
|
||||
this.movePiece(x, y);
|
||||
select = false;
|
||||
this.turnNumber += 1;
|
||||
// System.out.println(this.toString()); // Debug
|
||||
this.turnColor = !this.turnColor;
|
||||
} else {
|
||||
select = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean isSelected(int x, int y) {
|
||||
//TODO
|
||||
return false;
|
||||
boolean S;
|
||||
if (this.xm == x && this.ym == y) {S = true;}
|
||||
else {S = false;}
|
||||
return S;
|
||||
}
|
||||
|
||||
/* saving-loading feature :*/
|
||||
|
|
|
|||
|
|
@ -5,8 +5,7 @@ public class Piece {
|
|||
public int y;
|
||||
public PieceType type;
|
||||
public boolean isWhite;
|
||||
public Piece() {
|
||||
}
|
||||
|
||||
public Piece(int x, int y, PieceType type, boolean isWhite) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
|
|
|||
Loading…
Reference in New Issue