Пример #1
0
 private void AddHighScore(HighScoreEntry entry)
 {
     if (!_highScores.Add(entry))
     {
         Debug.LogWarning("Unable to add high score entry!");
     }
 }
Пример #2
0
    private void CreatHighScoreEntryTransform(HighScoreEntry highscoreEntry, Transform container, List <Transform> transformList)
    {
        float         templateHeight     = 70f;
        Transform     entryTransform     = Instantiate(entryTemplate, container);
        RectTransform entryRectTransform = entryTransform.GetComponent <RectTransform>();

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

        int    position = transformList.Count + 1;
        string posString;

        if (position == 1)
        {
            posString = "1ST";
        }
        else if (position == 2)
        {
            posString = "2ND";
        }
        else if (position == 3)
        {
            posString = "3RD";
        }
        else
        {
            posString = position + "TH";
        }

        entryTransform.Find("Position Text").GetComponent <Text>().text = posString;
        entryTransform.Find("Score Text").GetComponent <Text>().text    = highscoreEntry.score.ToString();
        entryTransform.Find("Name Text").GetComponent <Text>().text     = highscoreEntry.name;
        transformList.Add(entryTransform);
    }
Пример #3
0
    private IEnumerator PostScore(HighScoreEntry score, Keraysera era)
    {
        while (Settings.token == "")
        {
            yield return(null);
        }
        var newScore = JsonUtility.ToJson(score);

        using (var www = UnityWebRequest.Put(uri + era.pokaName + "/" + id + ".json?auth=" + Settings.token, newScore))
        {
            www.uploadHandler = new UploadHandlerRaw(Encoding.UTF8.GetBytes(newScore));
            www.timeout       = 5;
            yield return(www.SendWebRequest());

            if (www.isNetworkError || www.isHttpError)
            {
                if (Time.realtimeSinceStartup - tokenLastFetched > tokenFetchUpdateLimit)
                {
                    StartCoroutine(GetAuth());
                }
                era.onNewTimePosted(NetWorkResponse.NoConnection, "Ei internet-yhteyttä. Aikaasi ei päivitetty online-tietokantaan.");
            }
            else
            {
                era.onNewTimePosted(NetWorkResponse.Success, "Aikasi on päivitetty online-tietokantaan.");
                era.userBestTime = score.time;
            }
        }
    }
        public async Task RemoveEleventhElement()
        {
            var options = new DbContextOptionsBuilder <HighScoreContext>()
                          .UseInMemoryDatabase(databaseName: "HighScores")
                          .Options;

            var databaseContext = new HighScoreContext(options);

            databaseContext.Database.EnsureCreated();

            var service = new HighScoreEntryService(databaseContext);

            for (int i = 0; i < 10; i++)
            {
                await service.AddHighScoreEntryAsync(new HighScoreEntry
                {
                    Points         = i * 10,
                    PlayerInitials = "JD"
                });
            }

            var lastScore = new HighScoreEntry
            {
                Points         = 99999,
                PlayerInitials = "JD"
            };

            await service.AddHighScoreEntryAsync(lastScore);

            Assert.Contains(lastScore, service.GetAllItemsAsync().Result);
        }
Пример #5
0
    public static 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)
        {
            // There's no stored table, initialize
            highscores = new HighScores()
            {
                highscoreEntryList = new List <HighScoreEntry>()
            };
        }

        highscores.highscoreEntryList.Add(highscoreEntry);

        string json = JsonUtility.ToJson(highscores);

        PlayerPrefs.SetString("highscoretable", json);
        PlayerPrefs.Save();
    }
Пример #6
0
    public void SubmitScore()
    {
        bool wasAdded = false;

        //for i if i is < myHighScores
        for (int i = 0; i < myHighScores.Count; i++)
        {
            if (PlayerPrefs.GetFloat("RecentScore") < myHighScores[i].playerScore)
            {
                HighScoreEntry newScore = new HighScoreEntry(nameField.text, PlayerPrefs.GetFloat("RecentScore"));
                myHighScores.Insert(i, newScore);
                wasAdded = true;

                break;
            }
        }

        if (!wasAdded)
        {
            HighScoreEntry newScore = new HighScoreEntry(nameField.text, PlayerPrefs.GetFloat("RecentScore"));
            myHighScores.Add(newScore);
        }

        if (myHighScores.Count > 10)
        {
            myHighScores.RemoveAt(10);
        }

        SaveScore();
        ShowScores();
    }
