Skip to content

Commit

Permalink
Merge pull request #54 from IDATT2003-gruppe06/feat/prettify
Browse files Browse the repository at this point in the history
Merge Feat/prettify into dev
  • Loading branch information
mohenoen authored May 26, 2026
2 parents 381a64d + 2d2cbd3 commit 407efb1
Show file tree
Hide file tree
Showing 7 changed files with 695 additions and 65 deletions.
28 changes: 22 additions & 6 deletions src/main/java/millions/App.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
package millions;


import java.math.BigDecimal;
import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.stage.Stage;
import millions.controller.GameController;
import millions.controller.fileIO.CSV.CSVStockFileWriter;
import millions.controller.fileIO.InvalidFormatException;
import millions.controller.fileIO.UncheckedFileNotFoundException;
import millions.view.ExitView;
import millions.view.GameView;
import millions.view.StartView;

/** Main JavaFX application entry point for the Millions stock trading game. */
public class App extends Application {
private static final Logger logger = Logger.getLogger(App.class.getName());
private static final String STYLESHEET =
Objects.requireNonNull(App.class.getResource("/styles/millions.css")).toExternalForm();

@Override
public void start(Stage stage) {
GameController controller = new GameController();
Expand All @@ -35,23 +37,34 @@ public void start(Stage stage) {
startView.getSelectedFile().toPath(),
startView.getPreRunWeeks());

GameView gameView = new GameView(controller);
GameView gameView =
new GameView(
controller,
() -> {
ExitView exitView = new ExitView(controller.getPlayer());
exitView.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
Scene exitScene = new Scene(exitView, 500, 400);
exitScene.getStylesheets().add(STYLESHEET);
stage.setScene(exitScene);
});
controller.getPlayer().addListener(gameView);
controller.getExchange().addListener(gameView);

Scene gameScene = new Scene(gameView, 1920, 1080);
gameScene.getStylesheets().add(STYLESHEET);
stage.setScene(gameScene);
} catch (InvalidFormatException e) {
logger.log(Level.WARNING, "InvalidFormatException: " + e.getMessage());

Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error");
alert.setHeaderText("Error with selected file");
alert.setContentText(e.getMessage() + "\nPlease control the format of the selected file");
alert.setContentText(
e.getMessage() + "\nPlease control the format of the selected file");

alert.showAndWait();

} catch(UncheckedFileNotFoundException e) {
} catch (UncheckedFileNotFoundException e) {
logger.log(Level.WARNING, "FileNotFoundException: " + e.getMessage());

Alert alert = new Alert(Alert.AlertType.ERROR);
Expand All @@ -68,7 +81,10 @@ public void start(Stage stage) {
});

Scene scene = new Scene(startView, 400, 350);
scene.getStylesheets().add(STYLESHEET);
stage.setTitle("Millions");
stage.setMinWidth(900);
stage.setMinHeight(600);
stage.setScene(scene);
stage.show();
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/millions/model/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public void withdrawMoney(BigDecimal amount) {

/**
* Calculates the skill level of the player
*
* @return String player status level
*/
public String getStatus() {
Expand Down Expand Up @@ -101,6 +102,13 @@ public Portfolio getPortfolio() {
return this.portfolio;
}

/**
* @return player startingMoney
*/
public BigDecimal getStartingMoneh() {
return this.startingMoney;
}

/**
* @param share Share to be added
*/
Expand Down
79 changes: 79 additions & 0 deletions src/main/java/millions/view/ExitView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package millions.view;

import java.math.BigDecimal;
import javafx.application.Platform;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Separator;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import millions.model.Player;

public class ExitView extends VBox {

public ExitView(Player player) {
setSpacing(16);
setAlignment(Pos.CENTER);
setPadding(new Insets(60));

Label title = new Label("GAME OVER");
title.getStyleClass().add("game-over-title");
HBox titleRow = new HBox(title);
titleRow.setAlignment(Pos.CENTER);
titleRow.setMaxWidth(Double.MAX_VALUE);

Separator sep = new Separator();
sep.setMaxWidth(320);

Label weeks = new Label(String.valueOf(player.getTransactionArchive().countDistinctWeeks()));
Label trades =
new Label(String.valueOf(player.getTransactionArchive().getTransactions().size()));
Label netWorth = new Label(ViewUtils.formatMoney(player.getNetWorth()));

BigDecimal profit = player.getNetWorth().subtract(player.getStartingMoneh());
String sign = profit.compareTo(BigDecimal.ZERO) >= 0 ? "+" : "";
Label netProfit = new Label(sign + ViewUtils.formatMoney(profit));
netProfit
.getStyleClass()
.add(profit.compareTo(BigDecimal.ZERO) >= 0 ? "status-success" : "status-error");

GridPane stats = new GridPane();
stats.setHgap(24);
stats.setVgap(12);
ColumnConstraints labelCol = new ColumnConstraints();
labelCol.setHalignment(HPos.RIGHT);
labelCol.setHgrow(Priority.NEVER);
ColumnConstraints valueCol = new ColumnConstraints();
valueCol.setHalignment(HPos.LEFT);
valueCol.setHgrow(Priority.ALWAYS);
stats.getColumnConstraints().addAll(labelCol, valueCol);

stats.addRow(0, statlabel("Weeks traded"), weeks);
stats.addRow(1, statlabel("Trades made"), trades);
stats.addRow(2, statlabel("Final net worth"), netWorth);
stats.addRow(3, statlabel("Total profit"), netProfit);

for (Label l : new Label[] {weeks, trades, netWorth, netProfit}) {
l.getStyleClass().add("stat-value");
}

Button quitButton = new Button("Quit");
quitButton.getStyleClass().add("btn-primary");
quitButton.setPrefWidth(160);
quitButton.setOnAction(event -> Platform.exit());

getChildren().addAll(titleRow, sep, stats, quitButton);
}

private static Label statlabel(String text) {
Label l = new Label(text);
l.getStyleClass().add("section-title");
return l;
}
}
Loading

0 comments on commit 407efb1

Please sign in to comment.