Created
June 15, 2023 20:45
-
-
Save Filmaluco/46aeb3bce81a12ca9b66095f7f198871 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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