예제 #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 Grid removeTetro() {
   if (tetromino != null) {
     tetromino.representation = new boolean[1][1];
     tetromino.representation[0][0] = false;
   }
   return this;
 }
예제 #3
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;
  }
예제 #4
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;
 }
예제 #5
0
 private double landingHeight() {
   return tetromino.getHeightPosition() + tetromino.getHeigt() / 2;
 }
예제 #6
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));
 }
예제 #7
0
 /** Tourne le tetromino dans le sens hiraire inverse */
 public void turnCounterClockwise() {
   tetromino.turnCounterClockwise(this);
 }