Пример #7
0
    public void Continue()
    {
        highScoreEntries.Add(new HighScoreEntry {
            entryScore = score, entryName = inputField.text
        });

        // sort
        for (i = 0; i < highScoreEntries.Count; i++)
        {
            for (j = i + 1; j < highScoreEntries.Count; j++)
            {
                if (highScoreEntries[j].entryScore > highScoreEntries[i].entryScore)
                {
                    HighScoreEntry tmp = highScoreEntries[i];
                    highScoreEntries[i] = highScoreEntries[j];
                    highScoreEntries[j] = tmp;
                }
            }
        }

        highScoreEntries.RemoveAt(10);

        for (i = 0; i < highScoreEntries.Count; i++)
        {
            nameArray[i]         = highScoreEntries[i].entryName;
            nameTMPArray[i].text = nameArray[i];
            scoreArray[i]        = highScoreEntries[i].entryScore;
            scoreObjectArray[i].GetComponent <TextMeshProUGUI>().text = scoreArray[i].ToString();
        }

        Save();
        inputCanvas.GetComponent <Canvas>().enabled     = false;
        highScoreCanvas.GetComponent <Canvas>().enabled = true;
    }
Пример #8
0
    public void addHighScoreEntry(string name, int round, int score)
    {
        HighScores     highScores;
        HighScoreEntry highScoreEntry = new HighScoreEntry {
            name = name, round = round, score = score
        };

        string jsonString = PlayerPrefs.GetString("HighScoreTable");
        string json;

        if (string.IsNullOrEmpty(jsonString))
        {
            highScores = new HighScores();
            highScores.highScoreEntryList = new List <HighScoreEntry>();
        }
        else
        {
            highScores = JsonUtility.FromJson <HighScores>(jsonString);
        }

        highScores.highScoreEntryList.Add(highScoreEntry);

        highScores = sortScore(highScores);

        if (highScores.highScoreEntryList.Count > 5)
        {
            highScores.highScoreEntryList.RemoveAt(5);
        }

        json = JsonUtility.ToJson(highScores);

        PlayerPrefs.SetString("HighScoreTable", json);
        PlayerPrefs.Save();
    }
Пример #9
0
    private void CreateHighCoreEntryTransform(HighScoreEntry highScoreEntry, Transform container, List <Transform> transformlist)
    {
        float         templateHeight     = 65f;
        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();

        transformlist.Add(entryTransform);
    }
Пример #10
0
    public void Awake()
    {
        score = GetComponent <ScoreManager>();
        entryTemplate.gameObject.SetActive(false);

        AddHighscoreEntry(100000000, "CMK");

        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)
        {
            CreateHighscoreTransform(highScoreEntry, entryContainer, highscoreEntryTransformList);
        }
    }
Пример #11
0
    public static void AddHighScoreEntry(int Score, string Name)
    {
        /// <summary>
        /// Create new HighScoreEntry
        /// </summary>
        HighScoreEntry highScoreEntry = new HighScoreEntry {
            score = Score, name = Name
        };
        /// <summary>
        /// Get JSON list of the table entries
        /// </summary>
        string jsonString = PlayerPrefs.GetString("highScoreTable");
        /// <summary>
        /// Convert to list HighScores
        /// </summary>
        HighScores highScores = JsonUtility.FromJson <HighScores>(jsonString);

        /// <summary>
        /// Add new entry to the list
        /// </summary>
        highScores.highScoreEntryList.Add(highScoreEntry);
        /// <summary>
        /// Save updated
        /// </summary>
        string json = JsonUtility.ToJson(highScores);

        PlayerPrefs.SetString("highScoreTable", json);
        PlayerPrefs.Save();
    }
    void CreateHighScoreEntryTransform(HighScoreEntry highScoreEntry, List <GameObject> gameObjectList)
    {
        GameObject entryGameObject = Instantiate(entryTemplate, this.transform);

        entryGameObject.transform.position = entryPositions[gameObjectList.Count];


        int    rank = gameObjectList.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;
        }


        entryGameObject.transform.Find("Info").transform.Find("Name").GetComponent <Text>().text         = highScoreEntry.name;
        entryGameObject.transform.Find("Info").transform.Find("Points").GetComponent <Text>().text       = highScoreEntry.score.ToString();
        entryGameObject.transform.Find("Position").transform.Find("Position").GetComponent <Text>().text = rankString;

        gameObjectList.Add(entryGameObject);
    }
Пример #13
0
    private void createList(HighScoreEntry entry, Transform container, List <Transform> transformList)
    {
        Transform     entryTransform     = Instantiate(entryTemp, container);
        RectTransform entryRectTransform = entryTransform.GetComponent <RectTransform>();
        float         templateHeight     = 50f;

        entryRectTransform.anchoredPosition = new Vector2(0, -templateHeight * transformList.Count);
        entryTransform.gameObject.SetActive(true);
        entryTransform.Find("score").GetComponent <Text>().text = entry.score.ToString();
        entryTransform.Find("name").GetComponent <Text>().text  = entry.name.ToString();
        int    pos = transformList.Count + 1;
        string posLabelText;

        switch (pos)
        {
        case 1: posLabelText = "1st"; break;

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

        case 3: posLabelText = "3rd"; break;

        default: posLabelText = pos + "th"; break;
        }
        entryTransform.Find("pos").GetComponent <Text>().text = posLabelText;
        transformList.Add(entryTransform);
    }
