Skip to content

player status #134

Merged
merged 1 commit into from
May 26, 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
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,63 @@
* Enum representing a players' current status.
*
* <p>The player has the responsibility for getting
* a status.</p>
* a status. Each status has a percent-increase threshold
* (measured against the players' starting capital) and a
* human-readable, socio-economic display name used by
* the UI.</p>
* */
public enum PlayerStatus {

/** Status representing a beginner. */
NOOB(0),
/** Status representing a beginner / lowest tier. */
NOOB(0, "Really Poor"),

/**
* Status representing a player who has increased
* their net worth by at least 20 percent. */
NOVICE(20),
NOVICE(20, "Poor"),

/**
* Status representing a player who has increased
* their net worth by at least 50 percent. */
GOOD(50),
GOOD(50, "Middle Class"),

/** Status representing a player who has at least doubled their net worth. */
TRYHARD(100),
TRYHARD(100, "Wealthy"),

/** Status representing a player who has at least tripled their net worth. */
PRO(200),
PRO(200, "Rich"),

/**
* Status representing a player who has at least quintupled their
* net worth. */
SEER(400),
SEER(400, "Elite"),

/**
* Status representing a player who has at least dectupled their
* net worth. */
OMNIPOTENT(900);
OMNIPOTENT(900, "Tycoon");

/**
* Value representing percent increase
* from starting money needed to get the respective status.
* */
private final int percentIncreaseNeeded;

/**
* Human-readable, socio-economic label shown in the UI
* (e.g. "Really Poor", "Middle Class", "Tycoon").
* */
private final String displayName;

/**
* Constructor.
*
* @param percentIncreaseNeeded the increase needed to get the status.
* @param displayName the socio-economic label shown in the UI.
* */
PlayerStatus(final int percentIncreaseNeeded) {
PlayerStatus(final int percentIncreaseNeeded, final String displayName) {
this.percentIncreaseNeeded = percentIncreaseNeeded;
this.displayName = displayName;
}

/**
Expand All @@ -60,5 +71,16 @@ public enum PlayerStatus {
public int getPercentIncreaseNeeded() {
return percentIncreaseNeeded;
}
}

/**
* Returns the human-readable, socio-economic label
* for this status (e.g. "Really Poor", "Middle Class",
* "Tycoon"). Used by the UI to label the players'
* current income/investment tier.
*
* @return the display name.
* */
public String getDisplayName() {
return displayName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public SummaryController(final SummaryView viewElement,
eventManager.addSubscriber(this, EventType.STATE_RESET);
eventManager.addSubscriber(this, EventType.PRE_LOAD_SAVE);
getViewElement().setBalance(player.getStartingMoney().floatValue(), player.getStartingMoney().floatValue());
getViewElement().setStatus(player.getStatus());
}

@Override
Expand All @@ -46,14 +47,17 @@ protected void initInteractions() {
playerNetWorthHistory.add(player.getNetWorth().floatValue());
getViewElement().updateChart(playerNetWorthHistory);
getViewElement().setBalance(player.getMoney().floatValue(), player.getNetWorth().floatValue());
getViewElement().setStatus(player.getStatus());
});

player.getNetWorthAsFloatProperty().addListener((observable, o, n) -> {
getViewElement().setBalance(player.getMoney().floatValue(), player.getNetWorth().floatValue());
getViewElement().setStatus(player.getStatus());
});

player.getMoneyAsFloatProperty().addListener((observable, o, n) -> {
getViewElement().setBalance(player.getMoney().floatValue(), player.getNetWorth().floatValue());
getViewElement().setStatus(player.getStatus());
});
}

Expand Down Expand Up @@ -99,5 +103,6 @@ public <T> void handleEvent(final EventData<T> data) {
getViewElement().updateChart(playerNetWorthHistory);
getViewElement().setBalance(player.getMoney().floatValue(),
player.getNetWorth().floatValue());
getViewElement().setStatus(player.getStatus());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.financialsummary;

import edu.ntnu.idi.idatt2003.g40.mappe.model.PlayerStatus;
import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewElement;
import javafx.geometry.Pos;
import javafx.scene.chart.LineChart;
Expand All @@ -15,6 +16,7 @@

public class SummaryView extends ViewElement<HBox, SummaryActions> {
private Label balanceLabel;
private Label statusLabel;
private Label weekLabel;
private Label titleLabel;
private LineChart<Number, Number> chart;
Expand Down Expand Up @@ -43,11 +45,12 @@ protected void initLayout() {

titleLabel = new Label("Networth");
balanceLabel = new Label("0$");
statusLabel = new Label(PlayerStatus.NOOB.getDisplayName());

Region spacerL = new Region();
VBox.setVgrow(spacerL, Priority.ALWAYS);

balanceInfo.getChildren().addAll(titleLabel, spacerL, balanceLabel);
balanceInfo.getChildren().addAll(titleLabel, spacerL, balanceLabel, statusLabel);

xAxis = new NumberAxis(1, 10, 1);
xAxis.setMinorTickVisible(false);
Expand Down Expand Up @@ -106,13 +109,34 @@ protected void initStyling() {
getRootPane().getStyleClass().add("summary-container");
titleLabel.getStyleClass().add("balance-title");
balanceLabel.getStyleClass().add("balance-value");
statusLabel.getStyleClass().add("player-status-label");
nextBtn.getStyleClass().add("next-button");
}

public void setBalance(final float money, final float netWorth) {
balanceLabel.setText(Math.round(money*100f)/100f + "NOK / " + Math.round(netWorth*100f)/100f + "NOK");
}

/**
* Updates the displayed socio-economic status label.
*
* <p>Shows the players' current income/investment tier
* (e.g. "Really Poor", "Middle Class", "Tycoon") as
* computed by {@link edu.ntnu.idi.idatt2003.g40.mappe.controller.PlayerStatusController}.</p>
*
* @param status the players' current status. Null is ignored.
* */
public void setStatus(final PlayerStatus status) {
if (status == null) {
return;
}
statusLabel.setText(status.getDisplayName());
// Swap CSS pseudo/style class so each tier can be themed
// independently (e.g. red for "Really Poor", gold for "Tycoon").
statusLabel.getStyleClass().removeIf(c -> c.startsWith("status-tier-"));
statusLabel.getStyleClass().add("status-tier-" + status.name().toLowerCase());
}

public void setWeek(int week) {
weekLabel.setText("week: " + week);
}
Expand Down