Skip to content

Commit

Permalink
Added GameEngineView
Browse files Browse the repository at this point in the history
The view acts as the context module in the Strategy design pattern.
  • Loading branch information
tommyah committed May 23, 2026
1 parent 625bbf5 commit f7c5472
Showing 1 changed file with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.minigames;

import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewElement;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;

import java.util.function.IntConsumer;

public final class GameEngineView extends ViewElement<BorderPane, MiniGamesActions> {
private Button quitButton;
private Label scoreLabel;
private Label timerLabel;
private Label rankLabel;
private HBox topDashboardBar;
private int curScore;

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.
*
* @param score the score to show.
* @param time the time to show.
* @param rank the rank to show.
* */
public void updateMetadataDisplay(final int score,
final String time,
final String rank) {
scoreLabel.setText("Score: " + score);
timerLabel.setText(time);
rankLabel.setText("Rank: " + rank);
}

/**
* Sets the content of this view based on the game provided through the
* {@link GameGimmick} interface.
*
* @param gimmick a concrete implementation of the {@link GameGimmick}
* interface
* */
public void setGameGimmickContent(final GameGimmick gimmick, final IntConsumer consumer) {
getRootPane().setCenter(gimmick.getCanvasNode());
gimmick.initialize(consumer);
}

@Override
protected void initStyling() {
getRootPane().setStyle("-fx-background-color: rgba(180, 180, 180, 0.85);");
topDashboardBar.setStyle("-fx-background-color: transparent;");
scoreLabel.setStyle("-fx-font-size: 24px; -fx-text-fill: black;");
timerLabel.setStyle("-fx-font-size: 24px; -fx-text-fill: black;");
rankLabel.setStyle("-fx-font-size: 24px; -fx-text-fill: black;");
}
}

0 comments on commit f7c5472

Please sign in to comment.