@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); } } }
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; }
@Override public boolean isMine(Point pt) { if (getMines() == null) return false; return getMines().contains(pt) || (isGameOver() && removedMines.contains(pt)); }
@Override public boolean isFlag(Point pt) { return isFlag.contains(pt); }
private boolean isSapperCanMoveToDirection(Direction direction) { Point cell = getCellPossiblePosition(direction); return cells.contains(cell); }