Skip to content

Commit

Permalink
Merge pull request #121 from Team-40-IDATT2003/118-play-game-menu
Browse files Browse the repository at this point in the history
118 play game menu
  • Loading branch information
tommyah authored May 24, 2026
2 parents 7401a6f + f4b7f67 commit e730057
Show file tree
Hide file tree
Showing 11 changed files with 1,345 additions and 159 deletions.
54 changes: 32 additions & 22 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,8 @@
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.creategame.CreateGameController;
import edu.ntnu.idi.idatt2003.g40.mappe.view.creategame.CreateGameView;
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;
Expand Down Expand Up @@ -68,7 +70,7 @@ static void main(String[] args) {
public void start(final Stage stage) throws Exception {
Scene scene = new Scene(new Pane());
scene.getStylesheets()
.add(Objects.requireNonNull(getClass().getResource("/styles.css")).toExternalForm());
.add(Objects.requireNonNull(getClass().getResource("/styles.css")).toExternalForm());
Font.loadFont(getClass().getResourceAsStream("/Fonts/Aptos.ttf"), 16);
stage.setScene(scene);
stage.setWidth(ConfigValues.VIEWPORT_WIDTH.getValue());
Expand All @@ -92,11 +94,18 @@ public void start(final Stage stage) throws Exception {

// Play game (mellom hovedmeny og spillet)
PlayGameView playGameView = new PlayGameView();
new PlayGameController(playGameView, eventManager);

// Last lagrede spill fra disk.
SaveGameService saveGameService = new SaveGameService();
playGameView.setSaves(saveGameService.loadSaves());
PlayGameController playGameController =
new PlayGameController(playGameView, eventManager, saveGameService);
playGameController.refresh();


// Create game (mellom play-game og selve spillet)
CreateGameView createGameView = new CreateGameView();
CreateGameController createGameController =
new CreateGameController(createGameView, eventManager, saveGameService);
// Refresh save-listen etter at en ny save er skrevet til disk.
createGameController.setOnSaveCreated(playGameController::refresh);

// Settings
SettingsView settingsView = new SettingsView();
Expand All @@ -117,10 +126,10 @@ public void start(final Stage stage) throws Exception {
// Dashboard (default center-view in-game - første siden du ser)
DashBoardView dashBoardView = new DashBoardView();
new DashBoardController(dashBoardView,
eventManager,
player,
exchange,
stocksInFile);
eventManager,
player,
exchange,
stocksInFile);

// Stats page (Stats-knappen i topbaren tar deg hit)
StatsView statsView = new StatsView();
Expand All @@ -129,10 +138,10 @@ public void start(final Stage stage) throws Exception {
// Market page (Market-knappen tar deg hit)
MarketView marketView = new MarketView();
new MarketController(marketView,
eventManager,
player,
exchange,
stocksInFile);
eventManager,
player,
exchange,
stocksInFile);

// In-game (Change "topBarView" to "topBarView2" if no summary section).
// Dashboard er default center-view.
Expand All @@ -152,8 +161,8 @@ public void start(final Stage stage) throws Exception {
ClickerGame clickerGame = new ClickerGame();
FindStockGame findStockGame = new FindStockGame(
stocksInFile.stream()
.map(Stock::getSymbol)
.toList()
.map(Stock::getSymbol)
.toList()
);
TimeInputsGame timeInputsGame = new TimeInputsGame();

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

// Register all views
viewManager.addView(mainMenuView);
viewManager.addView(playGameView);
viewManager.addView(createGameView);
viewManager.addView(settingsView);
viewManager.addView(inGameView);
viewManager.setScene(mainMenuView);
Expand Down
130 changes: 94 additions & 36 deletions src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/model/SaveGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,102 @@
* Represents one save game entry.
*
* <p>
* Holds the display name and the current balance for a single
* Holds the display name, current balance, starting capital and
* (optionally) the path to a custom stock data file for a single
* saved game.
* </p>
*
* <p>
* When {@link #getStockDataPath()} returns {@code null} the save is
* expected to be loaded with the default bundled stock data file.
* </p>
*/
public class SaveGame {

/** Display name of the save. */
private final String name;

/** Current balance in the save. */
private final double balance;

/**
* Constructor.
*
* @param name the display name of the save.
* @param balance the current balance value.
*/
public SaveGame(final String name, final double balance) {
this.name = name;
this.balance = balance;
}

/**
* Getter method for the name.
*
* @return the save name.
*/
public String getName() {
return name;
}

/**
* Getter method for the balance.
*
* @return the balance value.
*/
public double getBalance() {
return balance;
}
}
/** Display name of the save. */
private final String name;

/** Current balance in the save. */
private final double balance;

/** The starting capital chosen when the save was created. */
private final double startingCapital;

/**
* Absolute path to a custom stock data file, or {@code null}
* if the save should use the default bundled stock data.
* */
private final String stockDataPath;

/**
* Full constructor.
*
* @param name the display name of the save.
* @param balance the current balance value.
* @param startingCapital the starting capital chosen on creation.
* @param stockDataPath absolute path to a custom stock data file,
* or {@code null} to use the default file.
*/
public SaveGame(final String name,
final double balance,
final double startingCapital,
final String stockDataPath) {
this.name = name;
this.balance = balance;
this.startingCapital = startingCapital;
this.stockDataPath = stockDataPath;
}

/**
* Convenience constructor matching the legacy "name + balance" format.
*
* <p>
* Starting capital is defaulted to the balance value and
* {@code stockDataPath} is left {@code null} so the default stock
* data file is used.
* </p>
*
* @param name the display name of the save.
* @param balance the current balance value.
*/
public SaveGame(final String name, final double balance) {
this(name, balance, balance, null);
}

/**
* Getter method for the name.
*
* @return the save name.
*/
public String getName() {
return name;
}

/**
* Getter method for the balance.
*
* @return the balance value.
*/
public double getBalance() {
return balance;
}

/**
* Getter method for the starting capital.
*
* @return the starting capital chosen on creation.
*/
public double getStartingCapital() {
return startingCapital;
}

/**
* Getter method for the custom stock data path.
*
* @return the absolute path to a custom stock data file,
* or {@code null} if the save uses the default data.
*/
public String getStockDataPath() {
return stockDataPath;
}
}
Loading

0 comments on commit e730057

Please sign in to comment.