private List<Point> initializeBoardCells() { List<Point> result = new ArrayList<Point>(); for (int x = 1; x < size.getValue() - 1; x++) { for (int y = 1; y < size.getValue() - 1; y++) { result.add(new PointImpl(x, y)); } } return result; }
@Override public void newGame() { validate(); isFlag = new LinkedList<Point>(); walkAt = new HashMap<Point, Integer>(); printer = new Printer(this.getSize(), new MinesweeperPrinter(this)); useDetector = false; maxScore = 0; score = 0; cells = initializeBoardCells(); sapper = initializeSapper(); sapper.iWantToHaveMineDetectorWithChargeNumber(detectorCharge.getValue()); mines = minesGenerator.get(minesCount.getValue(), this); removedMines = new LinkedList<Point>(); tick(); }
@Override public void tick() { if (currentSize != size.getValue()) { // TODO потестить это currentSize = size.getValue(); newGame(); return; } if (nextStep == null) { return; } if (useDetector) { useMineDetectorToGivenDirection(nextStep); useDetector = false; } else { sapperMoveTo(nextStep); } nextStep = null; }
@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 int getSize() { return size.getValue(); }
private void validate() { if (size.getValue() < 5) { size.update(5); } while (minesCount.getValue() > ((size.getValue() - 1) * (size.getValue() - 1) - 1)) { minesCount.update(minesCount.getValue() / 2); } if (detectorCharge.getValue() < minesCount.getValue()) { detectorCharge.update(minesCount.getValue()); } }