Пример #14
0
    private void Awake()
    {
        entryContainer = transform.Find("HighscoreEntryContainer");
        entryTemplate  = entryContainer.Find("HighscoreEntryTemplate");

        entryTemplate.gameObject.SetActive(false);

        scoreS = PlayerPrefs.GetInt("Score");
        if (PlayerPrefs.HasKey("HighscoreTable"))
        {
            string     jsonString = PlayerPrefs.GetString("HighscoreTable");
            Highscores highscores = JsonUtility.FromJson <Highscores>(jsonString);

            highscoreEntryTransformList = new List <Transform>();
            foreach (HighScoreEntry highScoreEntry in highscores.highscoreEntryList)
            {
                CreatingHighscoreEntryTransform(highScoreEntry, entryContainer, highscoreEntryTransformList);
            }
        }
        else
        {
            HighScoreEntry defaultHighscoreEntry = new HighScoreEntry {
                score = 100, name = "AAA"
            };
            string defaultJson = JsonUtility.ToJson(defaultHighscoreEntry);
            PlayerPrefs.SetString("HighscoreTable", defaultJson);
            PlayerPrefs.Save();
        }
    }
Пример #15
0
    public void AddHighscoreEntry(int i_Score)
    {
        //create highscore entry
        HighScoreEntry highscoreEntry = new HighScoreEntry(i_Score);
        // load saved highscores
        string     jsonString = PlayerPrefs.GetString("highscoreTable");
        Highscores highscores = JsonUtility.FromJson <Highscores>(jsonString);

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

        highscores.highscoreEntryList.Add(highscoreEntry);
        //save updated score
        string json = JsonUtility.ToJson(highscores);

        PlayerPrefs.SetString("highscoreTable", json);
        PlayerPrefs.Save();
    }
Пример #16
0
    // Use this for initialization
    void Start()
    {
        GameObject     go = GameObject.Find("HighscoreText");
        HighScoreEntry highScoreEntry;

        //dummy data
        if (_sceneNum == 0)
        {
            highScoreEntry = new HighScoreEntry("Kenney Chann", 20, 20);
            HighScoreManager.getInstance().addHighScore(0, highScoreEntry);
        }
        else if (_sceneNum == 1)
        {
            highScoreEntry = new HighScoreEntry("Kalanarama", 30, 40);
            HighScoreManager.getInstance().addHighScore(0, highScoreEntry);
        }

        List <HighScoreEntry> listForLevel = HighScoreManager.getInstance().getHighScoresForLevel(_sceneNum);

        //error checking
        if (listForLevel.Count == 0)
        {
            go.GetComponent <Text> ().text = "No Objects :C!\n";
        }
        else            //normal case
        {
            string textInput = "";
            foreach (HighScoreEntry entry in listForLevel)
            {
                int totalScore = (int)entry._argueScore + (int)entry._collectScore;
                textInput = textInput + entry._name + "\t Argue Score: " + entry._argueScore + "\t Collectable Score: " + entry._collectScore + "\n";
            }
            go.GetComponent <Text> ().text = textInput;
        }
    }
Пример #17
0
    /*
     * Adding new entry
     * */
    public void AddHighScoreEntry(int score)
    {
        // Create HighScoreEntry
        HighScoreEntry highScoreEntry = new HighScoreEntry {
            score = score
        };

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

        if (highscores == null)
        {
            // If there is no stored table
            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();
    }
Пример #18
0
    private void CreateHighscoreEntryTransform(HighScoreEntry highscore, Transform container, List <Transform> transformList)
    {
        Transform     entryTransform     = Instantiate(entryTemplate, entryContainer);
        RectTransform entryRectTransform = entryTransform.GetComponent <RectTransform>();

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

        Image  Trophy = entryTransform.Find("Trophy").GetComponent <Image>();
        int    rank   = transformList.Count + 1;
        string rankString;

        switch (rank)
        {
        case 1: rankString = "1St"; Trophy.color = new Color32(254, 225, 1, 255); Trophy.enabled = true; break;

        case 2: rankString = "2Nd"; Trophy.color = new Color32(215, 215, 215, 255); Trophy.enabled = true; break;

        case 3: rankString = "3Rd"; Trophy.color = new Color32(130, 74, 2, 255); Trophy.enabled = true; break;

        default: rankString = rank.ToString() + "Th"; break;
        }
        entryTransform.Find("Place").GetComponent <Text>().text = rankString;

        int score = highscore.score;

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

        string name = highscore.name;

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

        transformList.Add(entryTransform);
    }
Пример #19
0
    // ADD ONE ENTRY
    private void CreateEntryTransform(HighScoreEntry highScoreEntry, Transform entryContainer, List <Transform> transformList)
    {
        float         templateHeight     = 25f;
        Transform     entryTransform     = Instantiate(entryTemplate, entryContainer);
        RectTransform entryRectTransform = entryTransform.GetComponent <RectTransform>();

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

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

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

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

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

        default: rankString = rank + "TH"; break;
        }

        int    score = highScoreEntry.score;
        string name  = highScoreEntry.name;

        entryTransform.Find("posText").GetComponent <TextMeshProUGUI>().text   = rankString;
        entryTransform.Find("scoreText").GetComponent <TextMeshProUGUI>().text = score.ToString();
        entryTransform.Find("nameText").GetComponent <TextMeshProUGUI>().text  = name;

        transformList.Add(entryTransform);
    }
