Пример #1
0
 public boolean moveDown() {
   for (Cell cell : tetromino.getCells(this)) {
     if (isOccupied(cell.getCol(), cell.getRow() + 1)) return false;
   }
   tetromino.fall();
   return true;
 }
Пример #2
0
  public String toString() {
    String str = "\n";
    for (int row = 0; row < HEIGHT; row++) {
      str += "|";
      for (int col = 0; col < WIDTH; col++) {
        if (getCell(row, col).isOccupied()) str += " X ";
        else if (tetromino != null && tetromino.getCells(this).contains(getCell(row, col)))
          str += " O ";
        else str += " . ";
      }
      str += "|\n";
      if (row == HEIGHT - 1) str += "\\______________________________/";
    }

    return str;
  }
Пример #3
0
 /** Déplace le tetromino vers la droite */
 public boolean moveRight() {
   for (Cell cell : tetromino.getCells(this))
     if (isOccupied(cell.getCol() + 1, cell.getRow())) return false;
   tetromino.moveRight();
   return true;
 }
Пример #4
0
 /**
  * Test si la case situ�e � la colonne col , ligne row est occup�
  *
  * @param col
  * @param row
  * @return true si la case est hors du jeu
  */
 private boolean occupied(int col, int row) {
   if (col < 0 || row < 0 || col >= WIDTH || row >= HEIGHT) return true;
   return board[col][row].isOccupied() || tetromino.getCells(this).contains(getCell(row, col));
 }