예제 #1
0
    public void AddHighscoreEntry(int score, string name)
    {
        HighscoreEntry highscoreEntry = new HighscoreEntry {
            score = score, name = name
        };

        string     jsonString = PlayerPrefs.GetString("highscoreTable");
        Highscores highscores = JsonUtility.FromJson <Highscores>(jsonString);

        if (highscores == null)
        {
            highscores = new Highscores()
            {
                highscoreEntryList = new List <HighscoreEntry>()
            };
        }

        highscores.highscoreEntryList.Add(highscoreEntry);

        string json = JsonUtility.ToJson(highscores);

        PlayerPrefs.SetString("highscoreTable", json);
        PlayerPrefs.Save();

        RefreshHighscoreTable();
    }
예제 #2
0
    void onPlayerPref()
    {
        string jsonString = PlayerPrefs.GetString("highscoretable");

        highscores = JsonUtility.FromJson <Highscores>(jsonString);

        for (int i = 0; i < highscores.highscoreEntryList.Count; i++)
        {
            for (int j = i + 1; j < highscores.highscoreEntryList.Count; j++)
            {
                if (highscores.highscoreEntryList[j].score > highscores.highscoreEntryList[i].score)
                {
                    HighscoreEntry temp = highscores.highscoreEntryList[i];
                    highscores.highscoreEntryList[i] = highscores.highscoreEntryList[j];
                    highscores.highscoreEntryList[j] = temp;
                }
            }
        }

        highscoreEntryTransformList = new List <Transform>();
        foreach (HighscoreEntry highscoreEntry in highscores.highscoreEntryList)
        {
            CreateHighscoreEntryTransform(highscoreEntry, container, highscoreEntryTransformList);
        }
    }
예제 #3
0
    private string getMainText(List <HighscoreEntry> currentEntries, HighscoreEntry newEntry)
    {
        int _case = 0;

        if (currentEntries != null && currentEntries.Count > 0)
        {
            HighscoreEntry bestRun = currentEntries[0];
            _case = newEntry.CompareTo(bestRun) < 0 ? 1 : 2;
        }
        int    minutes = (int)(newEntry.playTime % 3600); minutes = (int)(minutes / 60);
        int    seconds = (int)(newEntry.playTime % 60);
        string text    = "Die künstliche Intelligenz hat die Simulation ";

        text += _case == 0 ? "das erste Mal " : "";
        text += "mit einer Zeit von " + minutes + " Minuten und " + seconds + " Sekunden ";
        text += _case == 0 ? "erfolgreich " : "";
        text += "abgeschlossen";
        if (_case == 0)
        {
            text += ". Es werden weitere Simulationen durchgeführt, um die Effizienz weiter zu steigern.";
        }
        else if (_case == 1)
        {
            text += " und sich dabei im Vergleich zuvor weiterentwickelt. Diese Daten werden genutzt, um neue Simulationen durchzuführen und die Effizienz weiter zu steigern.";
        }
        else if (_case == 2)
        {
            text += " und ist dabei im Vergleich zuvor degeneriert. Die Daten werden zurückgesetzt, um weiteren Schaden zu vermeiden.";
        }
        return(text);
    }
예제 #4
0
    private void AddHighscoreEntry(int score, string name)
    {
        // Create HighscoreEntry
        HighscoreEntry highscoreEntry = new HighscoreEntry {
            score = score, name = name
        };

        // Load saved Highscores
        string     jsonString = PlayerPrefs.GetString("highscoreTable");
        Highscores highscores = JsonUtility.FromJson <Highscores>(jsonString);


        if (highscores == null)
        {
            // There's no stored table, initialize
            highscores = new Highscores()
            {
                highscoreEntryList = new List <HighscoreEntry>()
            };
        }

        // Add new entry to Highscores
        highscores.highscoreEntryList.Add(highscoreEntry);

        // Save updated Highscores
        string json = JsonUtility.ToJson(highscores);

        PlayerPrefs.SetString("highscoreTable", json);
        PlayerPrefs.Save();
    }
예제 #5
0
    public void AddNewEntry(int pos, HighscoreEntry entry)
    {
        highscores.highscoreEntryList.Insert(pos, entry);

        //INSERT RECORD INTO DATABASE
        StartCoroutine(InsertScore(entry.name, entry.score));
    }
예제 #6
0
    private void CreateHighscoreEntryTransform(HighscoreEntry highscoreEntry, Transform container, List <Transform> transformList)
    {
        float templateHeight = 40f;

        Transform     entryTransform     = Instantiate(entryTemplate, container);
        RectTransform entryRectTransform = entryTransform.GetComponent <RectTransform>();

        entryRectTransform.anchoredPosition = new Vector2(0, -templateHeight * transformList.Count);
        entryTransform.gameObject.SetActive(true);

        int    rank = transformList.Count + 1;
        string rankString;

        switch (rank)
        {
        default:
            rankString = rank + "TH"; break;

        case 1: rankString = "1ST"; break;

        case 2: rankString = "2ND"; break;

        case 3: rankString = "3RD"; break;
        }

        entryTransform.Find("posText").GetComponent <Text>().text = rankString;
        int score = highscoreEntry.score;

        entryTransform.Find("scoreText").GetComponent <Text>().text = score.ToString();
        string name = highscoreEntry.name;

        entryTransform.Find("nameText").GetComponent <Text>().text = name;

        transformList.Add(entryTransform);
    }
예제 #7
0
    public HighscoreEntry AddHighscore(int level, float time)
    {
        Debug.Log("Add Highscore " + level + "/" + time);

        var entry = Highscores.Find(q => q.Level == level);

        if (entry != null)
        {
            entry.Tries++;
            entry.HasWon++;

            if (entry.Time > time)
            {
                entry.Time = time;
            }
        }
        else
        {
            entry = new HighscoreEntry()
            {
                Level  = level,
                Time   = time,
                Tries  = 1,
                HasWon = 1
            };

            Highscores.Add(entry);
        }

        SaveHighscore();

        return(entry);
    }
예제 #8
0
    private void Start()
    {
        _instance = this;
        entryTemplate.gameObject.SetActive(false);

        string     jsonString = PlayerPrefs.GetString("highscoreTable");
        Highscores highscores = JsonUtility.FromJson <Highscores>(jsonString);

        for (int i = 0; i < highscores.highscoreEntryList.Count; i++)
        {
            for (int j = i + 1; j < highscores.highscoreEntryList.Count; j++)
            {
                if (highscores.highscoreEntryList[j].score < highscores.highscoreEntryList[i].score)
                {
                    HighscoreEntry tmp = highscores.highscoreEntryList[i];
                    highscores.highscoreEntryList[i] = highscores.highscoreEntryList[j];
                    highscores.highscoreEntryList[j] = tmp;
                }
            }
        }

        highscoreEntryTransformList = new List <Transform>();
        foreach (HighscoreEntry highscoreEntry in highscores.highscoreEntryList)
        {
            CreateHighscoreEntryTransform(highscoreEntry, entryContainer, highscoreEntryTransformList);
        }
    }
예제 #9
0
    private void CreateHighscoreEntryTransform(HighscoreEntry highscoreEntry, Transform container, List <Transform> transformList)
    {
        float         templateHeight     = 50f;
        Transform     entryTransform     = Instantiate(entryTemplate, container);
        RectTransform entryRectTransform = entryTransform.GetComponent <RectTransform>();

        entryRectTransform.anchoredPosition = new Vector2(0, -templateHeight * transformList.Count);
        entryTransform.gameObject.SetActive(true);

        int rank = transformList.Count + 1;

        entryTransform.Find("PositionText").GetComponent <Text>().text = rank.ToString();

        int score = highscoreEntry.score;

        entryTransform.Find("ScoreText").GetComponent <Text>().text = score.ToString();

        string name = highscoreEntry.name;

        entryTransform.Find("NameText").GetComponent <Text>().text = name;

        float time     = highscoreEntry.time;
        float seconds  = (time % 60);
        float minutes  = ((int)time / 60) % 60;
        char  splitter = ':';

        entryTransform.Find("TimeText").GetComponent <Text>().text = minutes.ToString("00") + splitter + seconds.ToString("00");

        transformList.Add(entryTransform);
    }
    public void AddHighscoreEntry(float score, string name)
    {
        HighscoreEntry highscoreEntry = new HighscoreEntry {
            score = score, name = name
        };

        //Load saved Highscores
        string     jsonString = PlayerPrefs.GetString("highscoreTable");
        Highscores highscores = JsonUtility.FromJson <Highscores>(jsonString);

        if (highscores == null)
        {
            highscores = new Highscores();
            highscores.highscoreEntryList = new List <HighscoreEntry>();
        }

        //Add new entry to Highscores
        highscores.highscoreEntryList.Add(highscoreEntry);

        //Save updates Highscores
        string json = JsonUtility.ToJson(highscores);

        PlayerPrefs.SetString("highscoreTable", json);
        PlayerPrefs.Save();
    }
예제 #11
0
 public HighscoreEntry(HighscoreEntry entry)
 {
     name    = entry.name;
     time    = entry.time;
     strokes = entry.strokes;
     points  = CalculatePoints(entry.time, entry.strokes);
 }
예제 #12
0
    //Adds a highscoreEntry to the existing list
    public static void AddEntry(HighscoreEntry highscoreEntry)
    {
        HighscoreSaveData savedScores = GetSavedScores();

        bool scoreAdded = false;

        for (int i = 0; i < savedScores.highscoreList.Count; i++)
        {
            if (highscoreEntry.entryScore > savedScores.highscoreList[i].entryScore)
            {
                savedScores.highscoreList.Insert(i, highscoreEntry);
                scoreAdded = true;
                break;
            }
        }

        if (!scoreAdded && savedScores.highscoreList.Count < maxEntryLimit)
        {
            savedScores.highscoreList.Add(highscoreEntry);
        }

        if (savedScores.highscoreList.Count > maxEntryLimit)
        {
            savedScores.highscoreList.RemoveRange(maxEntryLimit, savedScores.highscoreList.Count - maxEntryLimit);
        }
        SaveScores(savedScores);
    }
예제 #13
0
    public void SubmitEntry()
    {
        if (playerInput.text == "")
        {
            return;
        }
        HighscoreEntry entry = new HighscoreEntry {
            highScore = PointHandeler.GetScore(), name = playerInput.text
        };

        CalculateNewHighscore(entry);
        for (int i = 0; i < entries.Count; i++)
        {
            HighscoreEntry currentEntry = new HighscoreEntry {
                highScore = int.Parse(entries[i].Find("ScoreTab").GetComponent <Text>().text),
                name      = entries[i].Find("NameTab").GetComponent <Text>().text
            };
            highscoreEntryList.Add(currentEntry);
        }
        Highscores highscores = new Highscores {
            highscoreEntryList = highscoreEntryList
        };
        string json = JsonUtility.ToJson(highscores);

        PlayerPrefs.SetString("highscoreTable", json);
        PlayerPrefs.Save();
        inputWindow.SetActive(false);
    }
예제 #14
0
        public void Run()
        {
            Console.Clear();
            Console.WriteLine("Podaj swoje imie:");
            var name = Console.ReadLine();

            bool result;

            do
            {
                Console.Write("Zgadnij: ");
                var bet = Console.ReadLine();

                result = _game.Guess(bet, out var answer);

                Console.WriteLine(answer);
            } while (!result);

            Console.WriteLine($"Wynik: {_game.Result}");

            if (_scoreManager == null)
            {
                return;
            }

            var highscoreEntry = new HighscoreEntry(name, _game.Result);

            _scoreManager.Add(highscoreEntry);

            Console.WriteLine("\nNAJLEPSZE WYNIKI:");
            foreach (var entry in _scoreManager.List())
            {
                Console.WriteLine(entry);
            }
        }
예제 #15
0
    public HighscoreEntry AddTry(int level)
    {
        Debug.Log("Add Try " + level);

        var entry = Highscores.Find(q => q.Level == level);

        if (entry != null)
        {
            entry.Tries++;
        }
        else
        {
            entry = new HighscoreEntry()
            {
                Level  = level,
                Time   = 0,
                Tries  = 1,
                HasWon = 0
            };

            Highscores.Add(entry);
        }

        SaveHighscore();

        return(entry);
    }
예제 #16
0
    public void AddHighscoreEntry(int score)
    {
        HighscoreEntry highscoreEntry = new HighscoreEntry {
            score = score
        };

        string     jsonString = PlayerPrefs.GetString("HighScoreTable");
        Highscores highscores = JsonUtility.FromJson <Highscores>(jsonString);

        highscores.highscoreEntryList.Add(highscoreEntry);

        highscores.highscoreEntryList.Sort((x, y) => y.score.CompareTo(x.score));

        if (highscores.highscoreEntryList.Count > 10)
        {
            for (int h = highscores.highscoreEntryList.Count; h > 10; h--)
            {
                highscores.highscoreEntryList.RemoveAt(10);
            }
        }

        string json = JsonUtility.ToJson(highscores);

        PlayerPrefs.SetString("HighScoreTable", json);
        PlayerPrefs.Save();
    }
예제 #17
0
    //Do create gameobject for highscore entries
    private void CreateHighscoreEntryTransform(HighscoreEntry entry, Transform parent, List <Transform> transforms)
    {
        var           height    = 30F;
        Transform     transform = Instantiate(template, parent);
        RectTransform rect      = transform.GetComponent <RectTransform>();

        rect.anchoredPosition = new Vector2(0, -height * transforms.Count);
        transform.gameObject.SetActive(true);
        var rank = transforms.Count + 1;
        //Switch statement to turn numbers into ordinals
        string rankString;

        switch (rank)
        {
        case 1:
            rankString = "1ST";
            break;

        case 2:
            rankString = "2ND";
            break;

        case 3:
            rankString = "3RD";
            break;

        default:
            rankString = rank + "TH";
            break;
        }
        ;
        transform.Find("Position").GetComponent <Text>().text = rankString;
        transform.Find("Score").GetComponent <Text>().text    = entry.score.ToString();
        transforms.Add(transform);
    }
예제 #18
0
    public void Awake()
    {
        Scene currentScene = SceneManager.GetActiveScene();

        print(currentScene.name);
        LevelNameSelect = LevelNSelect.ToString();
        print(LevelNameSelect);
        entryContainer = transform.Find("highscoreEntryContainer");

        entryTemplate.gameObject.SetActive(false);

        if (Highscores.Get(0).time == 0)
        {
            // There's no stored table, initialize
            Debug.Log("Initializing table with default values...");
            AddHighscoreEntry(2005001, "Nik");
            AddHighscoreEntry(1010002, "CPU");
            AddHighscoreEntry(0040003, "CP2");
        }

        highscoreEntryTransformList = new List <Transform>();
        for (int i = 0; i < Highscores.Count; i++)
        {
            HighscoreEntry highscoreEntry = Highscores.Get(i);
            CreateHighscoreEntryTransform(highscoreEntry, entryContainer, highscoreEntryTransformList);
        }
    }
예제 #19
0
    private void RefreshHighscoreTable()
    {
        string     jsonString = PlayerPrefs.GetString("highscoreTable");
        Highscores highscores = JsonUtility.FromJson <Highscores>(jsonString);

        // Sort entry list by Score
        for (int i = 0; i < highscores.highscoreEntryList.Count; i++)
        {
            for (int j = i + 1; j < highscores.highscoreEntryList.Count; j++)
            {
                if (highscores.highscoreEntryList[j].score < highscores.highscoreEntryList[i].score)
                {
                    // Swap
                    HighscoreEntry tmp = highscores.highscoreEntryList[i];
                    highscores.highscoreEntryList[i] = highscores.highscoreEntryList[j];
                    highscores.highscoreEntryList[j] = tmp;
                }
            }
        }

        if (highscoreEntryTransformList != null)
        {
            foreach (Transform highscoreEntryTransform in highscoreEntryTransformList)
            {
                Destroy(highscoreEntryTransform.gameObject);
            }
        }

        highscoreEntryTransformList = new List <Transform>();
        foreach (HighscoreEntry highscoreEntry in highscores.highscoreEntryList)
        {
            CreateHighscoreEntryTransform(highscoreEntry, entryContainer, highscoreEntryTransformList);
        }
    }
    private void Awake()
    {
        entryContainer = transform.Find("HighScoreEntryContainer");
        entryTemplate  = entryContainer.Find("HighScoreEntryTemplate");

        entryTemplate.gameObject.SetActive(false);

        string     jsonString = PlayerPrefs.GetString("highscoreTable");
        Highscores highscores = JsonUtility.FromJson <Highscores>(jsonString);

        // Sort entry list by Score
        for (int i = 0; i < highscores.highscoreEntryList.Count; i++)
        {
            for (int j = i + 1; j < highscores.highscoreEntryList.Count; j++)
            {
                if (highscores.highscoreEntryList[j].score > highscores.highscoreEntryList[i].score)
                {
                    // Swap
                    HighscoreEntry tmp = highscores.highscoreEntryList[i];
                    highscores.highscoreEntryList[i] = highscores.highscoreEntryList[j];
                    highscores.highscoreEntryList[j] = tmp;
                }
            }
        }


        highscoreEntryTransformList = new List <Transform>();
        foreach (HighscoreEntry highscoreEntry in highscores.highscoreEntryList)
        {
            CreateHighscoreEntryTransform(highscoreEntry, entryContainer, highscoreEntryTransformList);
        }
    }
