Advertisement
klasscho

Untitled

Jun 9th, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. private boolean move(int row, int col, int horizontalDirection, int verticalDirection, Direction dir) {
  2. boolean canMove = false;
  3. Tile current = board[row][col];
  4. if (current == null) {
  5. return false;
  6. } else {
  7. boolean move = true;
  8. int newCol = col;
  9. int newRow = row;
  10.  
  11. while(move) {
  12. newCol += horizontalDirection;
  13. newRow += verticalDirection;
  14. if (this.checkOutBounds(dir, newRow, newCol)) {
  15. break;
  16. }
  17.  
  18. if (board[newRow][newCol] == null) {
  19. board[newRow][newCol] = current;
  20. board[newRow - verticalDirection][newCol - horizontalDirection] = null;
  21. board[newRow][newCol].setSlideTo(new Point(newRow, newCol));
  22. canMove = true;
  23. } else if (board[newRow][newCol].getValue() == current.getValue() && board[newRow][newCol].canCombine()) {
  24. board[newRow][newCol].setCanCombine(false);
  25. board[newRow][newCol].setValue(board[newRow][newCol].getValue() * 2);
  26. canMove = true;
  27. board[newRow - verticalDirection][newCol - horizontalDirection] = null;
  28. board[newRow][newCol].setSlideTo(new Point(newRow, newCol));
  29. board[newRow][newCol].setCombineAnimation(true);
  30. score += board[newRow][newCol].getValue();
  31. } else {
  32. move = false;
  33. }
  34. }
  35.  
  36. return canMove;
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement