Ejemplo n.º 1
0
 /**
  * Set's given row's block array's blocks null. And moves all blocks with smaller y-coordinate in
  * the table one step down.
  *
  * @param i the rownumber to destroy
  * @param table The Table whose row is to be destroyed.
  */
 public void destroyRow(int i, Table table) {
   Block[][] blocks = table.getBlocks();
   for (int j = 0; j < table.getWidth(); j++) {
     blocks[j][i] = null;
   }
   for (int j = i; j >= 0; j--) {
     for (int k = 0; k < table.getWidth(); k++) {
       if (blocks[k][j] != null) {
         blocks[k][j].moveDown();
         blocks[k][j + 1] = table.getBlocks()[k][j];
         blocks[k][j] = null;
       }
     }
   }
 }
Ejemplo n.º 2
0
 /**
  * Searches every row in Tables block array with no null values, and adds it's row-index to a
  * list.
  *
  * @param levelManager The LevelManager, whose destroyedRows is updated after collecting the
  *     correct rows.
  * @param table The Table whose rows are effected.
  * @return The list of indexes of rows with no null block -values.
  */
 public ArrayList<Integer> searchFullRows(LevelManager levelManager, Table table) {
   ArrayList<Integer> rowsToDestroy = new ArrayList<>();
   int piecesInRow = 0;
   for (int i = 0; i < table.getHeight(); i++) {
     for (int j = 0; j < table.getWidth(); j++) {
       if (table.getBlocks()[j][i] != null) {
         piecesInRow++;
       }
     }
     if (piecesInRow == table.getWidth()) {
       rowsToDestroy.add(i);
       levelManager.increaseRowsDestroyed();
     }
     piecesInRow = 0;
   }
   return rowsToDestroy;
 }