Skip to content

Add player status #27

Merged
merged 3 commits into from
May 24, 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
30 changes: 30 additions & 0 deletions src/main/java/Model/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,35 @@ public TransactionArchive getTransactionArchive() {
return this.transactionArchive;
}

/**
* Returns the player's current status based on trading activity and net worth performance.
*
* Status levels:
* - NOVICE: Starting level, no requirements
* - INVESTOR: At least 10 weeks of trading AND net worth increased by at least 20%
* - SPECULATOR: At least 20 weeks of trading AND net worth at least doubled
*
* @return the player's current PlayerStatus
*/
public PlayerStatus getStatus() {
// Calculate total net worth: current cash + portfolio value
BigDecimal totalNetWorth = this.money.add(this.portfolio.getNetWorth());

// Get number of weeks with trading activity
int weeksActive = this.transactionArchive.countDistinctWeeks();

// Check for SPECULATOR status: 20+ weeks AND net worth doubled
if (weeksActive >= 20 && totalNetWorth.compareTo(this.startingMoney.multiply(new BigDecimal("2"))) >= 0) {
return PlayerStatus.SPECULATOR;
}

// Check for INVESTOR status: 10+ weeks AND net worth increased by 20%
if (weeksActive >= 10 && totalNetWorth.compareTo(this.startingMoney.multiply(new BigDecimal("1.2"))) >= 0) {
return PlayerStatus.INVESTOR;
}

// Default: NOVICE
return PlayerStatus.NOVICE;
}

}
25 changes: 25 additions & 0 deletions src/main/java/Model/PlayerStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package Model;

/**
* Enum representing the player's status level based on trading activity and performance.
*
* Status levels:
* - NOVICE: Starting level, no requirements
* - INVESTOR: Traded for at least 10 weeks AND increased net worth by at least 20%
* - SPECULATOR: Traded for at least 20 weeks AND doubled the net worth (100% increase)
*/
public enum PlayerStatus {
NOVICE("Novice"),
INVESTOR("Investor"),
SPECULATOR("Speculator");

private final String displayName;

PlayerStatus(String displayName) {
this.displayName = displayName;
}

public String getDisplayName() {
return displayName;
}
}
2 changes: 2 additions & 0 deletions src/main/java/View/MainGameScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,10 @@ private void updateBuyInfo(String symbol, TextField qtyField, Label label) {
}

private void updateStatus() {
PlayerStatus playerStatus = player.getStatus();
statusLabel.setText(
"Player: " + player.getName() +
" | Status: " + playerStatus.getDisplayName() +
" | Week: " + exchange.getWeek() +
" | Cash: $" + formatMoney(player.getMoney()) +
" | Net Worth: $" + formatMoney(getNetWorth())
Expand Down