Exemple #1
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="key">Dictionary key name</param>
 /// <param name="value">Level statistics object to store</param>
 public LevelStatisticsItem(string key, LevelStatistics value)
 {
     Key = key;
     Value = value;
 }
Exemple #2
0
        /// <summary>
        /// Update statistics with new data
        /// </summary>
        /// <param name="levelName">Level name</param>
        /// <param name="numberOfSteps">Number of steps taken to complete level</param>
        /// <param name="levelTime">Total time it took to complete level</param>
        public void UpdateLevelStats(string levelName, int numberOfSteps, DateTime levelTime)
        {
            // Check if there's a previous created level statistics item
            LevelStatistics stats;
            if (m_levelStats.ContainsKey(levelName))
            {
                stats = m_levelStats[levelName];
            }
            else
            {
                // Allocate a new item since we didnt have a previous loaded.
                stats = new LevelStatistics();
                stats.numberOfSteps = Int32.MaxValue;
                stats.bestTime = new DateTime();
            }

            // Update level data..
            if((numberOfSteps < stats.numberOfSteps) ||
                (numberOfSteps == stats.numberOfSteps && (levelTime.CompareTo(stats.bestTime) < 0))
                )
            {
                // Player have better stats now, update structure.
                stats.name = levelName;
                stats.numberOfSteps = numberOfSteps;
                stats.bestTime = levelTime;
                m_levelStats[levelName] = stats;
            }

            // Save current stats to file..
            Save();
        }