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 colNum;
|
||||||
private int lineNum;
|
private int lineNum;
|
||||||
private ArrayList<Piece> pieces = new ArrayList<>();
|
private ArrayList<Piece> pieces = new ArrayList<>();
|
||||||
|
private int x = -1;
|
||||||
|
private int y = -1;
|
||||||
|
|
||||||
public Board(int colNum, int lineNum) {
|
public Board(int colNum, int lineNum) {
|
||||||
this.colNum = colNum;
|
this.colNum = colNum;
|
||||||
|
|
@ -90,14 +92,46 @@ public class Board {
|
||||||
return pieces;
|
return pieces;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void userTouch(int x, int y) {
|
public void userTouch(int x, int y) { //NOT WORKING
|
||||||
//TODO
|
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) {
|
public boolean isSelected(int x, int y) {
|
||||||
//TODO
|
boolean selection = false;
|
||||||
return false;
|
if ((this.x == x) && (this.y == y)){
|
||||||
|
selection = true;
|
||||||
|
}
|
||||||
|
return selection;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* saving-loading feature :*/
|
/* saving-loading feature :*/
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,14 @@ public class Piece {
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setX(int x) {
|
||||||
|
this.x = x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setY(int y) {
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
|
|
||||||
public PieceType getType() {
|
public PieceType getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue