Skip to content

Commit

Permalink
Feat: WIP for generating report after game
Browse files Browse the repository at this point in the history
  • Loading branch information
tommyah committed May 23, 2026
1 parent 72a7a71 commit bfb3228
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 23 deletions.
6 changes: 5 additions & 1 deletion src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ public void start(final Stage stage) throws Exception {
TimeInputsGame timeInputsGame = new TimeInputsGame();

GameEngineView gameEngineView = new GameEngineView();
GameEngineController gameEngineController = new GameEngineController(gameEngineView, eventManager);
GameEngineController gameEngineController = new GameEngineController(
gameEngineView,
eventManager,
stocksInFile.getFirst()
);

MiniGamesView miniGamesView = new MiniGamesView();
new MiniGamesController(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.minigames;

import edu.ntnu.idi.idatt2003.g40.mappe.model.Stock;
import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventManager;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewController;
import javafx.animation.KeyFrame;
Expand All @@ -13,9 +14,12 @@ public final class GameEngineController extends ViewController<GameEngineView> {
private int secondsRemaining = 60;
private GameGimmick activeGimmick;
private Timeline engineLoop;
private Stock chosenStock;

public GameEngineController(final GameEngineView viewElement,
final EventManager eventManager) throws IllegalArgumentException {
final EventManager eventManager,
final Stock chosenStock) throws IllegalArgumentException {
this.chosenStock = chosenStock;
super(viewElement, eventManager);

engineLoop = new Timeline(new KeyFrame(Duration.millis(16.6), e -> {
Expand Down Expand Up @@ -53,6 +57,10 @@ public void launchGimmickSession(final GameGimmick gimmick) {
engineLoop.play();
}

public void setChosenStock(final Stock newStock) {
chosenStock = newStock;
}

private void refreshMetrics() {
int hours = secondsRemaining / 3600;
int minutes = (secondsRemaining % 3600) / 60;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;

import java.util.function.IntConsumer;

Expand All @@ -17,30 +18,16 @@ public final class GameEngineView extends ViewElement<BorderPane, MiniGamesActio
private HBox topDashboardBar;
private int curScore;

private VBox reportContainer;
private Label reportTitleLabel;
private Label rankResultLabel;
private Label stockEffectLabel;
private Button closeReportBtn;

public GameEngineView() {
super(new BorderPane(), MiniGamesActions.class);
}

@Override
protected void initLayout() {
quitButton = new Button("Quit");
quitButton.setPrefSize(100, 50);

scoreLabel = new Label("Score: 0");
timerLabel = new Label("00:00:60");
rankLabel = new Label("Rank: E");

HBox statsDisplay = new HBox(40, scoreLabel, timerLabel, rankLabel);
statsDisplay.setAlignment(Pos.CENTER);

topDashboardBar = new HBox(20, quitButton, statsDisplay);
topDashboardBar.setAlignment(Pos.CENTER_LEFT);
topDashboardBar.setPadding(new javafx.geometry.Insets(15));

getRootPane().setTop(topDashboardBar);
registerButton(MiniGamesActions.INGAME_QUIT, quitButton);
}

/**
* Method for updating the game per tick with score, time and rank.
*
Expand Down Expand Up @@ -68,6 +55,63 @@ public void setGameGimmickContent(final GameGimmick gimmick, final IntConsumer c
gimmick.initialize(consumer);
}

/**
* Displays the report after a minigames timers is finished.
*
* @param rank the rank the player got.
* @param stockSymbol the symbol of the affected stock.
* @param isPositive whether the change is positive or not.
* */
public void showGameReport(final String rank,
final String stockSymbol,
final boolean isPositive) {
getRootPane().setCenter(null);

reportContainer = new VBox(25);
reportContainer.setAlignment(Pos.CENTER);
reportContainer.getStyleClass().add("minigames-report-box");

reportTitleLabel = new Label("GAME OVER - REPORT");
reportTitleLabel.setStyle("-fx-font-size: 32px; -fx-font-weight: bold;");

rankResultLabel = new Label("Final Rank: " + rank);
rankResultLabel.setStyle("-fx-font-size: 24px;");

String effectText = isPositive
? "Performance impact: Positive change for " + stockSymbol + " next week! 📈"
: "Performance impact: Negative change for " + stockSymbol + " next week... 📉";

stockEffectLabel = new Label(effectText);
stockEffectLabel.setStyle("-fx-font-size: 18px; -fx-text-fill: " + (isPositive ? "green;" : "red;"));

closeReportBtn = new Button("Return to Menu");
closeReportBtn.setPrefSize(200, 50);
registerButton(MiniGamesActions.CLOSE_REPORT, closeReportBtn);

reportContainer.getChildren().addAll(reportTitleLabel, rankResultLabel, stockEffectLabel, closeReportBtn);
getRootPane().setCenter(reportContainer);
}

@Override
protected void initLayout() {
quitButton = new Button("Quit");
quitButton.setPrefSize(100, 50);

scoreLabel = new Label("Score: 0");
timerLabel = new Label("00:00:60");
rankLabel = new Label("Rank: E");

HBox statsDisplay = new HBox(40, scoreLabel, timerLabel, rankLabel);
statsDisplay.setAlignment(Pos.CENTER);

topDashboardBar = new HBox(20, quitButton, statsDisplay);
topDashboardBar.setAlignment(Pos.CENTER_LEFT);
topDashboardBar.setPadding(new javafx.geometry.Insets(15));

getRootPane().setTop(topDashboardBar);
registerButton(MiniGamesActions.INGAME_QUIT, quitButton);
}

@Override
protected void initStyling() {
getRootPane().setStyle("-fx-background-color: rgba(180, 180, 180, 0.85);");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,10 @@ public enum MiniGamesActions {
/**
* Action called when quitting a minigame.
* */
INGAME_QUIT
INGAME_QUIT,

/**
* Action called when closing the report at the end of a minigame.
* */
CLOSE_REPORT
}

0 comments on commit bfb3228

Please sign in to comment.