javafx - game not updating changes to scene?

时间:2015-04-24 21:35:03

标签: java user-interface javafx

I am making a Minesweeper clone, I am trying to create a new Board class when the user clicks on a mine thereby replacing the current board, but nothing happens when I create a new Board(). I tried to search online and the closest thing I can find is this How can I externally update a JavaFX scene?. I don't really understand the top answer and I need some guidance on a couple things;

  • First (and the original question), how do I replace the losing game over Board with a new Board? Board class line 90
  • Second (but relevant), is the way I'm creating this game even good design wise? I don't really know if I am following MVP or if I'm just barfing out code and trying to make something of the mess.

Here is my Minesweeper clone on GitHub Gist.

EDIT: On user request, added some code snippets.

The main start method;

public void start(Stage primaryStage) {
    primaryStage.setTitle("Minesweeper");
    Control admin = new Control();
    Scene sc = new Scene(admin.board);
    primaryStage.setScene(sc);
    primaryStage.sizeToScene();
    primaryStage.setResizable(false);
    primaryStage.show();
}

Where I create a new Board() in the Board class;

void display(Tile tile) {
    String display = String.valueOf(tile.surMineNum);
    if (tile.isMine) {
        // HERE IS WHERE I CREATE A NEW BOARD()
        admin.board = new Board(admin);
        display = "M";
    }
    else if (tile.surMineNum < 1)
        display = "";
    tile.setText(display);
    tile.setSelected(true);
}

0 个答案:

没有答案