示例#1
0
  public void importFrom(InputStream stream) throws IOException {
    // 1. wipe the view
    boardView.reset();

    // 2. instantiate new model and load new data
    board = new Board();
    board.loadFrom(stream);
    board.calculateAllHints();

    // 3. redraw view
    updateEntireView();

    // 4. setup controller
    boardView.setOnKeyPressed(this);
    boardView.requestFocus();

    // 5. reset timer
    timer.reset();
  }
示例#2
0
  private void checkGameIsSolved() {
    if (board.isSolved() == false) {
      return;
    }

    // clear UNDO stack
    steps.clear();

    // stop the timer
    pauseTimer();

    // stop showing combination list
    combinationView.update(new Group(Group.NON_ID));

    // prevent user input
    boardView.setOnKeyPressed(null);

    // congratulate user
    boardView.congratulate();

    // pop up alert
    AlertFactory.createInfo("SUCCESS", null, "Congratulation! You are genius!").showAndWait();
  }
示例#3
-1
  public GameController() {
    logger.debug("Instantiating model");
    board = new Board();

    logger.debug("Instantiating views");
    boardView = new BoardView(Block.COUNT);

    // instantiate click event handler only one time to save instantiation time
    EventHandler<MouseEvent> onCellViewClicked =
        new EventHandler<MouseEvent>() {
          @Override
          public void handle(MouseEvent event) {
            boardView.requestFocus();
            CellView cellView = (CellView) event.getSource();
            moveFocusTo(cellView.row, cellView.col);
          }
        };

    // apply click event handler to all cells
    board.forEach(cell -> boardView.getCellView(cell).setOnMouseClicked(onCellViewClicked));

    // apply key press handler to the board (not each individual cell)
    boardView.setOnKeyPressed(this);

    // instantiate timer
    timer = new TimerWidget();

    // init check box for toggling hint mode
    hintMode = new CheckBox("Pencil (SHIFT)");
    hintMode.setFocusTraversable(false);
    autoMode = new CheckBox("Automation");
    autoMode.setFocusTraversable(false);
    autoMode.setSelected(true);
    remainMode = new CheckBox("Show remaining sum");
    remainMode.setFocusTraversable(false);
    remainMode.setSelected(true);

    // listener for hint mode and remain mode
    hintMode
        .selectedProperty()
        .addListener(
            new ChangeListener<Boolean>() {
              @Override
              public void changed(
                  ObservableValue<? extends Boolean> observable,
                  Boolean oldValue,
                  Boolean newValue) {
                if (newValue) {
                  boardView.setHintsCursor();
                } else {
                  boardView.setValueCursor();
                }
              }
            });

    remainMode
        .selectedProperty()
        .addListener(
            new ChangeListener<Boolean>() {
              @Override
              public void changed(
                  ObservableValue<? extends Boolean> observable,
                  Boolean oldValue,
                  Boolean newValue) {
                toggleGroupSumMode(newValue);
              }
            });

    VBox controlBox = new VBox(hintMode, autoMode, remainMode);
    controlBox.setPadding(new Insets(0, 10, 0, 50));
    controlBox.setSpacing(4);

    // init combination list view
    combinationView = new CombinationView();

    // init combinator view
    combinator = new CombinatorWidget();

    // organize all components in grid style
    view = new GridPane();
    view.setBackground(BackgroundFactory.create(Color.rgb(200, 230, 200)));
    view.add(boardView, 0, 0);
    controlPanel = new VBox(timer, controlBox, combinationView, combinator);
    controlPanel.setAlignment(Pos.TOP_CENTER);
    view.add(controlPanel, 1, 0);
  }