-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The view acts as the context module in the Strategy design pattern.
- Loading branch information
Showing
1 changed file
with
79 additions
and
0 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/minigames/GameEngineView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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;"); | ||
| } | ||
| } |