Class Statistics
java.lang.Object
com.csse3200.game.progression.statistics.Statistics
The Statistics class tracks and stores player/user statistics across the game and manages
achievements based on those statistics. It records cumulative data such as total kills, total
shots, player level, number of plants unlocked, and all-time total coins earned.
Statistics are initialised within and linked to a particular Profile. When statistics are updated, the class checks achievement quotas and unlocks achievements automatically.
Achievements are stored as a list of unlocked achievement keys, similar to how Arsenal and Inventory work.
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor for Statistics.Creates a Statistics instance with specified statistics and achievements. -
Method Summary
Modifier and TypeMethodDescriptionGets all statistics.int
getStatistic
(String key) Gets the value of a specific statistic.Gets the list of unlocked achievement keys.void
incrementStatistic
(String key) Increments a statistic by 1 and checks for achievement unlocks.void
incrementStatistic
(String key, int amount) Increments a statistic by a specific amount and checks for achievement unlocks.boolean
isAchievementUnlocked
(String achievementKey) Checks if an achievement is unlocked.void
setStatistic
(String key, int newValue) Updates a statistic and checks for achievement unlocks.
-
Constructor Details
-
Statistics
public Statistics()Default constructor for Statistics. -
Statistics
Creates a Statistics instance with specified statistics and achievements.- Parameters:
stats
- the statistics mapachievements
- the list of unlocked achievement keys
-
-
Method Details
-
getStatistic
Gets the value of a specific statistic.- Parameters:
key
- the name of the statistic- Returns:
- the value of the statistic, or 0 if not found
-
getAllStatistics
Gets all statistics.- Returns:
- map of all statistics
-
getUnlockedAchievements
Gets the list of unlocked achievement keys.- Returns:
- list of unlocked achievement keys
-
isAchievementUnlocked
Checks if an achievement is unlocked.- Parameters:
achievementKey
- the achievement key- Returns:
- true if unlocked, false otherwise
-
setStatistic
Updates a statistic and checks for achievement unlocks.- Parameters:
key
- the name of the statistic to updatenewValue
- the new value for the statistic
-
incrementStatistic
Increments a statistic by 1 and checks for achievement unlocks.- Parameters:
key
- the name of the statistic to increment
-
incrementStatistic
Increments a statistic by a specific amount and checks for achievement unlocks.- Parameters:
key
- the name of the statistic to incrementamount
- the amount to increment by
-