Skip to content

Instantly share code, notes, and snippets.

@Filmaluco
Created June 15, 2023 20:45
Show Gist options
  • Save Filmaluco/46aeb3bce81a12ca9b66095f7f198871 to your computer and use it in GitHub Desktop.
Save Filmaluco/46aeb3bce81a12ca9b66095f7f198871 to your computer and use it in GitHub Desktop.
package pt.isec.pa.pong.ui;
import javafx.application.Platform;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import pt.isec.pa.pong.model.Game;
class CommandsViewModel {
Game game;
BooleanProperty btStart, bdPause, bdResume;
CommandsViewModel(Game game) {
this.game = game;
btStart = new SimpleBooleanProperty(false);
bdPause = new SimpleBooleanProperty(false);
bdResume = new SimpleBooleanProperty(false);
game.addListener(Game.PROP_GAME, evt -> Platform.runLater(() -> {
btStart.set(game.isGameActive());
bdPause.set(!game.isGameActive() || game.isGamePaused());
bdResume.set(!game.isGameActive() || !game.isGamePaused());
}));
}
public void start() {
game.initGame();
}
public void pause() {
game.pauseGame();
}
public void resume() {
game.resumeGame();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment