Exemple #1
0
        private void TestHighscoreAdd()
        {
            Highscores hs = new Highscores();

            hs.AddHighscore("John", 34000);
            hs.AddHighscore("Mark", 68000);
            hs.AddHighscore("Lewis", 25000);
            Assert.IsTrue(hs.highscorelst.Contains("John") && hs.highscorelst.Contains("34000") && hs.highscorelst.Contains("Mark") && hs.highscorelst.Contains("68000") && hs.highscorelst.Contains("Lewis") && hs.highscorelst.Contains("25000"));
        }
Exemple #2
0
    public void ShouldSortHighscoresByScore()
    {
        var highscores = new Highscores();

        var newScoreOne = HighscoreData.Create(5000, 20);

        Assert.IsTrue(highscores.AddHighscore(newScoreOne));
        Assert.AreEqual(newScoreOne, highscores[0]);
        Assert.AreEqual(highscores.Count, Highscores.maxHighscoreTables);


        var newScoreTwo = HighscoreData.Create(2500, 10);

        Assert.IsTrue(highscores.AddHighscore(newScoreTwo));
        Assert.AreEqual(newScoreOne, highscores[0]);
        Assert.AreEqual(newScoreTwo, highscores[1]);
        Assert.AreEqual(highscores.Count, Highscores.maxHighscoreTables);

        var newScoreThree = HighscoreData.Create(10000, 10);

        Assert.IsTrue(highscores.AddHighscore(newScoreThree));
        Assert.AreEqual(newScoreThree, highscores[0]);
        Assert.AreEqual(newScoreOne, highscores[1]);
        Assert.AreEqual(newScoreTwo, highscores[2]);
        Assert.AreEqual(highscores.Count, Highscores.maxHighscoreTables);

        var newScoreFour = HighscoreData.Create(7500, 30);

        Assert.IsTrue(highscores.AddHighscore(newScoreFour));
        Assert.AreEqual(newScoreThree, highscores[0]);
        Assert.AreEqual(newScoreFour, highscores[1]);
        Assert.AreEqual(newScoreOne, highscores[2]);
        Assert.AreEqual(newScoreTwo, highscores[3]);
        Assert.AreEqual(highscores.Count, Highscores.maxHighscoreTables);

        var newScoreFive = HighscoreData.Create(2000, 30);

        Assert.IsTrue(highscores.AddHighscore(newScoreFive));
        Assert.AreEqual(newScoreThree, highscores[0]);
        Assert.AreEqual(newScoreFour, highscores[1]);
        Assert.AreEqual(newScoreOne, highscores[2]);
        Assert.AreEqual(newScoreTwo, highscores[3]);
        Assert.AreEqual(newScoreFive, highscores[4]);
        Assert.AreEqual(highscores.Count, Highscores.maxHighscoreTables);

        var newScoreSix = HighscoreData.Create(1000, 30);

        // return false when the score wasnt be added
        Assert.IsFalse(highscores.AddHighscore(newScoreFive));
        Assert.AreEqual(newScoreThree, highscores[0]);
        Assert.AreEqual(newScoreFour, highscores[1]);
        Assert.AreEqual(newScoreOne, highscores[2]);
        Assert.AreEqual(newScoreTwo, highscores[3]);
        Assert.AreEqual(newScoreFive, highscores[4]);
        Assert.AreEqual(highscores.Count, Highscores.maxHighscoreTables);
    }
    public void EndGame()
    {
        gameOver.Value = true;

        newHighscoreRank = hs.AddHighscore(gameScore.Value);

        if (newHighscoreRank >= 0)
        {
            // There's a new highscore
            UpdateHighScoresUI();
            highscoresUI.GetComponent <ScreenController>().SetWindowState(true);
        }
        else
        {
            StartCoroutine(StartNewGame());
        }
    }