Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
 @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();
 }
Ejemplo n.º 3
0
  @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;
  }
Ejemplo n.º 4
0
 @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;
 }
Ejemplo n.º 5
0
 @Override
 public int getSize() {
   return size.getValue();
 }
Ejemplo n.º 6
0
  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());
    }
  }