Skip to content

Commit

Permalink
Merge pull request #27 from solvena/27-add-player-status
Browse files Browse the repository at this point in the history
Add player status
  • Loading branch information
solvena authored May 24, 2026
2 parents 0d8e827 + 58f8cac commit 6cdac6f
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
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 @@ -488,8 +488,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

0 comments on commit 6cdac6f

Please sign in to comment.