Пример #20
0
    private void AddHighScoreEntry(int minutes, int seconds)
    {
        HighScoreEntry highScoreEntry = new HighScoreEntry {
            minutes = minutes, seconds = seconds
        };

        string     jsonString = PlayerPrefs.GetString("HighScoreTable");
        HighScores HighScores = JsonUtility.FromJson <HighScores>(jsonString);
        int        max        = findMax(HighScores.highScoreEntryList);

        if (HighScores.highScoreEntryList[max].minutes == highScoreEntry.minutes)
        {
            if (HighScores.highScoreEntryList[max].seconds > highScoreEntry.seconds)
            {
                HighScores.highScoreEntryList[max] = highScoreEntry;
            }
        }
        else if (HighScores.highScoreEntryList[max].minutes > highScoreEntry.minutes)
        {
            HighScores.highScoreEntryList[max] = highScoreEntry;
        }

        string json = JsonUtility.ToJson(HighScores);

        PlayerPrefs.SetString("HighScoreTable", json);
        PlayerPrefs.Save();
    }
Пример #21
0
    public void addScoreEntry(int Score)
    {
        HighScoreEntry highscoreentry = new HighScoreEntry {
            score = Score
        };

        string a = PlayerPrefs.GetString("scoreplayerfile");

        if (a == "")
        {
            listainicial = new List <HighScoreEntry>()
            {
                new HighScoreEntry {
                    score = Score
                }
            };

            Highscores highscores = new Highscores {
                ClassHighscoreEntrylist = listainicial
            };
            string json = JsonUtility.ToJson(highscores);
            PlayerPrefs.SetString("scoreplayerfile", json);
            PlayerPrefs.Save();
        }
        else
        {
            string     jsonscores = PlayerPrefs.GetString("scoreplayerfile");
            Highscores highscores = JsonUtility.FromJson <Highscores>(jsonscores);
            highscores.ClassHighscoreEntrylist.Add(highscoreentry);

            string json = JsonUtility.ToJson(highscores);
            PlayerPrefs.SetString("scoreplayerfile", json);
            PlayerPrefs.Save();
        }
    }
Пример #22
0
    private void PostNewTime(float time)
    {
        string kone  = Settings.kerayskone.name == "0" ? "Punainen" : Settings.kerayskone.name == "1" ? "Vihreä" : "Violetti";
        var    score = new HighScoreEntry(Settings.username, time, kone);

        HighScoreManager.Instance.PostNewScore(score, Settings.keraysera);
    }
Пример #23
0
        public static async Task Run([QueueTrigger("gamescorequeue")] GameScoreReceivedEvent message,
                                     [Table("HighScores")] CloudTable table,
                                     [SignalR(HubName = "leaderboardhub")] IAsyncCollector <SignalRMessage> signalRMessages,
                                     ILogger log)
        {
            log.LogInformation($"C# Queue trigger function processed: {message.Id}");

            TableOperation retrieve = TableOperation.Retrieve <HighScoreEntry>(message.Score.Game.ToLower(), message.Score.Nickname);
            TableResult    result   = await table.ExecuteAsync(retrieve);

            HighScoreEntry entry = (HighScoreEntry)result.Result ?? new HighScoreEntry()
            {
                PartitionKey = message.Score.Game.ToLower(),
                RowKey       = message.Score.Nickname
            };

            if (entry.Points < message.Score.Points)
            {
                log.LogInformation(entry.Points.ToString());
                entry.ETag   = "*";
                entry.Points = message.Score.Points;

                TableOperation store = TableOperation.InsertOrReplace(entry);
                await table.ExecuteAsync(store);

                await signalRMessages.AddAsync(new SignalRMessage()
                {
                    Target    = "leaderboardUpdated",
                    Arguments = new string[] { },
                });

                await signalRMessages.FlushAsync();
            }
        }
Пример #24
0
    private void AddHighScoreEntry(int score, string name)
    {
        //Create HighScoreEntry
        HighScoreEntry highScoreEntry = new HighScoreEntry {
            score = score, name = name
        };

        //Load saved HighScores
        string     jsonString = System.IO.File.ReadAllText(Application.persistentDataPath + "/TableData.json");
        HighScores highScores = JsonUtility.FromJson <HighScores>(jsonString);

        //Add new entry
        highScores.highScoresEntryList.Add(highScoreEntry);


        _HighScores = new HighScores {
            highScoresEntryList = highScores.highScoresEntryList
        };

        string list = JsonUtility.ToJson(_HighScores);

        Debug.Log(list);

        System.IO.File.WriteAllText(Application.persistentDataPath + "/TableData.json", list);
    }
