Skip to content

Instantly share code, notes, and snippets.

@ansisec
Last active May 30, 2023 14:19
Show Gist options
  • Save ansisec/793048801974e3b0264fb5ab885ab638 to your computer and use it in GitHub Desktop.
Save ansisec/793048801974e3b0264fb5ab885ab638 to your computer and use it in GitHub Desktop.
Ficheiro auxiliar para criação da lista com histórico
package pt.isec.pa.gamebw.model.data;
public record History(int nrWBwon, int nrWBout, int nrBBout, int bet, Type type) {
public enum Type {BET, BETWON, BETLOST, LOSE, REMOVE, OTHER}
}
// Informação parcial
public class ShowInfoUI extends BorderPane {
...
VBox list;
...
private void createViews() {
...
TilePane titlePane = getLine(
450,
"WBalls won",
"WBalls out",
"BBalls out",
"Action"
);
titlePane.setStyle("-fx-background-color: #c0c0c0;");
list = new VBox();
ScrollPane scrollPane = new ScrollPane(list);
scrollPane.setStyle("-fx-background-color: white");
scrollPane.setPrefHeight(200);
VBox listWithTitle = new VBox(titlePane,scrollPane);
listWithTitle.setBorder(new Border(new BorderStroke(Color.DARKGRAY,BorderStrokeStyle.SOLID,
CornerRadii.EMPTY,new BorderWidths(2))));
VBox vBox = new VBox( ... , listWithTitle);
vBox.setFillWidth(false);
vBox.setSpacing(10);
vBox.setAlignment(Pos.CENTER);
setAlignment(vBox,Pos.CENTER);
this.setCenter(vBox);
}
...
private void update() {
...
List<History> history = gameBWManager.getHistory();
list.getChildren().clear();
for (int i = 0; i < history.size(); i++) {
int bet = history.get(i).bet();
String type = switch (history.get(i).type()) {
case LOSE -> "Lose W";
case REMOVE -> "Two Balls";
case BET -> "Bet " + bet;
case BETLOST -> "Lost";
case BETWON -> "Won";
default -> "--";
};
TilePane tilePane = getLine(
450,
""+history.get(i).nrWBwon(),
""+history.get(i).nrWBout(),
""+history.get(i).nrBBout(),
type
);
list.getChildren().add(tilePane);
}
}
private TilePane getLine(double width, String... strings) {
TilePane tilePane = new TilePane();
for (int i = 0; i <strings.length; i++) {
Label label = new Label(strings[i]);
tilePane.getChildren().add(label);
}
tilePane.setPrefWidth(width);
tilePane.setPrefTileWidth(width/strings.length);
return tilePane;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment