如何在JavaFx

时间:2018-06-25 16:09:07

标签: java javafx othello

@FXML AnchorPane gamePane;

public void gameStart() {
    if(!Started) {
        board = new Board();
        stones = new Circle[8][8];
        newTurn();
        applyBoard();
        Started = true;
    }
    else {
        DestroyBoard(); // <--- Erase all the stones 
        board = new Board();
        stones = new Circle[8][8];
        newTurn();
        applyBoard();
    }
}

public void applyBoard() { 
    for(int i = 0; i < board.boardsize; i++) {
        for(int j = 0; j < board.boardsize; j++) {
            if(board.board[i][j] != board.EMPTY) {
                if(board.board[i][j] == board.BLACK) {
                    stones[i][j] = new Circle(155 + 90 * j, 85 + 90 * i, 40);
                    stones[i][j].setFill(Color.BLACK);
                    gamePane.getChildren().add(stones[i][j]);
                }
                else if(board.board[i][j] == board.WHITE) {
                    stones[i][j] = new Circle(155 + 90 * j, 85 + 90 * i, 40);
                    stones[i][j].setFill(Color.WHITE);
                    gamePane.getChildren().add(stones[i][j]);
                }
            }
        }
    }
}
public void DestroyBoard() { // <---Test Function and not worked!!
    gamePane.getChildren().remove(stones[3][3]);
}

我试图确定是否再次按下开始按钮,然后擦除板上的所有宝石并开始新游戏。第一步,我尝试擦除一块基本的石头,但不能删除板上的任何石头。我该怎么解决?

1 个答案:

答案 0 :(得分:3)

结石存储在ObservableList容器内的gamePane中,您可以使用getChildren()方法进行访问。该列表具有非常有用的clear()方法,该方法可以删除列表中的所有项目。

因此,如果您只是想从gamePane中移除所有宝石,只需调用此方法:

gamePane.getChildren().clear();