Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private boolean move(int row, int col, int horizontalDirection, int verticalDirection, Direction dir) {
- boolean canMove = false;
- Tile current = board[row][col];
- if (current == null) {
- return false;
- } else {
- boolean move = true;
- int newCol = col;
- int newRow = row;
- while(move) {
- newCol += horizontalDirection;
- newRow += verticalDirection;
- if (this.checkOutBounds(dir, newRow, newCol)) {
- break;
- }
- if (board[newRow][newCol] == null) {
- board[newRow][newCol] = current;
- board[newRow - verticalDirection][newCol - horizontalDirection] = null;
- board[newRow][newCol].setSlideTo(new Point(newRow, newCol));
- canMove = true;
- } else if (board[newRow][newCol].getValue() == current.getValue() && board[newRow][newCol].canCombine()) {
- board[newRow][newCol].setCanCombine(false);
- board[newRow][newCol].setValue(board[newRow][newCol].getValue() * 2);
- canMove = true;
- board[newRow - verticalDirection][newCol - horizontalDirection] = null;
- board[newRow][newCol].setSlideTo(new Point(newRow, newCol));
- board[newRow][newCol].setCombineAnimation(true);
- score += board[newRow][newCol].getValue();
- } else {
- move = false;
- }
- }
- return canMove;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement