Exemplo n.º 1
0
        private void IsNewHighscoreTest(TestHighscoreListType type, int time, int points, bool isNew)
        {
            Highscore highscore = new Highscore()
            {
                Points     = (uint)points,
                GameTime   = TimeSpan.FromSeconds(time),
                PlayerName = "player"
            };
            var list  = ProvideList((int)type);
            var clone = new List <Highscore>(list);
            ISettingsProvider provider = new TestSettingsProvider();

            provider.Highscores = list;
            provider.Save();
            HighscoreList highscoreList = new HighscoreList(provider);
            bool          b             = highscoreList.IsNewHighscore(highscore);

            Assert.Equal(isNew, b);
            if (isNew)
            {
                highscoreList.AddHighscore(highscore);
            }
            Assert.True(highscoreList.Highscores.Count <= 10);
            if (isNew)
            {
                clone.Add(highscore);
            }
            clone.Sort(new HighscoreComparer());
            clone = clone.Take(10).ToList();
            Assert.Equal(clone.Count, highscoreList.Highscores.Count);
            for (int i = 0; i < list.Count; i++)
            {
                Assert.Equal(clone[i], highscoreList.Highscores[i]);
            }
        }
Exemplo n.º 2
0
 public virtual void SaveHighscore()
 {
     if (!IsHighscore)
     {
         return;
     }
     _highscores.AddHighscore(CreateHighscore());
     Close();
 }
Exemplo n.º 3
0
        /// <summary>
        /// used to submit the highscore of the player
        /// </summary>
        /// <param name="playername">string of the playername</param>
        /// <param name="score">int of the score</param>
        /// <param name="timer">int of the time in seconds</param>
        private void SubmitScore(string playername, int score, int combo, int timer)
        {
            int    minutes = timer / 60;
            string seconds = (timer % 60).ToString();

            if (Int32.Parse(seconds) < 10)
            {
                seconds = "0" + seconds;
            }

            string time = minutes + " : " + seconds;

            singlePlayerScore += score * combo / (1 + minutes);

            highscoreList.AddHighscore(new Highscore(playername, singlePlayerScore, time));
            highscoreList.Save();
        }