Пример #25
0
    public void Fill(string songHash, string difficulty, string playingMethod, HighScoreEntry entryToHighlight = null)
    {
        foreach (var line in GetComponentsInChildren <HighScoreLine>())
        {
            GameObject.Destroy(line.gameObject);
        }

        var scores = scoreSystem.GetHighScoresOfSong(songHash, difficulty, playingMethod, MaxScores);

        if (scores.Count > 0)
        {
            content.SetActive(true);
            HighScoreTitle.text = "HIGHSCORES";

            var yOffset = 0.0f;

            for (int i = 0; i < scores.Count; i++)
            {
                var obj = Instantiate(LinePrefab, ScoreLineHolder.transform, false);
                obj.transform.localPosition = new Vector3(0, yOffset, 0);

                var line = obj.GetComponent <HighScoreLine>();
                line.Display(i + 1, scores[i].Score.ToString(), scores[i].Username, entryToHighlight != null && entryToHighlight.Equals(scores[i]));

                line.gameObject.SetActive(true);

                yOffset -= line.GetComponent <RectTransform>().rect.height;
            }
        }
        else
        {
            content.SetActive(false);
        }
    }
Пример #26
0
    private void CreateHighScoreEntryTransform(HighScoreEntry highScoreEntry, Transform container, List <Transform> transformList)
    {
        Transform     entryTransform     = Instantiate(entryTemplate, entryContainer);
        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);
    }
Пример #27
0
    public void AddNewEntry()
    {
        if (entryAdded)
        {
            return;
        }

        HighScoreEntry newEntry = new HighScoreEntry(GetPlayerName(), GetPlayerPoints());
        bool           inserted = false;

        for (int i = 0; i < highScoreList.Count; i++)
        {
            if (highScoreList[i].PointsSmallerThan(newEntry.GetPoints()))
            {
                highScoreList.Insert(i, newEntry);
                inserted = true;
                break;
            }
        }
        if (!inserted)
        {
            highScoreList.Add(newEntry);
        }
        DisplayHighScoreList();
        SaveHighScoreList();
        entryAdded = true;
    }
Пример #28
0
    private void AddHighScoreEntry(int score, string name)
    {
        // Create entry
        HighScoreEntry highScoreEntry = new HighScoreEntry {
            score = score, name = name
        };

        // Load saved highscores
        string     jsonString = PlayerPrefs.GetString("HighScoreTable");
        HighScores highScores = JsonUtility.FromJson <HighScores>(jsonString);

        // If no table create one
        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("HighScoreTable", json);
        PlayerPrefs.Save();
    }
Пример #29
0
    //make and spawn highscore data on screen
    private void CreateHighScoreEntryGObj(HighScoreEntry highScoreEntry, GameObject container, List <GameObject> gObjList)
    {
        float         height             = 40;
        GameObject    entryGObj          = (GameObject)Instantiate(ScoreTableTemplate, container.transform);
        RectTransform entryRectTransform = entryGObj.GetComponent <RectTransform>();

        entryRectTransform.anchoredPosition = new Vector2(0, -height * gObjList.Count);
        entryGObj.SetActive(true);

        int    rank       = gObjList.Count + 1;
        string rankString = rank.ToString("D");
        string gemString  = highScoreEntry.gemsDestroyed.ToString();
        string timeString = highScoreEntry.time.ToString("F");

        Transform rankTransform = entryGObj.transform.Find("Rank");

        rankTransform.GetComponent <Text>().text = rankString;

        Transform gemsTransform = entryGObj.transform.Find("Gems");

        gemsTransform.GetComponent <Text>().text = gemString;

        Transform timeTransform = entryGObj.transform.Find("Time");

        timeTransform.GetComponent <Text>().text = timeString;

        gObjList.Add(entryGObj);
    }
