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 List<Point> getFreeCells() { List<Point> result = new LinkedList<Point>(); for (Point cell : getCells()) { boolean isSapper = cell.equals(getSapper()); boolean isBoard = cell.getX() == 0 || cell.getY() == 0 || cell.getX() == size.getValue() - 1 || cell.getY() == size.getValue() - 1; // TODO test me boolean isMine = isMine(cell); if (!isSapper && !isMine && !isBoard) { result.add(cell); } } return result; }
@Override public boolean isSapper(Point pt) { return pt.equals(getSapper()); }