diff --git a/src/main/java/de/hsfulda/onses/controllers/GameController.java b/src/main/java/de/hsfulda/onses/controllers/GameController.java index 3eccd0c..e9146bc 100644 --- a/src/main/java/de/hsfulda/onses/controllers/GameController.java +++ b/src/main/java/de/hsfulda/onses/controllers/GameController.java @@ -21,6 +21,7 @@ public class GameController implements Controller { private final App app; private PropertyChangeListener lastPlayedCardPropertyChangeListener; + private PropertyChangeListener gameOverListener; private final ArrayList controllers = new ArrayList<>(); public GameController(App app, GameService gameService) { @@ -59,6 +60,11 @@ public class GameController implements Controller { }; game.listeners().addPropertyChangeListener(Game.PROPERTY_LAST_PLAYED_CARD, lastPlayedCardPropertyChangeListener); + gameOverListener = e -> { + app.show(new GameOverController(app)); + }; + game.listeners().addPropertyChangeListener(Game.PROPERTY_GAME_OVER, gameOverListener); + exitGameButton.setOnAction(e -> { app.show(new AppController(app, new GameService())); }); @@ -96,5 +102,6 @@ public class GameController implements Controller { controller.destroy(); } game.listeners().removePropertyChangeListener(Game.PROPERTY_LAST_PLAYED_CARD, lastPlayedCardPropertyChangeListener); + game.listeners().removePropertyChangeListener(Game.PROPERTY_GAME_OVER, gameOverListener); } } diff --git a/src/main/java/de/hsfulda/onses/controllers/GameOverController.java b/src/main/java/de/hsfulda/onses/controllers/GameOverController.java new file mode 100644 index 0000000..5aaf6f9 --- /dev/null +++ b/src/main/java/de/hsfulda/onses/controllers/GameOverController.java @@ -0,0 +1,40 @@ +package de.hsfulda.onses.controllers; + +import de.hsfulda.onses.App; +import de.hsfulda.onses.Main; +import de.hsfulda.onses.services.GameService; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.control.Button; + +import java.io.IOException; +import java.util.Objects; + +public class GameOverController implements Controller { + + private final App app; + + public GameOverController(App app) { + this.app = app; + } + @Override + public Parent render() throws IOException { + final Parent parent = FXMLLoader.load(Objects.requireNonNull(Main.class.getResource("views/gameOver.fxml"))); + final Button newGameButton = (Button) parent.lookup("#newGameBtn"); + + newGameButton.setOnAction(e -> { + app.show(new GameController(app, new GameService())); + }); + return parent; + } + + @Override + public void destroy() { + + } + + @Override + public String getTitle() { + return null; + } +} diff --git a/src/main/java/de/hsfulda/onses/models/Game.java b/src/main/java/de/hsfulda/onses/models/Game.java index 6a9c67a..1b14ddd 100644 --- a/src/main/java/de/hsfulda/onses/models/Game.java +++ b/src/main/java/de/hsfulda/onses/models/Game.java @@ -10,6 +10,7 @@ public class Game { public final static String PROPERTY_LAST_PLAYED_CARD = "lastPlayedCard"; public final static String PROPERTY_DRAW_CARD_DECK = "drawCardDeck"; + public final static String PROPERTY_GAME_OVER = "gameOver"; protected PropertyChangeSupport listeners; @@ -70,7 +71,9 @@ public class Game { } public void setGameOver(boolean gameOver) { + final boolean oldValue = gameOver; this.gameOver = gameOver; + this.firePropertyChange(PROPERTY_GAME_OVER, oldValue, gameOver); } public boolean getGameOver() { diff --git a/src/main/resources/de/hsfulda/onses/views/gameOver.fxml b/src/main/resources/de/hsfulda/onses/views/gameOver.fxml new file mode 100644 index 0000000..9c3b6d7 --- /dev/null +++ b/src/main/resources/de/hsfulda/onses/views/gameOver.fxml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + +