Skip to content

Commit

Permalink
refactor added background to both screens and rewrote a lot of bad im…
Browse files Browse the repository at this point in the history
…plimentation
  • Loading branch information
peretr committed May 12, 2026
1 parent 40ea68f commit 5bf5364
Show file tree
Hide file tree
Showing 22 changed files with 133 additions and 171 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,14 @@
* Controller for the {@link BankApp}.
* Handles updating the player's financial status and portfolio view.
*/
public final class BankAppController implements AppController {
private final Player player;
private final BankApp bankApp;

public record BankAppController(BankApp bankApp, Player player) implements AppController {
/**
* Constructs a new BankAppController.
*
* @param bankApp the bank app view
* @param player the player model
*/
public BankAppController(final BankApp bankApp, final Player player) {
this.player = player;
this.bankApp = bankApp;
public BankAppController {
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ private void handleBuy(final Stock stock, final BigDecimal quantity) {
} else {
System.out.println("[DEBUG] Buy failed: transaction is null");
}
} catch (Exception e) {
} catch (Exception exception) {
System.out.println("[DEBUG] Buy failed with exception: "
+ e.getMessage());
e.printStackTrace();
+ exception.getMessage());
exception.printStackTrace();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@
* Controller for managing the game state and timing.
*/
public final class GameController {
/** The player model. */
private final Player player;
/** List of application controllers. */
private final List<AppController> appControllers = new ArrayList<>();
/** Timer for game ticks. */
private Timer timer;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
import edu.ntnu.idi.idatt2003.gruppe42.Model.Stock;
import edu.ntnu.idi.idatt2003.gruppe42.Model.StockFileHandler;
import edu.ntnu.idi.idatt2003.gruppe42.View.Apps.StockApp;
import javafx.application.Platform;

import java.nio.file.Path;
import java.util.List;
import java.util.Objects;

/**
* Controller for the stock market.
Expand All @@ -25,14 +24,14 @@ public MarketController() {
this.stockResolution = 50;

try {
Path path = Path.of(getClass().getClassLoader()
.getResource("stocks.csv").toURI());
Path path = Path.of(Objects.requireNonNull(getClass().getClassLoader()
.getResource("stocks.csv")).toURI());
exchange = new Exchange(StockFileHandler.readFromFile(path));

startMarket();
System.out.println("Market loaded");

} catch (Exception e) {
} catch (Exception exception) {
System.out.println("File not found");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,20 @@ public DesktopViewController(
) {
List<Popup> popups = new ArrayList<>();

final int appWidth = 400;
final int appHeight = 300;

AppStoreApp appStoreApp = new AppStoreApp(appWidth, appHeight, 100, 100);
AppStoreApp appStoreApp = new AppStoreApp();
gameController.addAppController(new AppStoreController(appStoreApp));

HustlersApp hustlersApp = new HustlersApp(appWidth, appHeight, 140, 140);
HustlersApp hustlersApp = new HustlersApp();

StockApp stockApp = new StockApp(appWidth, appHeight, 120, 120);
StockApp stockApp = new StockApp();
MarketController marketController = new MarketController();
gameController.addAppController(
new StockAppController(stockApp, marketController, player)
);

MailApp mailApp = new MailApp(appWidth, appHeight, 160, 160);
MailApp mailApp = new MailApp();

NewsApp newsApp = new NewsApp(appWidth, appHeight, 180, 180);
NewsApp newsApp = new NewsApp();

BankApp bankApp = new BankApp();
gameController.addAppController(new BankAppController(bankApp, player));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
* Calculator for stock purchase transactions.
*/
public final class PurchaseCalculator implements TransactionCalculator {
/** The price per share at purchase. */
private final BigDecimal purchasePrice;
/** The number of shares bought. */
private final BigDecimal quantity;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
* Calculator for stock sale transactions.
*/
public final class SaleCalculator implements TransactionCalculator {
/** The price per share at purchase. */
private final BigDecimal purchasePrice;
/** The current price per share at sale. */
private final BigDecimal salesPrice;
/** The number of shares sold. */
private final BigDecimal quantity;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ public class Exchange {
private int week;
/** Map of stock symbols to Stock objects. */
private final Map<String, Stock> stockMap;
/** Random number generator for simulation events. */
private final Random random;


/**
* Constructs a new {@code Exchange} with a list of stocks.
Expand All @@ -34,7 +33,6 @@ public class Exchange {
public Exchange(final List<Stock> stocks) {
this.week = 0;
this.stockMap = new HashMap<String, Stock>();
this.random = new Random();
for (Stock stock : stocks) {
stockMap.put(stock.getSymbol(), stock);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@
* Abstract base class for financial transactions.
*/
public abstract class Transaction {
/** The share position involved in the transaction. */
private final Share share;
/** The week the transaction occurred. */
private final int week;
/** The calculator used for this transaction. */
private final TransactionCalculator calculator;
/** Whether the transaction has been committed. */
private boolean committed = false;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,16 @@
import edu.ntnu.idi.idatt2003.gruppe42.View.Popup;

/**
* A popup for the AppStore app.
* A popup for the app store app.
*/
public class AppStoreApp extends Popup {

/**
* Constructs a new AppStore popup.
*
* @param width width of the popup
* @param height height of the popup
* @param x x-position of the popup
* @param y y-position of the popup
* Constructs a new app store popup.
*/
public AppStoreApp(int width, int height, int x, int y) {
super(width, height, x, y, App.APPSTORE);
// Add AppStore specific content here
public AppStoreApp() {
super(400, 300, 100, 100, App.APPSTORE);
// Add App store specific content here
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,59 +26,41 @@ public class BankApp extends Popup {
* Constructs a new Bank popup.
*/
public BankApp() {
super(400, 300, 120, 120, App.BANK);
super(400, 300, 220, 120, App.BANK);
this.portfolioList = new ListView<>();
updateContent();
}

private void updateContent() {
GridPane statusPane = new GridPane();
statusPane.add(netWorthLabel, 0, 0);
statusPane.add(growthPercentageLabel, 1, 0);
statusPane.add(unInvestedMoneyLabel, 0, 1);
statusPane.add(investedMoneyLabel, 1, 1);

final int col0 = 0;
final int col1 = 1;
final int row0 = 0;
final int row1 = 1;
portfolioList.setCellFactory(listView -> new ListCell<Share>() {
@Override
protected void updateItem(final Share share, final boolean empty) {
super.updateItem(share, empty);

statusPane.add(netWorthLabel, col0, row0);
statusPane.add(unInvestedMoneyLabel, col0, row1);
statusPane.add(investedMoneyLabel, col1, row1);
statusPane.add(growthPercentageLabel, col1, row0);
if (empty || share == null) {
setGraphic(null);
return;
}

portfolioList.setCellFactory(
lv ->
new ListCell<Share>() {
@Override
protected void updateItem(final Share share, final boolean empty) {
super.updateItem(share, empty);
if (empty || share == null) {
setGraphic(null);
} else {
GridPane sharePane = new GridPane();
final int col0 = 0;
final int col1 = 1;
final int row0 = 0;
final int row1 = 1;
final int row2 = 2;
final int row3 = 3;

sharePane.add(new Label(share.getStock().getCompany()),
col0, row0);
sharePane.add(new Label("Purchase"), col1, row0);
sharePane.add(new Label(share.getStock().getSymbol()),
col0, row1);
sharePane.add(new Label(share.getPurchasePrice().toString()),
col1, row1);
sharePane.add(new Label("Quantity"), col0, row2);
sharePane.add(new Label("Sale"), col1, row2);
sharePane.add(new Label(share.getQuantity().toString()),
col0, row3);
sharePane.add(new Label(share.getStock().getSalesPrice()
.toString()), col1, row3);
sharePane.setAlignment(Pos.CENTER_LEFT);
setGraphic(sharePane);
}
}
});
GridPane sharePane = new GridPane();
sharePane.setAlignment(Pos.CENTER_LEFT);
sharePane.add(new Label(share.getStock().getCompany()), 0, 0);
sharePane.add(new Label("Purchase"), 1, 0);
sharePane.add(new Label(share.getStock().getSymbol()), 0, 1);
sharePane.add(new Label(share.getPurchasePrice().toString()), 1, 1);
sharePane.add(new Label("Quantity"), 0, 2);
sharePane.add(new Label("Sale"), 1, 2);
sharePane.add(new Label(share.getQuantity().toString()), 0, 3);
sharePane.add(new Label(share.getStock().getSalesPrice().toString()), 1, 3);
setGraphic(sharePane);
}
});

content.getChildren().setAll(statusPane, portfolioList);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,9 @@ public class HustlersApp extends Popup {

/**
* Constructs a new Hustlers popup.
*
* @param width width of the popup
* @param height height of the popup
* @param x x-position of the popup
* @param y y-position of the popup
*/
public HustlersApp(int width, int height, int x, int y) {
super(width, height, x, y, App.HUSTLERS);
public HustlersApp() {
super(400, 300, 140, 140, App.HUSTLERS);
// Add Hustlers specific content here
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,9 @@ public class MailApp extends Popup {
/**
* Constructs a new Mail popup.
*
* @param width width of the popup
* @param height height of the popup
* @param x x-position of the popup
* @param y y-position of the popup
*/
public MailApp(int width, int height, int x, int y) {
super(width, height, x, y, App.MAIL);
public MailApp() {
super(400, 300, 140, 140, App.MAIL);
// Add Mail specific content here
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,9 @@ public class NewsApp extends Popup {

/**
* Constructs a new News popup.
*
* @param width width of the popup
* @param height height of the popup
* @param x x-position of the popup
* @param y y-position of the popup
*/
public NewsApp(int width, int height, int x, int y) {
super(width, height, x, y, App.NEWS);
// Add News specific content here
public NewsApp() {
super(400, 300, 180, 180, App.NEWS);
// Add news-specific content here
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,14 @@ public class StockApp extends Popup {
/**
* Constructs a new Stock popup.
*
* @param width width of the popup
* @param height height of the popup
* @param x x-position of the popup
* @param y y-position of the popup
*/
public StockApp(final int width, final int height, final int x, final int y) {
super(width, height, x, y, App.STOCK);
public StockApp() {
super(400, 300, 140, 140, App.STOCK);
this.searchField = new TextField();
this.stockList = new ListView<>();

final int minQuantity = -1000;
final int maxQuantity = 1000;
final int minQuantity = -10;
final int maxQuantity = 10;
final int initialQuantity = 0;
this.quantitySpinner = new Spinner<>(
minQuantity, maxQuantity, initialQuantity
Expand Down
Loading

0 comments on commit 5bf5364

Please sign in to comment.