Exemplo n.º 1
0
 /**
  * Rotates the tile if necessary
  *
  * @param tileToRotate the tile to rotate
  */
 private void rotateTile(BoardTileModel tileToRotate) throws GridPositionOutOfBoundsException {
   GridModel.GridPosition gridPosition = tileToRotate.getNextGridPosition();
   while (cannotPlaceTileAtPosition(gridPosition)) {
     tileToRotate.rotate();
     gridPosition = tileToRotate.getNextGridPosition();
   }
 }
Exemplo n.º 2
0
 private boolean cannotPlaceTileAtPosition(GridModel.GridPosition gridPosition) {
   BoardTileModel tileAtPosition;
   try {
     tileAtPosition = gridModel.get(gridPosition);
     if (tileAtPosition instanceof StartTileModel
         || tileAtPosition instanceof EndTileModel
         || tileAtPosition.isFull()) {
       return true;
     }
     if (!(tileAtPosition instanceof EmptyTileModel)) {
       MessagingCenter.getInstance().postGameEventMessage(GameConfig.GameEvent.TILE_DESTROYED);
     }
     return false;
   } catch (GridPositionOutOfBoundsException e) {
     return true;
   }
 }
Exemplo n.º 3
0
  public Optional<BoardTileModel> fillNextTileModel(GridModel.GridPosition gridPosition) {
    BoardTileModel boardTileModel, nextTileModel;
    Optional<BoardTileModel> boardTileModelOptional = Optional.absent();
    try {
      boardTileModel = gridModel.get(gridPosition);
      boardTileModel.setFilling(false);
      boardTileModel.setFull();
      GridModel.GridPosition nextGridPosition = boardTileModel.getNextGridPosition();
      nextTileModel = gridModel.get(nextGridPosition);
      nextTileModel.setFillable(gridPosition.subtract(nextGridPosition));
      boardTileModelOptional = Optional.of(nextTileModel);

    } catch (GridPositionOutOfBoundsException | NullPointerException e) {
      e.printStackTrace();
    }
    return boardTileModelOptional;
  }