コード例 #1
0
        public void WriteAndLoadHighscore()
        {
            // create highscore
            Highscore highscoreOriginal = AddDebugHighscoreEntries();

            WriteJSON.SaveHighscore(filename, highscoreOriginal);

            // load highscore
            Highscore highscore = WriteJSON.LoadHighscore(filename);

            // check if both highscores have the same amount of entries
            Assert.AreEqual(highscoreOriginal.GetLength(), highscore.GetLength(),
                            "The original highscore and the saved and loaded highscore have different lengths: " + highscoreOriginal.GetLength() + "/" + highscore.GetLength() + ".");

            // check if all highscore entries are equal
            for (int i = 0; i < highscoreOriginal.GetLength(); i++)
            {
                Assert.IsTrue(highscoreOriginal.GetEntry(i).Equals(highscore.GetEntry(i)),
                              "Entry " + i + " differs in the saved and read highscore from the original value. \n" +
                              "original: " + highscoreOriginal.GetEntry(i).ToString() + "\n" +
                              "new     : " + highscore.GetEntry(i).ToString());
            }

            // cleanup
            DeleteTestFiles();
        }
コード例 #2
0
        public void LoadEmptyHighscore()
        {
            Highscore emptyHighscore = WriteJSON.LoadHighscore("");

            // check if highscore is assigned & empty (should be, because the JSON File can't be found)
            Assert.IsNotNull(emptyHighscore,
                             "WriteJSON.LoadHighScore() should return a new highscore when the highscore file can't be found!");
            Assert.AreEqual(emptyHighscore.GetLength(), 0,
                            "WriteJSON.LoadHighScore() should return an empty highscore when the highscore file can't be found!");
        }
コード例 #3
0
    public void PlayerEnteredGoal()
    {
        // stop the game
        stats.timer.PauseTimer();
        controlsTutorial.enabled = false;
        EndscreenUI.SetActive(true);

        // hide the player (so the camera will still center)
        player.GetComponent <MeshRenderer>().enabled     = false;
        player.GetComponent <Rigidbody>().velocity       = Vector3.zero;
        player.GetComponent <Rigidbody>().useGravity     = false;
        player.GetComponent <PlayerController>().enabled = false;
        player.transform.GetChild(0).gameObject.SetActive(false);

        // create highscore entry from current run
        HighscoreEntry entry = new HighscoreEntry("Player", stats.timer.currentTime, stats.hits);

        // add highscore entry to highscore
        Highscore highscore = WriteJSON.LoadHighscore(saveFilename);

        highscore.AddEntry(entry);

        // save new highscore entry to save file
        WriteJSON.SaveHighscore(saveFilename, highscore);

        // clear score board
        for (int i = 0; i < highscoreEntries.Length; i++)
        {
            highscoreEntries[i].transform.GetChild(0).GetComponent <Text>().text = "";
            highscoreEntries[i].transform.GetChild(1).GetComponent <Text>().text = "";
            highscoreEntries[i].transform.GetChild(2).GetComponent <Text>().text = "";
            highscoreEntries[i].transform.GetChild(3).GetComponent <Text>().text = "";
        }

        // get smallest needed max index to draw either all highscore entries (entries < first n entries) or to draw the first n entries
        int maxIndex = (highscore.GetLength() < highscoreEntries.Length) ? highscore.GetLength() : highscoreEntries.Length;

        highscore.Sort();

        // show highscore
        for (int i = 0; i < maxIndex; i++)
        {
            HighscoreEntry highscoreEntry = highscore.GetEntry(i);
            highscoreEntries[i].transform.GetChild(0).GetComponent <Text>().text = highscoreEntry.name;
            highscoreEntries[i].transform.GetChild(1).GetComponent <Text>().text = highscoreEntry.time.ToString("0.00") + " sec";
            highscoreEntries[i].transform.GetChild(2).GetComponent <Text>().text = highscoreEntry.strokes.ToString();
            highscoreEntries[i].transform.GetChild(3).GetComponent <Text>().text = highscoreEntry.points.ToString("0.00");
        }
    }