Пример #30
0
    private void Awake()
    {
        entryContainer = transform.Find("HighScoreEntryContainer");
        entryTemplate  = entryContainer.Find("HighScoreEntryTemplate");

        entryTemplate.gameObject.SetActive(false);

        highScoreEntryList = new List <HighScoreEntry>()
        {
            new HighScoreEntry {
                score = 521854, name = "AAA"
            },
            new HighScoreEntry {
                score = 358462, name = "ANN"
            },
            new HighScoreEntry {
                score = 785123, name = "CAT"
            },
            new HighScoreEntry {
                score = 15524, name = "JON"
            },
            new HighScoreEntry {
                score = 897621, name = "JOE"
            },
            new HighScoreEntry {
                score = 68245, name = "MIK"
            },
            new HighScoreEntry {
                score = 872931, name = "DAV"
            },
            new HighScoreEntry {
                score = 542024, name = "MAX"
            },
        };

        for (int i = 0; i < highScoreEntryList.Count; i++)
        {
            for (int j = i + 1; j < highScoreEntryList.Count; j++)
            {
                if (highScoreEntryList[j].score > highScoreEntryList[i].score)
                {
                    HighScoreEntry tmp = highScoreEntryList[i];
                    highScoreEntryList[i] = highScoreEntryList[j];
                    highScoreEntryList[j] = tmp;
                }
            }
            highScoreEntryTransformList = new List <Transform>();

            foreach (HighScoreEntry highScoreEntry in highScoreEntryList)
            {
                CreateHighScoreEntryTransform(highScoreEntry, entryContainer, highScoreEntryTransformList);
            }


            JsonUtility.ToJson(highScoreEntryList);
            PlayerPrefs.SetString("highscoreTable", "100");
            PlayerPrefs.Save();
            Debug.Log(PlayerPrefs.GetString("highscoreTable"));
        }
    }
        /// <summary>
        /// Set the game objects collection to display the high score table
        /// </summary>
        /// <param name="highlightEntry">If a new score has been added, pass its entry here and it will be highlighted</param>
        private void ResetHighscoreTableDisplay(HighScoreEntry highlightEntry)
        {
            // Add the title
            GameObjects.Add(new TextObject(_game, _game.Fonts["Miramonte"], new Vector2(_game.GraphicsDevice.Viewport.Bounds.Width / 2, 150), "High Scores", TextObject.TextAlignment.Center, TextObject.TextAlignment.Far));

            // Add the score objects
            _game.HighScores.CreateTextObjectsForTable("Normal", _game.Fonts["Miramonte"], 1f, 200, 45, Color.Gold, Color.LightGray, highlightEntry, Color.Orange);
        }
