Example #1
0
        static void JSON3()
        {
            string JSONString = "[true]";

            Console.WriteLine($"Input: {JSONString}");

            ReadJSON      readJSON = new ReadJSON();
            List <object> obj      = readJSON.Parser(JSONString);
            Stopwatch     sw       = new Stopwatch();

            sw.Start();
            readJSON.Parser(JSONString);
            sw.Stop();

            Console.WriteLine($"所用时间:{sw.ElapsedMilliseconds} ms");
            Console.WriteLine("[");
            Console.WriteLine($"\t{obj[0]}");
            Console.WriteLine("]");
            Console.WriteLine($"转换为字符串:{WriteJSON.Write(obj)}");
            sw.Start();
            for (int i = 0; i < 100; ++i)
            {
                readJSON.Parser(JSONString);
            }
            sw.Stop();
            Console.WriteLine($"一百次所用时间:{sw.ElapsedMilliseconds} ms");
            Console.ReadKey();
        }
Example #2
0
        static void JSON4()
        {
            string JSONString = "{\"st\tring\": \"\t\t\\t\u1234\"}";

            Console.WriteLine($"Input: {JSONString}");

            ReadJSON readJSON = new ReadJSON();
            Dictionary <string, object> obj = readJSON.Parser(JSONString);
            Stopwatch sw = new Stopwatch();

            sw.Start();
            readJSON.Parser(JSONString);
            sw.Stop();

            Console.WriteLine($"所用时间:{sw.ElapsedMilliseconds} ms");
            Console.WriteLine("{");
            Console.WriteLine($"\t\"st\tring\":\"{obj["st\tring"]}\"");
            Console.WriteLine("}");
            Console.WriteLine($"转换为字符串:{WriteJSON.Write(obj)}");
            sw.Start();
            for (int i = 0; i < 100; ++i)
            {
                readJSON.Parser(JSONString);
            }
            sw.Stop();
            Console.WriteLine($"一百次所用时间:{sw.ElapsedMilliseconds} ms");
            Console.ReadKey();
        }
Example #3
0
        static void JSON2()
        {
            string JSONString = "{\"     Array\":[  \"字符串\", false],      \"number\":   " +
                                "\n\n\n\t\r123, \"dgfsrfe\": null}";

            Console.WriteLine($"Input: {JSONString}");
            ReadJSON readJSON = new ReadJSON();
            Dictionary <string, object> obj = readJSON.Parser(JSONString);
            Stopwatch sw = new Stopwatch();

            sw.Start();
            readJSON.Parser(JSONString);
            sw.Stop();
            Console.WriteLine($"所用时间:{sw.ElapsedMilliseconds} ms");
            Console.WriteLine("{");
            Console.WriteLine("\t\"     Array\": [");
            Console.WriteLine($"\t\t\"{((List<object>)obj["     Array"])[0]}\",");
            Console.WriteLine($"\t\t{((List<object>)obj["     Array"])[1]},");
            Console.WriteLine("\t],");
            Console.WriteLine($"\t\"number\":{obj["number"]},");
            Console.WriteLine($"\t\"dgfsrfe\":{obj["dgfsrfe"] ?? "null"}");
            Console.WriteLine("}");
            Console.WriteLine($"转换为字符串:{WriteJSON.Write(obj)}");
            sw.Start();
            for (int i = 0; i < 100; ++i)
            {
                readJSON.Parser(JSONString);
            }
            sw.Stop();
            Console.WriteLine($"一百次所用时间:{sw.ElapsedMilliseconds} ms");
            Console.ReadKey();
        }
 void Start()
 {
     ReadJson     = new ReadJSON();
     WriteJson    = new WriteJSON();
     ReadTarGzip  = new ReadTARGZIP();
     WriteTarGzip = new WriteTARGZIP();
 }
Example #5
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();
        }
Example #6
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!");
        }
Example #7
0
        public void WriteHighscoreToFile()
        {
            Highscore highscore = AddDebugHighscoreEntries();

            WriteJSON.SaveHighscore(filename, highscore);

            // check if file was created succesfully
            FileAssert.Exists(Application.persistentDataPath + filename,
                              "The highscore couldn't be written to the file: " + Application.persistentDataPath + filename);

            // cleanup
            DeleteTestFiles();
        }
Example #8
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");
        }
    }
Example #9
0
        public void SaveToFile(string filename)
        {
            IWriter writer = new WriteJSON();

            writer.Save(filename, main_data_structure.Groups);
        }