Browse Source

add gameOver screen

main^2
fdai7736 11 months ago
parent
commit
dd3b6d8f58
  1. 7
      src/main/java/de/hsfulda/onses/controllers/GameController.java
  2. 40
      src/main/java/de/hsfulda/onses/controllers/GameOverController.java
  3. 3
      src/main/java/de/hsfulda/onses/models/Game.java
  4. 22
      src/main/resources/de/hsfulda/onses/views/gameOver.fxml

7
src/main/java/de/hsfulda/onses/controllers/GameController.java

@ -21,6 +21,7 @@ public class GameController implements Controller {
private final App app; private final App app;
private PropertyChangeListener lastPlayedCardPropertyChangeListener; private PropertyChangeListener lastPlayedCardPropertyChangeListener;
private PropertyChangeListener gameOverListener;
private final ArrayList<Controller> controllers = new ArrayList<>(); private final ArrayList<Controller> controllers = new ArrayList<>();
public GameController(App app, GameService gameService) { public GameController(App app, GameService gameService) {
@ -59,6 +60,11 @@ public class GameController implements Controller {
}; };
game.listeners().addPropertyChangeListener(Game.PROPERTY_LAST_PLAYED_CARD, lastPlayedCardPropertyChangeListener); 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 -> { exitGameButton.setOnAction(e -> {
app.show(new AppController(app, new GameService())); app.show(new AppController(app, new GameService()));
}); });
@ -96,5 +102,6 @@ public class GameController implements Controller {
controller.destroy(); controller.destroy();
} }
game.listeners().removePropertyChangeListener(Game.PROPERTY_LAST_PLAYED_CARD, lastPlayedCardPropertyChangeListener); game.listeners().removePropertyChangeListener(Game.PROPERTY_LAST_PLAYED_CARD, lastPlayedCardPropertyChangeListener);
game.listeners().removePropertyChangeListener(Game.PROPERTY_GAME_OVER, gameOverListener);
} }
} }

40
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;
}
}

3
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_LAST_PLAYED_CARD = "lastPlayedCard";
public final static String PROPERTY_DRAW_CARD_DECK = "drawCardDeck"; public final static String PROPERTY_DRAW_CARD_DECK = "drawCardDeck";
public final static String PROPERTY_GAME_OVER = "gameOver";
protected PropertyChangeSupport listeners; protected PropertyChangeSupport listeners;
@ -70,7 +71,9 @@ public class Game {
} }
public void setGameOver(boolean gameOver) { public void setGameOver(boolean gameOver) {
final boolean oldValue = gameOver;
this.gameOver = gameOver; this.gameOver = gameOver;
this.firePropertyChange(PROPERTY_GAME_OVER, oldValue, gameOver);
} }
public boolean getGameOver() { public boolean getGameOver() {

22
src/main/resources/de/hsfulda/onses/views/gameOver.fxml

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
<AnchorPane prefHeight="690.0" prefWidth="1254.0" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Label layoutX="504.0" layoutY="158.0" text="Game Over" AnchorPane.leftAnchor="504.0" AnchorPane.topAnchor="158.0">
<font>
<Font size="43.0" />
</font>
</Label>
<Button fx:id="newGameBtn" layoutX="569.0" layoutY="329.0" mnemonicParsing="false" text="New Game" AnchorPane.leftAnchor="569.0" AnchorPane.topAnchor="329.0">
<font>
<Font size="17.0" />
</font>
</Button>
</children>
</AnchorPane>
Loading…
Cancel
Save