Exemplo n.º 1
0
        /// <summary>
        /// Publishes the current <see cref="LevelCompletionInfo.LevelScore"/> to the HighScores list in the parameter
        /// </summary>
        /// <param name="info"></param>
        public void PublishScore(LevelCompletionInfo info)
        {
            if (info.HighScores == null)
            {
                info.HighScores    = new int[10];
                info.HighScores[0] = info.LevelScore;
                return;
            }
            bool applied = false, overwriting = false;

            while (!applied)
            {
                for (int i = 0; i < info.HighScores.Length; i++)
                {
                    if (info.HighScores[i] == 0 || info.HighScores[i] == info.LevelScore ||
                        (overwriting && info.HighScores[i] < info.LevelScore))
                    {
                        info.HighScores[i] = info.LevelScore;
                        applied            = true;
                        break;
                    }
                }
                if (!applied)
                {
                    overwriting = true;
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Pushes the <see cref="LevelCompletionInfo"/> to the <see cref="LevelInfo"/> collection. Call <see cref="Save"/> to save changes to file
 /// </summary>
 /// <param name="NewInfo">The data to update in <see cref="LevelInfo"/>. LevelWorldName must be set or else an exception will be thrown. </param>
 public void UpdateInfo(LevelCompletionInfo NewInfo)
 {
     if (NewInfo.LevelWorldName == null)
     {
         throw new Exception("Error in updating save file. LevelWorldName is not set properly.");
     }
     if (LevelInfo.ContainsKey(NewInfo.LevelWorldName))
     {
         LevelInfo.Remove(NewInfo.LevelWorldName);
     }
     PublishScore(NewInfo);
     LevelInfo.Add(NewInfo.LevelWorldName, NewInfo);
 }