예제 #21
0
    private void CreateHighScoreEntryTransform(HighscoreEntry highscoreEntry, Transform container, List <Transform> transformList)
    {
        float         templeHeight       = 50f;
        Transform     entrytransform     = Instantiate(entryTemplate, container);
        RectTransform entryRectTransform = entrytransform.GetComponent <RectTransform>();

        entryRectTransform.anchoredPosition = new Vector2(0, -templeHeight * transformList.Count);
        entrytransform.gameObject.SetActive(true);

        int    rank = transformList.Count + 1;
        string rankString;

        switch (rank)
        {
        default:
            rankString = rank + "th"; break;

        case 1: rankString = "1st"; break;

        case 2: rankString = "2nd"; break;

        case 3: rankString = "3rd"; break;
        }
        float  time  = highscoreEntry.time;
        int    jumps = highscoreEntry.jumps;
        string name  = highscoreEntry.name;

        entrytransform.Find("posText").GetComponent <Text>().text  = rankString;
        entrytransform.Find("nameText").GetComponent <Text>().text = name;
        entrytransform.Find("timeText").GetComponent <Text>().text = time.ToString() + " sec";
        entrytransform.Find("jump").GetComponent <Text>().text     = jumps.ToString();

        entrytransform.Find("background").gameObject.SetActive(rank % 2 == 1);
        transformList.Add(entrytransform);
    }
예제 #22
0
    public void loadData()
    {
        entryContainer = transform.Find("Isi");
        entryTemplate  = entryContainer.Find("ListHighScore");

        string     jsonstring = PlayerPrefs.GetString("HighscoreTable");
        Highscores highscores = JsonUtility.FromJson <Highscores>(jsonstring);

        entryTemplate.gameObject.SetActive(false);

        for (int i = 0; i < highscores.highscoreEntryList.Count; i++)
        {
            for (int j = i + 1; j < highscores.highscoreEntryList.Count; j++)
            {
                if (highscores.highscoreEntryList[j].score > highscores.highscoreEntryList[i].score)
                {
                    HighscoreEntry tmp = highscores.highscoreEntryList[i];
                    highscores.highscoreEntryList[i] = highscores.highscoreEntryList[j];
                    highscores.highscoreEntryList[j] = tmp;
                }
            }
        }
        highscoreEntryTransformList = new List <Transform>();
        foreach (HighscoreEntry highscoreEntry in highscores.highscoreEntryList)
        {
            CreateHighscoreEntryTr(highscoreEntry, entryContainer, highscoreEntryTransformList);
        }
    }
예제 #23
0
    // Add Highscore entry
    public static void AddHighscoreEntry(int score, string name)
    {
        // Create HighscoreEntry
        HighscoreEntry highscoreEntry = new HighscoreEntry {
            score = score, name = name
        };

        // Load saved Highscores
        string     jsonString = PlayerPrefs.GetString("scoreTable");
        Highscores highscores = JsonUtility.FromJson <Highscores>(jsonString);

        // Initialize highscore table if it doesn't exist
        if (highscores == null)
        {
            highscores = new Highscores()
            {
                highscoreEntryList = new List <HighscoreEntry>()
            };
        }

        // Add new entry to Highscores
        highscores.highscoreEntryList.Add(highscoreEntry);

        // Save updated Highscores
        string json = JsonUtility.ToJson(highscores);

        PlayerPrefs.SetString("scoreTable", json);
        PlayerPrefs.Save();
    }
예제 #24
0
    private void CreateHighscoreEntryTransform(HighscoreEntry highscoreEntry, Transform container, List <Transform> transformList)
    {
        float         templateHeight     = 40f;
        Transform     entryTransform     = Instantiate(entryTemplate, container).transform;
        RectTransform entryRectTransform = entryTransform.GetComponent <RectTransform>();

        entryRectTransform.anchoredPosition = new Vector2(0, -templateHeight * transformList.Count);

        int    rank = transformList.Count + 1;
        string rankString;

        switch (rank)
        {
        default: rankString = rank + "th"; break;

        case 1: rankString = "1st"; break;

        case 2: rankString = "2nd"; break;

        case 3: rankString = "3rd"; break;
        }
        entryTransform.Find("Rank").GetComponent <TextMeshProUGUI>().text = rankString;
        int score = highscoreEntry.getScore();

        entryTransform.Find("Score").GetComponent <TextMeshProUGUI>().text = score.ToString();
        string name = highscoreEntry.getName();

        entryTransform.Find("Name").GetComponent <TextMeshProUGUI>().text = name;

        transformList.Add(entryTransform);
    }
예제 #25
0
    private void CreateHighscoreEntryTransform(HighscoreEntry highscoreEntry, Transform container, List <Transform> transformList)
    {
        Transform entryTransform = Instantiate(entryTemplate, container);

        entryTransform.gameObject.SetActive(true);
        entryTransform.localScale = new Vector3(8, 8, 1);

        int    rank = transformList.Count + 1;
        string rankString;

        switch (rank)
        {
        default:
            rankString = rank + "TH"; break;

        case 1: rankString = "1ST"; break;

        case 2: rankString = "2ND"; break;

        case 3: rankString = "3RD"; break;
        }

        entryTransform.Find("PosText").GetComponent <TextMeshProUGUI>().text = rankString;
        int time = highscoreEntry.time;

        entryTransform.Find("TimeText").GetComponent <TextMeshProUGUI>().text = time.ToString("00:00:000");
        string name = highscoreEntry.name;

        entryTransform.Find("NameText").GetComponent <TextMeshProUGUI>().text = name;
        transformList.Add(entryTransform);
    }
예제 #26
0
    public void recordPlayerHS()
    {
        //to do foolprof
        var highscore = new HighscoreEntry()
        {
            name  = inputField.text,
            score = PlayerPrefs.GetFloat("HighScore"),
        };
        var json = JsonConvert.SerializeObject(highscore);

        var response = Unirest.post("http://localhost/highscores")
                       .body(json)
                       .asJson <string>();

        if (response.Code != 200)
        {
            Debug.Log("Something went wrong (responce error)");
            somethingWentWrong.enabled = true;
            recordMyHS.gameObject.SetActive(false);
            return;
        }

        recorded.enabled = true;
        back.gameObject.SetActive(true);
        recordMyHS.gameObject.SetActive(false);

        //else
        //{
        //    somethingWentWrong.enabled = true;
        //    recordMyHS.gameObject.SetActive(false);
        //}
    }
예제 #27
0
    public void GetScoreList()
    {
        entryContainer = transform.Find("highscoreEntryContainer");
        foreach (Transform t in entryContainer)
        {
            GameObject.Destroy(t.gameObject);
        }
        entryTemplate.gameObject.SetActive(false);

        if (Highscores.Get(0).time == 0)
        {
            // There's no stored table, initialize
            Debug.Log("Initializing table with default values...");
            AddHighscoreEntry(2005001, "Nik");
            AddHighscoreEntry(1010002, "CPU");
            AddHighscoreEntry(0040003, "CP2");
        }

        highscoreEntryTransformList = new List <Transform>();
        for (int i = 0; i < Highscores.Count; i++)
        {
            HighscoreEntry highscoreEntry = Highscores.Get(i);
            CreateHighscoreEntryTransform(highscoreEntry, entryContainer, highscoreEntryTransformList);
        }
    }
예제 #28
0
    //Do adding new entry to highscore list
    public void AddHighscoreEntry(int score)
    {
        HighscoreEntry highscoreEntry = new HighscoreEntry(score);
        //fetch json from playerprefs
        string jsonString = PlayerPrefs.GetString("highscoreTable");
        //decompose json into object
        Highscores highscores = JsonUtility.FromJson <Highscores>(jsonString);

        //if fetch failed, make a new object
        if (highscores == null)
        {
            highscores = new Highscores();
        }
        //add entry and then sort the list based on scores
        highscores.highscoreEntries.Add(highscoreEntry);
        highscores.highscoreEntries = highscores.highscoreEntries.OrderByDescending(i => i.score).ToList();
        //prune highscore list to only show top 10
        while (highscores.highscoreEntries.Count > 10)
        {
            highscores.highscoreEntries.RemoveAt(highscores.highscoreEntries.Count - 1);
        }
        //save new highscore table to playerprefs
        string json = JsonUtility.ToJson(highscores);

        PlayerPrefs.SetString("highscoreTable", json);
        PlayerPrefs.Save();
    }
