Piece : setters added
Board : isSelected (ok ?) + UserTouch (not working)
This commit is contained in:
parent
c25bf93f74
commit
1b2c24f007
|
|
@ -6,6 +6,8 @@ public class Board {
|
|||
private int colNum;
|
||||
private int lineNum;
|
||||
private ArrayList<Piece> pieces = new ArrayList<>();
|
||||
private int x = -1;
|
||||
private int y = -1;
|
||||
|
||||
public Board(int colNum, int lineNum) {
|
||||
this.colNum = colNum;
|
||||
|
|
@ -90,14 +92,46 @@ public class Board {
|
|||
return pieces;
|
||||
}
|
||||
|
||||
public void userTouch(int x, int y) {
|
||||
//TODO
|
||||
public void userTouch(int x, int y) { //NOT WORKING
|
||||
int sizePieces = pieces.size();
|
||||
boolean positionOccupied = false;
|
||||
for(int j = 1;j <= sizePieces; j++) {
|
||||
if ((x == pieces.get(j).getX()) && (y == pieces.get(j).getY())){
|
||||
positionOccupied = true;
|
||||
}
|
||||
}
|
||||
if ((this.x == -1 ) && (positionOccupied == true)){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
else {
|
||||
if((this.x == x) && (this.y == y)) {
|
||||
this.x = -1;
|
||||
this.y = -1;
|
||||
}
|
||||
else {
|
||||
boolean foundPiece = false;
|
||||
int k = 1;
|
||||
while (foundPiece == false ) {
|
||||
if ((this.x == pieces.get(k).getX()) && (this.y == pieces.get(k).getY())){
|
||||
foundPiece = true;
|
||||
pieces.get(k).setX(x);
|
||||
pieces.get(k).setY(y);
|
||||
}
|
||||
k += 1;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean isSelected(int x, int y) {
|
||||
//TODO
|
||||
return false;
|
||||
boolean selection = false;
|
||||
if ((this.x == x) && (this.y == y)){
|
||||
selection = true;
|
||||
}
|
||||
return selection;
|
||||
}
|
||||
|
||||
/* saving-loading feature :*/
|
||||
|
|
|
|||
|
|
@ -20,6 +20,14 @@ public class Piece {
|
|||
return y;
|
||||
}
|
||||
|
||||
public void setX(int x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public void setY(int y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public PieceType getType() {
|
||||
return type;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue