Skip to content

Commit

Permalink
added game over
Browse files Browse the repository at this point in the history
  • Loading branch information
Triikk committed Feb 16, 2024
1 parent db9b2a2 commit d677153
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ private void redrawResourcesView() {
*/
private void checkGameOver() {
if (gameManager.isGameOver()) {
// TODO: draw end game
appView.drawEndGame();
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/it/unibo/view/AppView.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ public interface AppView {
* update the log.
*/
void updateLog(String name, String message);

/**
* Draws the end game window.
*/
void drawEndGame();
}
9 changes: 8 additions & 1 deletion src/main/java/it/unibo/view/AppViewImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
* Application.
*/
public final class AppViewImpl implements AppView {
private final Stage stage;
private static final int DEFAULT_HEIGHT = 450;
private final Stage stage;
private final BoardView boardView;
private final BankView bankView;
private final PlayersView playersView;
private final CurrentPlayerView currentPlayerView;
private final Map<String, Color> playerColors = new HashMap<>();
private final LogView logView;
private final EndGameView endGameView;

/**
* Constructor of AppView.
Expand All @@ -44,6 +45,7 @@ public AppViewImpl(final Stage stage, final List<String> players) {
playersView = new PlayersView(controller, playerColors);
currentPlayerView = new CurrentPlayerView(controller);
logView = new LogView();
endGameView = new EndGameView(controller, stage);

}

Expand Down Expand Up @@ -124,4 +126,9 @@ public void redrawPlayers() {
public void updateLog(final String name, final String message) {
logView.update(name, message);
}

@Override
public void drawEndGame() {
endGameView.draw();
}
}
12 changes: 10 additions & 2 deletions src/main/java/it/unibo/view/EndGameView.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,29 @@
* End game view.
*/
public class EndGameView {

private final BorderPane root = new BorderPane();
private final Stage stage;
private final MainController controller;

/**
* Constructor of Menu.
*
* @param stage the stage
*/
public EndGameView(final MainController controller, final Stage stage) {
final BorderPane root = new BorderPane();
this.controller = controller;
this.stage = stage;
}

public void draw() {
final VBox playersBox = new VBox();
controller.getPlayerNames().forEach(playerName -> {
final Label playerLabel = new Label(
playerName + " has " + controller.getPlayerPoints(playerName) + " victory points");
playersBox.getChildren().add(playerLabel);
});
root.setCenter(playersBox);

stage.setTitle("The game ended");
stage.setScene(new Scene(root));
stage.setMaximized(true);
Expand Down

0 comments on commit d677153

Please sign in to comment.