-
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.
Feat: Updated several classes to work with minigames
- Loading branch information
Showing
5 changed files
with
164 additions
and
10 deletions.
There are no files selected for viewing
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
78 changes: 78 additions & 0 deletions
78
...in/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/minigames/GameEngineController.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,78 @@ | ||
| package edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.minigames; | ||
|
|
||
| import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventManager; | ||
| import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewController; | ||
| import javafx.animation.KeyFrame; | ||
| import javafx.animation.Timeline; | ||
| import javafx.util.Duration; | ||
|
|
||
| public final class GameEngineController extends ViewController<GameEngineView> { | ||
|
|
||
| private int currentScore = 0; | ||
| private int frameCounter = 0; | ||
| private int secondsRemaining = 60; | ||
| private GameGimmick activeGimmick; | ||
| private Timeline engineLoop; | ||
|
|
||
| public GameEngineController(final GameEngineView viewElement, | ||
| final EventManager eventManager) throws IllegalArgumentException { | ||
| super(viewElement, eventManager); | ||
|
|
||
| engineLoop = new Timeline(new KeyFrame(Duration.millis(16.6), e -> { | ||
| activeGimmick.updateTick(); | ||
|
|
||
| frameCounter++; | ||
| if (frameCounter >= 60) { | ||
| secondsRemaining--; | ||
| frameCounter = 0; | ||
| refreshMetrics(); | ||
| } | ||
| })); | ||
| engineLoop.setCycleCount(Timeline.INDEFINITE); | ||
| } | ||
|
|
||
| @Override | ||
| protected void initInteractions() { | ||
| getViewElement().setOnAction(MiniGamesActions.INGAME_QUIT, this::stopGameSession); | ||
| } | ||
|
|
||
| public void launchGimmickSession(final GameGimmick gimmick) { | ||
| this.activeGimmick = gimmick; | ||
| this.currentScore = 0; | ||
| this.frameCounter = 0; | ||
| this.secondsRemaining = 60; | ||
| refreshMetrics(); | ||
|
|
||
| // Connect interactions. | ||
| getViewElement().setGameGimmickContent(gimmick, (scoreDelta) -> { | ||
| if (this.currentScore + scoreDelta >= 0) { | ||
| this.currentScore += scoreDelta; | ||
| refreshMetrics(); | ||
| } | ||
| }); | ||
| engineLoop.play(); | ||
| } | ||
|
|
||
| private void refreshMetrics() { | ||
| int hours = secondsRemaining / 3600; | ||
| int minutes = (secondsRemaining % 3600) / 60; | ||
| int seconds = secondsRemaining % 60; | ||
| String formattedTime = String.format("%02d:%02d:%02d", hours, minutes, seconds); | ||
|
|
||
| // Dynamic Rank classification engine evaluations | ||
| String rank = "E"; | ||
| if (currentScore > 50) rank = "A"; | ||
| else if (currentScore > 30) rank = "B"; | ||
| else if (currentScore > 15) rank = "C"; | ||
| else if (currentScore > 5) rank = "D"; | ||
|
|
||
| getViewElement().updateMetadataDisplay(currentScore, formattedTime, rank); | ||
| } | ||
|
|
||
| private void stopGameSession() { | ||
| if (engineLoop != null) { | ||
| engineLoop.stop(); | ||
| } | ||
| // Fire architecture EventManager updates here to go back to the menu view cleanly | ||
| } | ||
| } |
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
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
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