Skip to content

Commit

Permalink
Merge pull request #119 from Team-40-IDATT2003/115-minigames
Browse files Browse the repository at this point in the history
115 minigames
  • Loading branch information
etsorens authored May 24, 2026
2 parents 9e70218 + 544cae7 commit 7401a6f
Show file tree
Hide file tree
Showing 28 changed files with 2,267 additions and 29 deletions.
54 changes: 51 additions & 3 deletions src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventManager;
import edu.ntnu.idi.idatt2003.g40.mappe.utils.ConfigValues;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewManager;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ingame.InGameController;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ingame.InGameView;
import edu.ntnu.idi.idatt2003.g40.mappe.view.mainmenu.MainMenuController;
import edu.ntnu.idi.idatt2003.g40.mappe.view.mainmenu.MainMenuView;
Expand All @@ -19,20 +20,25 @@
import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;

import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.WidgetEnum;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.financialsummary.SummaryController;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.financialsummary.SummaryView;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.dashboard.DashBoardController;
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.*;
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 @@ -72,7 +78,7 @@ public void start(final Stage stage) throws Exception {
ViewManager viewManager = new ViewManager(stage, eventManager);

List<Stock> stocksInFile;
FileParser parser1 = new FileParser("/dummydata.txt");
FileParser parser1 = new FileParser("/sp500.csv");

FileConverter converter1 = new FileConverter();
stocksInFile = converter1.getStocksFromStrings(parser1.readFile());
Expand Down Expand Up @@ -131,6 +137,10 @@ public void start(final Stage stage) throws Exception {
// In-game (Change "topBarView" to "topBarView2" if no summary section).
// Dashboard er default center-view.
InGameView inGameView = new InGameView(topBarView, dashBoardView.getRootPane());
InGameController inGameController = new InGameController(
inGameView,
eventManager
);

// Transaction history page
TransactionsView transactionsView = new TransactionsView();
Expand All @@ -139,6 +149,34 @@ 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,
stocksInFile.getFirst()
);

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

// Wire top bar buttons til å bytte mellom dashboard / stats / market /
// transactions. Stats-knappen tar deg til stats-siden.
topBarController.setMarketIntegration(
Expand All @@ -147,7 +185,9 @@ public void start(final Stage stage) throws Exception {
marketView.getRootPane(),
statsView.getRootPane(),
transactionsView.getRootPane(),
transactionsController::refresh);
transactionsController::refresh,
miniGamesView.getRootPane()
);

// Register all views
viewManager.addView(mainMenuView);
Expand All @@ -156,6 +196,14 @@ public void start(final Stage stage) throws Exception {
viewManager.addView(inGameView);
viewManager.setScene(mainMenuView);

// Register all widgets
inGameController.addwidget(WidgetEnum.DASHBOARD, dashBoardView.getRootPane());
inGameController.addwidget(WidgetEnum.MARKET, marketView.getRootPane());
inGameController.addwidget(WidgetEnum.MINIGAMES_OVERVIEW, miniGamesView.getRootPane());
inGameController.addwidget(WidgetEnum.MINIGAMES_ENGINE, gameEngineView.getRootPane());
inGameController.addwidget(WidgetEnum.STATS, statsView.getRootPane());
inGameController.addwidget(WidgetEnum.TRANSACTIONS, transactionsView.getRootPane());

stage.show();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ public Transaction sell(final Share share, final Player player)
*
* @throws IllegalArgumentException if any parameter is null, or if player does not have enough shares.
* */
public List<Transaction> sell(BigDecimal amount, final String stockSymbol, final Player player)
public List<Transaction> sell(BigDecimal amount,
final String stockSymbol,
final Player player)
throws IllegalArgumentException {
if (amount == null || player == null || !Validator.NOT_EMPTY.isValid(stockSymbol)) {
throw new IllegalArgumentException("Invalid sell!");
Expand Down Expand Up @@ -253,7 +255,8 @@ public void advance() {
for (Stock stock : stockMap.values()) {
BigDecimal currentPrice = stock.getSalesPrice();

double change = (random.nextDouble() * 0.10) - 0.05;
double change = ((random.nextDouble() * 0.10) - 0.05) + stock.getFortune();
stock.setFortune(0);
BigDecimal factor = BigDecimal.valueOf(1 + change);

BigDecimal newPrice = currentPrice.multiply(factor);
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/model/Stock.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ public final class Stock {
* */
private final List<BigDecimal> prices = new ArrayList<>();

/**
* Value indicating this stocks fortune.
*
* <p>Higher fortune yields a higher
* increase when stock market changes price.</p>
* */
private double fortune;

/**
* Creates a new {@code Stock} with an initial sales price.
*
Expand All @@ -42,10 +50,29 @@ public Stock(final String symbol,
} else {
this.symbol = symbol;
this.company = company;
this.fortune = 0;
prices.add(salesPrice);
}
}

/**
* Setter method for fortune.
*
* @param newFortune the new value to set this stocks' fortune.
* */
public void setFortune(final double newFortune) {
fortune = newFortune;
}

/**
* Getter method for fortune.
*
* @return fortune.
* */
public double getFortune() {
return fortune;
}

/**
* Returns the stock symbol.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,35 @@ public enum EventType implements EventChannel {
* @see edu.ntnu.idi.idatt2003.g40.mappe.view.ViewManager
*
*/
SCENE_CHANGE;
SCENE_CHANGE,

/**
* Event type representing events that causes the center view in the
* current {@link edu.ntnu.idi.idatt2003.g40.mappe.view.ingame.InGameView}
* object to change.
*
* <p>Primarily handled by the active
* {@link edu.ntnu.idi.idatt2003.g40.mappe.view.ingame.InGameController}
* object.</p>
*
* @see edu.ntnu.idi.idatt2003.g40.mappe.view.ingame.InGameController
*
*/
CHANGE_INGAME_CENTER,

/**
* Event type representing events that change the center view to
* {@link edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.minigames.MiniGamesView},
* and selects a given stock for the minigames.
*
* <p>Primarily handled by the active
* {@link edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.minigames.MiniGamesController}
* object.</p>
*
* @see edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.dashboard.DashBoardController
*
*/
SELECT_STOCK_FOR_MINIGAME;

/**
* {@inheritDoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ protected void changeScene(final ViewEnum viewName) {
invoke(eventData, eventManager);
}

/**
* Overloaded invoke method to reduce parameters, by using
* internal reference to event manager.
*
* @param <T> the type of data to send.
* @param data the data to send.
* */
protected <T> void invoke(final EventData<T> data) {
invoke(data, eventManager);
}

@Override
public final <T> void invoke(final EventData<T> data,
final EventManager eventManager) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,43 @@
package edu.ntnu.idi.idatt2003.g40.mappe.view.ingame;

import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventData;
import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventManager;
import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventSubscriber;
import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventType;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewController;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.WidgetEnum;
import javafx.scene.Node;
import java.util.EnumMap;

public class InGameController extends ViewController<InGameView> {
public final class InGameController extends ViewController<InGameView>
implements EventSubscriber {

private final EnumMap<WidgetEnum, Node> widgetMap = new EnumMap<>(WidgetEnum.class);

/**
* {@inheritDoc}.
*/
protected InGameController(final InGameView viewElement,
public InGameController(final InGameView viewElement,
final EventManager eventManager)
throws IllegalArgumentException {
super(viewElement, eventManager);
eventManager.addSubscriber(this, EventType.CHANGE_INGAME_CENTER);
}

public void addwidget(final WidgetEnum widgetEnum, final Node widgetRoot) {
widgetMap.put(widgetEnum, widgetRoot);
}

@Override
protected void initInteractions() {

}

@Override
public <T> void handleEvent(final EventData<T> data) {
if (!(data.data() instanceof WidgetEnum) || !widgetMap.containsKey(data.data())) {
throw new IllegalArgumentException("Invalid event thrown!");
}
getViewElement().changeCenterView(widgetMap.get(data.data()));
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
package edu.ntnu.idi.idatt2003.g40.mappe.view.ingame;

import edu.ntnu.idi.idatt2003.g40.mappe.model.Stock;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewElement;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewEnum;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.topbar.TopBarView;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Separator;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;

import java.util.ArrayList;

public class InGameView extends ViewElement<VBox, InGameActions> {

private final TopBarView topBarView;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package edu.ntnu.idi.idatt2003.g40.mappe.view.widgets;

/**
* Enum used to define the various widgets for the application.
*
* <p>Primarily handled by the {@link edu.ntnu.idi.idatt2003.g40.mappe.view.ingame.InGameController}
* for changing the active section of the game.</p>
* */
public enum WidgetEnum {
/**
* {@link edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.dashboard.DashBoardView}.
* */
DASHBOARD,

/**
* {@link edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.market.MarketView}.
* */
MARKET,

/**
* {@link edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.minigames.MiniGamesView}.
* */
MINIGAMES_OVERVIEW,

/**
* {@link edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.minigames.GameEngineView}.
* */
MINIGAMES_ENGINE,

/**
* {@link edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.stats.StatsView}.
* */
STATS,

/**
* {@link edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.transactions.TransactionsView}.
* */
TRANSACTIONS
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,10 @@ public enum DashBoardActions {
/**
* Increasing quantity of shares to buy/sell by five.
* */
INCREASE_5;
INCREASE_5,

/**
* Selecting viewed stock to boost by playing minigames.
* */
MINIGAME;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import edu.ntnu.idi.idatt2003.g40.mappe.engine.Exchange;
import edu.ntnu.idi.idatt2003.g40.mappe.model.*;
import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventData;
import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventManager;
import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventType;
import edu.ntnu.idi.idatt2003.g40.mappe.utils.Validator;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewController;
import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.WidgetEnum;
import javafx.scene.control.Button;
import javafx.scene.control.TextFormatter;
import java.math.BigDecimal;
Expand Down Expand Up @@ -180,6 +183,11 @@ protected void initInteractions() {
.add(new BigDecimal("5")).toString());
});

getViewElement().setOnAction(DashBoardActions.MINIGAME, () -> {
invoke(new EventData<>(EventType.SELECT_STOCK_FOR_MINIGAME, getViewElement().getCurrentStock()));
invoke(new EventData<>(EventType.CHANGE_INGAME_CENTER, WidgetEnum.MINIGAMES_OVERVIEW));
});

exchange.weekProperty().addListener((observable,o,n) -> {
getViewElement().updateGraph(selectedTimeRange);
populateStockList(selectedFilter);
Expand Down
Loading

0 comments on commit 7401a6f

Please sign in to comment.