Esempio n. 1
1
  @Override
  public void useMineDetectorToGivenDirection(Direction direction) {
    final Point result = getCellPossiblePosition(direction);
    if (cells.contains(result)) {
      if (sapper.isEmptyCharge()) {
        return;
      }

      if (isFlag.contains(result)) {
        return;
      }

      sapper.tryToUseDetector(
          new DetectorAction() {
            @Override
            public void used() {
              isFlag.add(result);
              if (getMines().contains(result)) {
                removeMine(result);
              } else {
                fire(MinesweeperEvents.FORGET_CHARGE);
              }
            }
          });

      if (isEmptyDetectorButPresentMines()) {
        openAllBoard();
        fire(MinesweeperEvents.NO_MORE_CHARGE);
      }
    }
  }
Esempio n. 2
0
 private int getMinesNear(Point position) {
   int result = 0;
   for (Direction direction : Direction.values()) {
     Point newPosition = direction.change(position.copy());
     if (cells.contains(newPosition) && getMines().contains(newPosition)) {
       result++;
     }
   }
   return result;
 }
Esempio n. 3
0
 @Override
 public boolean isMine(Point pt) {
   if (getMines() == null) return false;
   return getMines().contains(pt) || (isGameOver() && removedMines.contains(pt));
 }
Esempio n. 4
0
 @Override
 public boolean isFlag(Point pt) {
   return isFlag.contains(pt);
 }
Esempio n. 5
0
 private boolean isSapperCanMoveToDirection(Direction direction) {
   Point cell = getCellPossiblePosition(direction);
   return cells.contains(cell);
 }