Class Statistics

java.lang.Object
com.csse3200.game.progression.statistics.Statistics

public class Statistics extends Object
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 Details

    • Statistics

      public Statistics()
      Default constructor for Statistics.
    • Statistics

      public Statistics(Map<String,Integer> stats, List<String> achievements)
      Creates a Statistics instance with specified statistics and achievements.
      Parameters:
      stats - the statistics map
      achievements - the list of unlocked achievement keys
  • Method Details

    • getStatistic

      public int getStatistic(String key)
      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

      public Map<String,Integer> getAllStatistics()
      Gets all statistics.
      Returns:
      map of all statistics
    • getUnlockedAchievements

      public List<String> getUnlockedAchievements()
      Gets the list of unlocked achievement keys.
      Returns:
      list of unlocked achievement keys
    • isAchievementUnlocked

      public boolean isAchievementUnlocked(String achievementKey)
      Checks if an achievement is unlocked.
      Parameters:
      achievementKey - the achievement key
      Returns:
      true if unlocked, false otherwise
    • setStatistic

      public void setStatistic(String key, int newValue)
      Updates a statistic and checks for achievement unlocks.
      Parameters:
      key - the name of the statistic to update
      newValue - the new value for the statistic
    • incrementStatistic

      public void incrementStatistic(String key)
      Increments a statistic by 1 and checks for achievement unlocks.
      Parameters:
      key - the name of the statistic to increment
    • incrementStatistic

      public void incrementStatistic(String key, int amount)
      Increments a statistic by a specific amount and checks for achievement unlocks.
      Parameters:
      key - the name of the statistic to increment
      amount - the amount to increment by