예제 #29
0
    public void AddHighscoreEntry(string gameMode, int score, int enemies, string time, string name)
    {
        gameMode = gameMode + "HighScores";
        // Load saved Highscores
        string     jsonString = PlayerPrefs.GetString(gameMode);
        Highscores highscores = JsonUtility.FromJson <Highscores>(jsonString);

        HighscoreEntry highscoreEntry = new HighscoreEntry {
            score = score, enemies = enemies, time = time, name = name
        };

        // If there isn't a high score list yet, make one
        if (highscores == null)
        {
            // There's no stored table, initialize
            highscores = new Highscores()
            {
                highscoreEntryList = new List <HighscoreEntry>()
            };
        }
        highscores.highscoreEntryList.Add(highscoreEntry);

        // Save updated Highscores
        string json = JsonUtility.ToJson(highscores);

        PlayerPrefs.SetString(gameMode, json);
        PlayerPrefs.Save();
    }
예제 #30
0
    public void OnNameGiven(string playerName)
    {
        int playerScore = SceneController.instance.GetPlayerScore();

        AddHighscoreEntry(playerScore, playerName);

        string     jsonString = PlayerPrefs.GetString("highscoreTable");
        Highscores highscores = JsonUtility.FromJson <Highscores>(jsonString);   // "Decode" from JSON to Object

        // Sort entry list by Score
        for (int i = 0; i < highscores.highscoreEntryList.Count; i++)
        {
            for (int j = i + 1; j < highscores.highscoreEntryList.Count; j++)
            {
                if (highscores.highscoreEntryList[j].score > highscores.highscoreEntryList[i].score)
                {
                    // Swap
                    HighscoreEntry tmp = highscores.highscoreEntryList[i];
                    highscores.highscoreEntryList[i] = highscores.highscoreEntryList[j];
                    highscores.highscoreEntryList[j] = tmp;
                }
            }
        }

        int size = highscores.highscoreEntryList.Count < 12 ? highscores.highscoreEntryList.Count : 12;

        highscoreEntryTransformList = new List <Transform>();
        for (int i = 0; i < size; i++)
        {
            CreateHighscoreEntryTransform(highscores.highscoreEntryList[i], entryContainer, highscoreEntryTransformList);
        }

        textInputCanvas.enabled = false; // not working
    }
	public void fillInEmptyEntries() {
		int emptyEntriesNeeded = Mathf.Abs(mEntries.Count - MAX_HIGH_SCORES);
		for(int i = 0; i < emptyEntriesNeeded; i++) {
			HighscoreEntry entry = new HighscoreEntry("AAA", 0);
			mEntries.Add(entry);
		}
		mEntries.Sort();
	}
예제 #32
0
    public static int addScore(string name, int score)
    {
        HighscoreEntry e = new HighscoreEntry (name, score);

        highscores.Add (e);
        highscores.Sort ((a,b) => b.score - a.score);

        return highscores.IndexOf (e) + 1;
    }
	//See the logs
	public void Test() {
		HighscoreEntry a = new HighscoreEntry ("Janna", 230);
		HighscoreEntry b = new HighscoreEntry ("Mac", 100);
		HighscoreEntry c = new HighscoreEntry ("Doug", 80);
		mEntries = new List<HighscoreEntry>(){a,b,c};
		Save ();
		mEntries.Clear ();
		Load();
		Debug.Log (mEntries.Count);
		for (int i = 0; i < mEntries.Count; i++) {
			Debug.Log ("Score: " + mEntries[i].GetName() + " " + mEntries[i].GetScore());
		}
	}
	public void Load() {
		mEntries.Clear();
		string serializedScores = PlayerPrefs.GetString (PLAYER_PREF_HIGHSCORE_KEY, "");
		if (serializedScores.Length == 0)
			return;
		IList json = (IList) MiniJSON.Json.Deserialize(serializedScores);
		foreach (IDictionary entry in json) {
			String name = entry ["name"].ToString ();
			int score = Convert.ToInt32(entry ["score"]);
			HighscoreEntry newEntry = new HighscoreEntry (name, score);
			mEntries.Add (newEntry);
		}	
		mEntries.Sort ();
		int entryCount = mEntries.Count;
		mEntries.RemoveRange (MAX_HIGH_SCORES, entryCount - MAX_HIGH_SCORES);
	}
        public void ShouldUseCorrectOrder()
        {
            // Arrange
            var list = new HighscoreList();
            var entry1 =  new HighscoreEntry("Simon", 1, DateTime.Now);
            var entry2 =  new HighscoreEntry("Simon", 2, DateTime.Now);

            // Act
            list.Add(entry1);
            list.Add(entry2);

            // Assert
            var enumerator = list.GetEnumerator();
            enumerator.MoveNext();
            Assert.AreSame(entry2, enumerator.Current);
        }
