Skip to content

Commit

Permalink
Feat: Updated several classes to work with minigames
Browse files Browse the repository at this point in the history
  • Loading branch information
tommyah committed May 23, 2026
1 parent c31d0ec commit 5cc0d08
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 10 deletions.
26 changes: 22 additions & 4 deletions src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.dashboard.DashBoardView;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.market.MarketController;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.market.MarketView;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.minigames.MiniGamesController;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.minigames.MiniGamesView;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.minigames.*;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.minigames.games.ClickerGame;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.minigames.games.FindStockGame;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.minigames.games.TimeInputsGame;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.stats.StatsController;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.stats.StatsView;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.topbar.TopBarController;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.topbar.TopBarView;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.transactions.TransactionsController;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.transactions.TransactionsView;
import javafx.application.Application;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.text.Font;
Expand Down Expand Up @@ -141,11 +142,28 @@ public void start(final Stage stage) throws Exception {
eventManager,
player.getTransactionArchive());

ClickerGame clickerGame = new ClickerGame();
FindStockGame findStockGame = new FindStockGame(
stocksInFile.stream()
.map(Stock::getSymbol)
.toList()
);
TimeInputsGame timeInputsGame = new TimeInputsGame();

GameEngineView gameEngineView = new GameEngineView();
GameEngineController gameEngineController = new GameEngineController(gameEngineView, eventManager);

MiniGamesView miniGamesView = new MiniGamesView();
new MiniGamesController(
miniGamesView,
eventManager,
stocksInFile.getFirst()
stocksInFile.getFirst(),
gameEngineView,
gameEngineController,
clickerGame,
inGameView,
findStockGame,
timeInputsGame
);

// Wire top bar buttons til å bytte mellom dashboard / stats / market /
Expand Down
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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
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 edu.ntnu.idi.idatt2003.g40.mappe.view.ingame.InGameView;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.minigames.games.ClickerGame;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.minigames.games.FindStockGame;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.minigames.games.TimeInputsGame;

/**
* Controller class for the associated {@link MiniGamesView} object.
Expand All @@ -11,12 +15,30 @@
* */
public final class MiniGamesController extends ViewController<MiniGamesView> {
private Stock activeStock;
private final GameEngineView gameEngineView;
private final GameEngineController gameEngineController;
private final ClickerGame clickerGame;
private final InGameView inGameView;
private final FindStockGame findStockGame;
private final TimeInputsGame timeInputsGame;

public MiniGamesController(final MiniGamesView viewElement,
final EventManager eventManager,
final Stock initialStock) {
super(viewElement, eventManager);
final Stock initialStock,
final GameEngineView gameEngineView,
final GameEngineController gameEngineController,
final ClickerGame clickerGame,
final InGameView inGameView,
final FindStockGame findStockGame,
final TimeInputsGame timeInputsGame) {
this.activeStock = initialStock;
this.gameEngineView = gameEngineView;
this.gameEngineController = gameEngineController;
this.clickerGame = clickerGame;
this.inGameView = inGameView;
this.findStockGame = findStockGame;
this.timeInputsGame = timeInputsGame;
super(viewElement, eventManager);
refresh();
}

Expand All @@ -27,15 +49,18 @@ protected void initInteractions() {
});

getViewElement().setOnAction(MiniGamesActions.CLICKER_GAME, () -> {
// Logic for launching Clicker Game
inGameView.changeCenterView(gameEngineView.getRootPane());
gameEngineController.launchGimmickSession(clickerGame);
});

getViewElement().setOnAction(MiniGamesActions.FIND_STOCK, () -> {
// Logic for launching Find Stock Game
inGameView.changeCenterView(gameEngineView.getRootPane());
gameEngineController.launchGimmickSession(findStockGame);
});

getViewElement().setOnAction(MiniGamesActions.TIME_CLICKS, () -> {
// Logic for launching Time Clicks Game
inGameView.changeCenterView(gameEngineView.getRootPane());
gameEngineController.launchGimmickSession(timeInputsGame);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewElement;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
Expand Down
34 changes: 33 additions & 1 deletion src/main/resources/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -860,4 +860,36 @@
.minigames-cardBtn:hover, .minigames-helpBtn:hover {
-fx-background-color: #c0c0c0;
}
/* --------------------------------------------- */
/* --------------------------------------------- */
/* --------------- FIND STOCK GAME ------------*/
.find-stock-minigame-root {
-fx-spacing: 15;
-fx-alignment: CENTER;
}

.find-stock-minigame-grid {
-fx-hgap: 15px;
-fx-vgap: 15px;
-fx-alignment: center;
}
/*----------------------------------------------*/
/*--------------- CLICKER GAME -----------------*/
.clicker-minigame-root {
-fx-spacing: 20;
-fx-alignment: CENTER;
}

.clicker-minigame-clickBtn {
-fx-pref-width: 100;
-fx-pref-height: 100;
}

.clicker-minigame-upgradeBtn {
-fx-text-alignment: center;
}
/*--------------- TIMED INPUT GAME -------------*/
.time-inputs-minigame-root {
-fx-background-color: transparent;
-fx-focus-traversable: true;
}
/*-----------------------------------------------*/

0 comments on commit 5cc0d08

Please sign in to comment.