usertouch V1
This commit is contained in:
parent
8e85a12068
commit
4225e0c586
|
|
@ -119,10 +119,27 @@ public class Board {
|
|||
}
|
||||
|
||||
public void userTouch(int x, int y) {
|
||||
//TODO
|
||||
|
||||
}
|
||||
if (x < 0 || x >= width || y < 0 || y >= height) return;
|
||||
|
||||
if (selectedX == -1) { // No selection yet
|
||||
if (board[x][y] != null) {
|
||||
selectedX = x;
|
||||
selectedY = y;
|
||||
}
|
||||
} else { // Already selected
|
||||
if (x == selectedX && y == selectedY) { // Unselect
|
||||
selectedX = -1;
|
||||
selectedY = -1;
|
||||
} else { // Move piece
|
||||
board[x][y] = board[selectedX][selectedY];
|
||||
board[selectedX][selectedY] = null;
|
||||
turn++; // Increment turn
|
||||
selectedX = -1;
|
||||
selectedY = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSelected(int x, int y) {
|
||||
return x == selectedX && y == selectedY;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue