daily pastebin goal
70%
SHARE
TWEET

Untitled

a guest Dec 18th, 2018 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Heavy extends AbstractFallHandler
  2. {
  3.     public Heavy(final String name) {
  4.     super(name);
  5.     }
  6.  
  7.     public boolean supportExists(Board board, int x, int y) {
  8.     while (y < board.getHeight() + Board.getOutsideMargin()) {
  9.         if (board.getSquareFromBoard(x, y) == SquareType.EMPTY) {
  10.         return false;
  11.         }
  12.         y++;
  13.     }
  14.     return true;
  15.     }
  16.  
  17.     public void pushDown(Board board, int x, int y) {
  18.     int start = y;
  19.     while (start < board.getHeight() + Board.getOutsideMargin()) {
  20.         if (board.getSquareFromBoard(x, start) == SquareType.EMPTY) {
  21.         break;
  22.         }
  23.         start++;
  24.     }
  25.  
  26.     for (int i = start; i > y - 1; i--) {
  27.         board.setSquareAt(x, i, board.getSquareFromBoard(x, i - 1));
  28.     }
  29.     }
  30.  
  31.     public boolean hasCollision(Board board) {
  32.     //Checking if capable of pushing down blocks
  33.     for (int y = 0; y < board.getFalling().getHeight(); y++) {
  34.         for (int x = 0; x < board.getFalling().getWidth(); x++) {
  35.         SquareType fallingSquare = board.getFalling().getSquareAt(x, y);
  36.  
  37.         if (fallingSquare != SquareType.EMPTY) {
  38.             if (board.getSquareFromBoard(board.getFallingX() + x, board.getFallingY() + y) == SquareType.OUTSIDE ||
  39.             supportExists(board, board.getFallingX() + x, board.getFallingY() + y)) {
  40.             return true;
  41.             }
  42.         }
  43.         }
  44.     }
  45.  
  46.     //Pushing down block(s)
  47.     for (int y = 0; y < board.getFalling().getHeight(); y++) {
  48.         for (int x = 0; x < board.getFalling().getWidth(); x++) {
  49.         if (board.getSquareFromBoard(board.getFallingX() + x, board.getFallingY() + y) != SquareType.EMPTY &&
  50.             board.getFalling().getSquareAt(x, y) != SquareType.EMPTY) {
  51.             pushDown(board, board.getFallingX() + x, board.getFallingY() + y);
  52.         }
  53.         }
  54.     }
  55.     return false;
  56.     }
  57. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top