I want to open tiles with the left mouseclick and mark them with the right mouseclick. I read and tried a lot but somehow can't get this working.
private class Tile extends StackPane {
private int x, y;
private boolean hasBomb;
private boolean isOpen = false;
private Rectangle border = new Rectangle(TILE_SIZE - 2, TILE_SIZE - 2);
private Text text = new Text();
public Tile(int x, int y, boolean hasBomb) {
this.x = x;
this.y = y;
this.hasBomb = hasBomb;
border.setStroke(Color.BLACK);
border.setFill(Color.GREY);
text.setFont(Font.font(18));
text.setText(hasBomb ? "X" : "");
text.setVisible(false);
getChildren().addAll(border, text);
setTranslateX(x * TILE_SIZE);
setTranslateY(y * TILE_SIZE);
onMouseClicked: function(e:MouseEvent):Void {
if (e.button == MouseButton.SECONDARY) {
setOnMouseClicked(e -> open());
}
}
}
Could anyonw please help?