Exemple #1
0
  public boolean roomExist(boolean[][] tempCoordinates, Piece p) {
    boolean[][] temp;
    try {
      temp = MatrixBoolean2DUtil.alignedNand(tempCoordinates, p.getPiece_bits(), p.x, p.y);
    } catch (ArrayIndexOutOfBoundsException aie) {
      return false;
    }

    return MatrixBoolean2DUtil.isFullySparseFor(temp, true);
  }
Exemple #2
0
  public void rotateCurrentPiece() {
    Piece imaginary = currentPiece.getRotated();

    boolean[][] tempResult =
        MatrixBoolean2DUtil.alignedNand(
            coordinates, currentPiece.getPiece_bits(), currentPiece.getX(), currentPiece.getY());
    boolean[][] tempCoordinates = MatrixBoolean2DUtil.and(coordinates, tempResult);

    if (roomExist(tempCoordinates, imaginary)) {
      coordinates = tempCoordinates;
      spawn(imaginary);
    }
  }
Exemple #3
0
  public void fall() {
    Piece imaginary =
        new Piece(currentPiece.getX() + 1, currentPiece.getY(), currentPiece.getPiece_bits());
    boolean[][] tempResult =
        MatrixBoolean2DUtil.alignedNand(
            coordinates, currentPiece.getPiece_bits(), currentPiece.getX(), currentPiece.getY());
    boolean[][] tempCoordinates = MatrixBoolean2DUtil.and(coordinates, tempResult);

    if (roomExist(tempCoordinates, imaginary)) {
      coordinates = tempCoordinates;
      spawn(imaginary);
    } else {
      currentPiece.hitsBottom();

      checkForPoints();

      currentPiece = null;
    }
  }
Exemple #4
0
  public boolean spawn(Piece p) {
    currentPiece = p;

    if (roomExist(coordinates, p)) {
      coordinates = MatrixBoolean2DUtil.alignedOr(coordinates, p.getPiece_bits(), p.x, p.y);

      setChanged();
      notifyObservers();
      return true;
    } else {
      showEndGameMessage = true;
      setChanged();
      notifyObservers();
      return false;
    }
  }