Пример #32
0
        internal HighScoreEntry AddEntry(string name, int score, DateTime date)
        {
            HighScoreEntry entry = new HighScoreEntry();
            entry.Name = name;
            entry.Score = score;
            entry.Date = date;

            _scoreEntries.Add(entry);

            _scoreEntries.Sort(new HighScoreEntry());

            if (_scoreEntries.Count > _tableSize) {
                _scoreEntries.RemoveAt(_tableSize);
            }

            if (_scoreEntries.Contains(entry)) {
                return entry;
            }

            return null;
        }
        /// <summary>
        /// An internal overload of AddEntry which also allows the entry date
        /// to be specified. This is used when loading the scores from the
        /// storage file.
        /// </summary>
        internal HighScoreEntry AddEntry(string name, int score, DateTime date)
        {
            // Create and initialize a new highscore entry
            HighScoreEntry entry = new HighScoreEntry();
            entry.Name = name;
            entry.Score = score;
            entry.Date = date;

            // Add to the table
            _scoreEntries.Add(entry);

            // Sort into descending order
            _scoreEntries.Sort(new HighScoreEntry());

            // Limit the number of entries to the requested table size
            if (_scoreEntries.Count > _tableSize)
            {
                _scoreEntries.RemoveAt(_tableSize);
            }

            // Is our entry still in the list
            if (_scoreEntries.Contains(entry))
            {
                // Yes, so return the entry object
                return entry;
            }
            // No, so return null
            return null;
        }
        //        protected SpriteTile _cubeIcon;
        //        protected SpriteTile _scoreIcon;
        //        protected SpriteTile _timeIcon;
        // CONSTRUCTOR ------------------------------------------
        public InfiniteModeScreen(MenuSystemScene pMenuSystem)
        {
            MenuSystem = pMenuSystem;

            var map = Crystallography.UI.FontManager.Instance.GetMap( Crystallography.UI.FontManager.Instance.GetInGame("Bariol", 25, "Bold") );

            _bestCubes = _bestPoints = 0;
            _bestTime = 0.0f;

            _timeLimitText = new Label() {
                FontMap = map,
                Color = Colors.Black
            };
            //			_timeLimitText.RegisterPalette(0);
            this.AddChild(_timeLimitText);

            timeLimitSlider = new Slider(540) {
                Text = "time limit",
                Position = new Vector2(33.0f, 440.0f),
                max = 60.0f,
                min = 5.0f,
                discreteOptions = new List<float>() { 5.0f, 10.0f, 20.0f, 35.0f, 60.0f },
                OnChange = (unused) => {
                    if ( timeLimitSlider.Value != timeLimitSlider.max ) {
                        _timeLimitText.Text = timeLimitSlider.Value.ToString() + " minutes";
                        _bestTitleText.Text = _timeLimitText.Text;
                        if(_highScoreEntries != null) {
            //							_highScoreEntries[0].ShowBestTime(false);
                            _highScoreEntries[0].BestCubes = DataStorage.timedCubes[timeLimitSlider.SelectedOption,0,0];
                            _highScoreEntries[0].BestPoints = DataStorage.timedScores[timeLimitSlider.SelectedOption,0,1];
                        }
                    } else {
                        _timeLimitText.Text = "infinite";
                        if(_highScoreEntries != null) {
            //							_highScoreEntries[0].ShowBestTime(true);

                            _highScoreEntries[0].BestCubes = DataStorage.infiniteCubes[0,0];
                            _highScoreEntries[0].BestPoints = DataStorage.infiniteScores[0,1];
            //							_highScoreEntries[0].BestTime = DataStorage.infiniteTimes[0,2];
                        }
                    }
                }
            };
            timeLimitSlider.AddTickmarks();
            timeLimitSlider.RegisterPalette(2);
            timeLimitSlider.SetSliderValue( (float)DataStorage.options[4] );
            this.AddChild(timeLimitSlider);

            //			_timeLimitText.Position = new Vector2(timeLimitSlider.Position.X + timeLimitSlider.Length + 20.0f, timeLimitSlider.Position.Y);
            _timeLimitText.Position = new Vector2(timeLimitSlider.Position.X + 4.0f, timeLimitSlider.Position.Y - 41.0f);

            //			_fourthQualityText = new Label() {
            //				FontMap = map
            //			};
            //			_fourthQualityText.RegisterPalette(1);
            //			this.AddChild(_fourthQualityText);

            //			fourthQualitySlider = new Slider() {
            //				Text = "fourth quality",
            //				Position = new Vector2(timeLimitSlider.Position.X, timeLimitSlider.Position.Y - 100.0f),
            //				max = 2.0f,
            //				min = 0.0f,
            //				discreteOptions = new List<float>() { 0.0f, 1.0f, 2.0f },
            //				OnChange = (unused) => {
            //					switch(fourthQualitySlider.Value.ToString("#0.#")) {
            //					case("0"):
            //						_fourthQualityText.Text = "none";
            //						break;
            //					case("1"):
            //						_fourthQualityText.Text = "particles";
            //						break;
            //					case("2"):
            //						_fourthQualityText.Text = "sound";
            //						break;
            //					}
            //				}
            //			};
            //			fourthQualitySlider.AddTickmarks();
            //			fourthQualitySlider.RegisterPalette(1);
            //			fourthQualitySlider.SetSliderValue( 1.0f );
            ////			this.AddChild(fourthQualitySlider);
            //
            //			_fourthQualityText.Position = new Vector2(fourthQualitySlider.Position.X + fourthQualitySlider.Length + 20.0f, fourthQualitySlider.Position.Y);
            //
            _fourthQualityTitle = new Label() {
                Text = "bonus quality",
                FontMap = Crystallography.UI.FontManager.Instance.GetMap( Crystallography.UI.FontManager.Instance.GetInGame("Bariol", 32, "Bold") ),
                Position = new Vector2(33.0f, 326.0f),
                Color = Colors.Black
            };
            this.AddChild(_fourthQualityTitle);

            _buttonHighlight = Support.UnicolorSprite("Black", 0,0,0,255);
            _buttonHighlight.Scale = new Vector2(10.8125f, 12.125f);
            this.AddChild(_buttonHighlight);

            _soundButton = new BetterButton(173.0f, 176.0f) {
                Text = "sound",
                TextFont = FontManager.Instance.GetInGame("Bariol", 25, "Bold"),
                Icon = Support.TiledSpriteFromFile("/Application/assets/images/icons/icons.png", 4, 2),
                IconAndTextOffset = new Vector2(31.0f, 17.0f),
                TextOffset = new Vector2(-58.0f, -50.0f),
                Position = new Vector2(33.0f, 109.0f)
            };
            _soundButton.Icon.TileIndex1D = 4;
            _soundButton.background.RegisterPalette(0);
            _soundButton.Icon.Color = LevelManager.Instance.BackgroundColor;
            this.AddChild(_soundButton);

            _particleButton = new BetterButton(173.0f, 176.0f) {
                Text = "particles",
                TextFont = FontManager.Instance.GetInGame("Bariol", 25, "Bold"),
                Icon = Support.TiledSpriteFromFile("/Application/assets/images/icons/icons.png", 4, 2),
                IconAndTextOffset = new Vector2(31.0f, 17.0f),
                TextOffset = new Vector2(-58.0f, -50.0f),
                Position = new Vector2(216.0f, 109.0f)
            };
            _particleButton.Icon.TileIndex1D = 2;
            _particleButton.background.RegisterPalette(1);
            _particleButton.Icon.Color = LevelManager.Instance.BackgroundColor;
            this.AddChild(_particleButton);

            _noneButton = new BetterButton(173.0f, 176.0f) {
                Text = "none",
                TextFont = FontManager.Instance.GetInGame("Bariol", 25, "Bold"),
                Icon = Support.TiledSpriteFromFile("/Application/assets/images/icons/icons.png", 4, 2),
                IconAndTextOffset = new Vector2(31.0f, 17.0f),
                TextOffset = new Vector2(-64.0f, -50.0f),
                Position = new Vector2(399.0f, 109.0f)
            };
            _noneButton.Icon.TileIndex1D = 6;
            _noneButton.background.RegisterPalette(2);
            this.AddChild(_noneButton);

            _instructionsButton = new BetterButton(362.0f, 62.0f) {
                Text = "instructions",
                Position = Vector2.Zero
            };
            _instructionsButton.background.RegisterPalette(2);
            this.AddChild(_instructionsButton);

            _bestBG = Support.UnicolorSprite("black", 0,0,0,255);
            _bestBG.Position = new Vector2(598.0f, 0.0f);
            _bestBG.Scale = new Vector2(22.625f, 34.0f);
            this.AddChild(_bestBG);

            _bestTitleText = new Label() {
                Text = _timeLimitText.Text,
                FontMap = Crystallography.UI.FontManager.Instance.GetMap( Crystallography.UI.FontManager.Instance.GetInGame("Bariol", 32, "Bold") ),
                Position = new Vector2(_bestBG.Position.X + 41.0f, 465.0f)
            };
            //			_bestTitleText.RegisterPalette(2);
            _bestTitleText.Color = LevelManager.Instance.BackgroundColor;
            this.AddChild(_bestTitleText);

            _highScoreEntries = new HighScoreEntry[3];
            _highScoreEntries[0] = new HighScoreEntry() {
                BestCubes = DataStorage.infiniteCubes[0,0],
                BestPoints = DataStorage.infiniteCubes[0,1],
            //				BestTime = (float)DataStorage.infiniteCubes[0,2],
                Position = new Vector2(_bestTitleText.Position.X, _bestTitleText.Position.Y - 316.0f)
            };
            //			_highScoreEntries[1] = new HighScoreEntry() {
            //				BestCubes = DataStorage.infiniteScores[0,0],
            //				BestPoints = DataStorage.infiniteScores[0,1],
            //				BestTime = (float)DataStorage.infiniteScores[0,2],
            //				Position = new Vector2(_bestTitleText.Position.X, _bestTitleText.Position.Y - 120)
            //			};
            //			_highScoreEntries[2] = new HighScoreEntry() {
            //				BestCubes = DataStorage.infiniteTimes[0,0],
            //				BestPoints = DataStorage.infiniteTimes[0,1],
            //				BestTime = (float)DataStorage.infiniteTimes[0,2],
            //				Position = new Vector2(_bestTitleText.Position.X, _bestTitleText.Position.Y - 180)
            //			};
            //			for(int i=0; i<3; i++){
            //				this.AddChild(_highScoreEntries[i]);
            //			}
            this.AddChild(_highScoreEntries[0]);

            cancelButton = new BetterButton(362.0f, 62.0f) {
                Text = "main menu",
                Position = new Vector2(598.0f, 62.0f)
            };
            cancelButton.background.RegisterPalette(1);
            this.AddChild(cancelButton);

            playButton = new BetterButton(362.0f, 62.0f) {
                Text = "play",
                Position = new Vector2(598.0f, 0.0f)
            };
            playButton.background.RegisterPalette(0);
            this.AddChild(playButton);

            _instructionsPanel = new ChallengeModeInstructionsPanel();
            this.AddChild(_instructionsPanel);
        }
        /// <summary>
        /// Create a series of TextObjects to represent the scores in the specified table
        /// </summary>
        /// <param name="tableName">The name of the table whose scores are to be displayed</param>
        /// <param name="font">The font to use for the score objects</param>
        /// <param name="scale">A scaling factor for the text</param>
        /// <param name="top">The coordinate for the topmost text item</param>
        /// <param name="height">The height of each score item</param>
        /// <param name="firstColor">The color for the topmost item in the table</param>
        /// <param name="lastColor">The color for the final item in the table</param>
        /// <param name="highlightEntry">An entry to highlight in the table (e.g., a newly-added item)</param>
        /// <param name="highlightColor">The color for the highlighted entry</param>
        public void CreateTextObjectsForTable(string TableName, SpriteFont font, float scale, float top, float height, Color firstColor, Color lastColor, HighScoreEntry highlightEntry, Color highlightColor)
        {
            HighScoreTable table;
            int entryCount;
            float yPosition;
            TextObject textObject;
            Color entryColor;
            
            table = GetTable(TableName);

            entryCount = table.Entries.Count;
            for (int i = 0; i < entryCount; i++)
            {
                // Find the vertical position for the entry
                yPosition = top + (height * i);

                // Find the color for the entry
                if (table.Entries[i] == highlightEntry)
                {
                    entryColor = highlightColor;
                }
                else
                {
                    entryColor = new Color(Vector3.Lerp(firstColor.ToVector3(), lastColor.ToVector3(), (float)i / entryCount));
                }

                // Create and add a text item for the position and name
                textObject = new TextObject(_game, font, new Vector2(_game.GraphicsDevice.Viewport.Width/2-200, yPosition), (i + 1).ToString() + ". " + table.Entries[i].Name);
                textObject.Scale = new Vector2(scale);
                textObject.SpriteColor = entryColor;
                _game.GameObjects.Add(textObject);
                // Create and add a text item for the score
                textObject = new TextObject(_game, font, new Vector2(_game.GraphicsDevice.Viewport.Width/2 + 200, yPosition), table.Entries[i].Score.ToString(), TextObject.TextAlignment.Far, TextObject.TextAlignment.Near);
                textObject.Scale = new Vector2(scale);
                textObject.SpriteColor = entryColor;
                _game.GameObjects.Add(textObject);
            }

        }