예제 #36
0
    void loadHighscore() {
        if (!File.Exists(Application.persistentDataPath + "/highscore.dat")) {
            Debug.Log("No Highscore to Load");
          
            highscore = new HighscoreEntry[10];
            
            for (int i = 0; i < 10; i++) {
                highscore[i] = new HighscoreEntry("Empty", 0); 
            }

            return;
        }
        
        BinaryFormatter formatter = new BinaryFormatter();

        FileStream file = File.Open(Application.persistentDataPath + "/highscore.dat", FileMode.Open); 
        highscore = (HighscoreEntry[]) formatter.Deserialize(file);
        file.Close();
    }
	public void Load() {
		mEntries.Clear();
		string serializedScores = PlayerPrefs.GetString (PLAYER_PREF_HIGHSCORE_KEY, "");
		//Debug.Log ("Serialized Scores: " + serializedScores);
		if (serializedScores.Length == 0) {
			fillInEmptyEntries ();
			return;
		}
		IList json = (IList) MiniJSON.Json.Deserialize(serializedScores);
		foreach (IDictionary entry in json) {
			String name = entry ["name"].ToString ();
			int score = Convert.ToInt32(entry ["score"]);
			HighscoreEntry newEntry = new HighscoreEntry (name, score);
			mEntries.Add (newEntry);
		}	
		mEntries.Sort ();

		// If there are any empty entries ...
		fillInEmptyEntries ();
	}
        public void ShouldDeepCloneReferences()
        {
            var machine = new PinballMachine();
            var element = new Bumper();
            var entry = new HighscoreEntry("Simon", 1, DateTime.Now);

            machine.Add(element);
            machine.Highscores.Add(entry);
            var copy = machine.Clone() as PinballMachine;

            Assert.AreNotSame(copy, machine);
            Assert.AreNotSame(copy.Balls, machine.Balls);
            Assert.AreNotSame(copy.Highscores, machine.Highscores);
            Assert.AreNotSame(copy.Highscores.First(), machine.Highscores.First());
            Assert.AreNotSame(copy.Layout, machine.Layout);
        }
	public void LoadFakeData() {
		HighscoreEntry a = new HighscoreEntry ("DAG", 3210);
		HighscoreEntry b = new HighscoreEntry ("JON", 2800);
		HighscoreEntry c = new HighscoreEntry ("NIC", 2750);
		HighscoreEntry d = new HighscoreEntry ("DAV", 2100);
		HighscoreEntry e = new HighscoreEntry ("ADM", 1800);
		HighscoreEntry f = new HighscoreEntry ("ADM", 1670);
		HighscoreEntry g = new HighscoreEntry ("ADM", 1670);
		HighscoreEntry h = new HighscoreEntry ("ADM", 1670);
		HighscoreEntry i = new HighscoreEntry ("ADM", 1670);
		HighscoreEntry j = new HighscoreEntry ("ADM", 1670);
		mEntries = new List<HighscoreEntry>(){a,b,c,d,e,f,g,h,i,j};
	}
예제 #40
0
    public bool checkHighscore(int score) {
        loadHighscore();

        for (int i = 0; i < 10; i++) {
            if (highscore[i].score < score) {
                if (i != 9) {
                    continue;
                }
            }
            if (i == 0) {
                return false;
            }

            int rank;

            if (i == 9) {
                rank = i;
            } else {
                rank = i - 1;
            }

            for (int j = 1; j <= rank; j++) {
                highscore[j-1] = highscore[j];
            }
            highscore[rank] = new HighscoreEntry("Player", score);

            saveHighscore();
            
            return true;
        }
        return false;
    }
예제 #41
0
    // ******************************************** START/ UPDATE ********************************************
    void Awake()
    {
        // find components:
        compoPool = Camera.main.GetComponent<Pool>();
        compoHS = Camera.main.GetComponent<HighscoreEntry>();
        compoScoreTextMesh = scoreDisplay.GetComponent<TextMesh>();
        compoLivesTextMesh = livesDisplay.GetComponent<TextMesh>();

        Application.targetFrameRate = 90;
    }
	public void addScore(HighscoreEntry entry) {
		mEntries.Add(entry);
	}