Skip to content

This will change everything. #102

Merged
merged 2 commits into from
May 14, 2026
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .claude/settings.local.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"permissions": {
"allow": [
"Bash(del \"C:\\\\Users\\\\perer\\\\Documents\\\\GitHub\\\\Millions\\\\src\\\\main\\\\java\\\\edu\\\\ntnu\\\\idi\\\\idatt2003\\\\gruppe42\\\\View\\\\Apps\\\\DebtWarningApp.java\")"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import javafx.application.Platform;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.ListCell;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
Expand All @@ -31,6 +32,12 @@ public final class StockAppController implements AppController {
private Stock currentStock;
private AudioManager audioManager = AudioManager.getInstance();

/** True while the game is on Saturday or Sunday. */
private boolean isWeekend = false;

/** Called when the player clicks Trade during a weekend. */
private Runnable onMarketClosed;

/**
* Constructs a new StockAppController.
*
Expand Down Expand Up @@ -164,10 +171,46 @@ protected void updateItem(final Stock stock, final boolean empty) {
};
}

/**
* Enables or disables trading based on whether it is a weekend.
* When weekend is {@code true} the Trade button is visually dimmed and
* the spinner is disabled; clicking Trade triggers the market-closed callback.
*
* @param weekend {@code true} on Saturday/Sunday, {@code false} on weekdays
*/
public void setWeekend(final boolean weekend) {
this.isWeekend = weekend;
Button tradeButton = stockApp.getConfirmButton();
if (weekend) {
tradeButton.getStyleClass().add("trade-button-weekend");
tradeButton.setOpacity(0.45);
stockApp.getQuantitySpinner().setDisable(true);
} else {
tradeButton.getStyleClass().remove("trade-button-weekend");
tradeButton.setOpacity(1.0);
stockApp.getQuantitySpinner().setDisable(false);
}
}

/**
* Registers the callback invoked when the player clicks Trade on a weekend.
*
* @param callback the action to run (typically shows a market-closed warning)
*/
public void setOnMarketClosed(final Runnable callback) {
this.onMarketClosed = callback;
}

/**
* Handles the trade button action based on the spinner value.
*/
private void handleTransaction() {
if (isWeekend) {
if (onMarketClosed != null) {
onMarketClosed.run();
}
return;
}
if (currentStock == null) {
return;
}
Expand Down Expand Up @@ -210,7 +253,7 @@ private void handleBuy(final Stock stock, final BigDecimal quantity) {
*/
private void handleSell(final Stock stock, final BigDecimal quantity) {
player.getPortfolio().getShares().stream()
.filter(s -> s.getStock().getSymbol().equals(stock.getSymbol()))
.filter(share -> share.getStock().getSymbol().equals(stock.getSymbol()))
.findFirst()
.ifPresent(existingShare -> {
if (existingShare.getQuantity().compareTo(quantity) < 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void setGameState(GameState gameState) {
public void startGame() {
timer = new Timer(true);
final int delay = 0;
final int period = 1000;
final int period = 50;

timer.scheduleAtFixedRate(
new TimerTask() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
public final class MarketController {
private Exchange exchange;
private final int stockResolution;
private StockApp stockApp;

/**
* Constructs a new MarketController and starts the market.
Expand Down Expand Up @@ -64,8 +63,10 @@ public void updateMarket() {
* Starts the market by performing initial updates.
*/
public void startMarket() {
for (int i = 0; i < stockResolution; i++) {
updateMarket();
for (Stock stock : exchange.getAllStocks()) {
stock.fakeHistory(stockResolution);
stock.updateStockGraph();

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import edu.ntnu.idi.idatt2003.gruppe42.Model.App;
import edu.ntnu.idi.idatt2003.gruppe42.View.Popup;
import java.util.List;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;

Expand Down Expand Up @@ -55,6 +56,10 @@ public List<Popup> getPopups() {
return popups;
}

public void bindOpenButton(Button button, App type){
button.setOnAction(event -> show(type));
}

private void makeDraggable(Popup popup) {
BorderPane root = popup.getRoot();
double[] offset = new double[2];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public TimeAndWeatherController(GameController gameController) {
public void nextTick() {
int nextHour = hour.get() + 1;
if (nextHour >= 24) {
System.out.println("This is the day" + dayIndex);
System.out.println("This is the hour" + hour);
dayIndex.set((dayIndex.get() + 1) % 7);
updateGameState();
updateWeather();
Expand All @@ -56,19 +54,16 @@ private void updateWeather() {
// Range from -10 to 30
int change = random.nextInt(11) - 5; // -5 to +5
int newTemp = temperature.get() + change;
if (newTemp < -10) newTemp = -10;
if (newTemp > 30) newTemp = 30;
newTemp = Math.min(Math.max(newTemp, -10), 30);
temperature.set(newTemp);

if (newTemp <= 0) {

if (random.nextBoolean()) {
weather.set("Sunny");
} else if (newTemp <= 0) {
weather.set("Snow");
} else {
// If warm, could be sunny or rain
if (random.nextBoolean()) {
weather.set("Sunny");
} else {
weather.set("Rain");
}
weather.set("Rain");
}
}

Expand Down Expand Up @@ -112,13 +107,10 @@ public String getWeekString() {
}

public void updateGameState() {

if (dayIndex.get() == 6) {
System.out.println("det er lørdag");
gameController.setGameState(GameState.RENTDAY);
return;
} else if (dayIndex.get() == 0) {
System.out.println("det er søndag");
gameController.setGameState(GameState.FREEDAY);
return;
}
Expand Down
Loading