public async Task <IActionResult> Edit(int id, [Bind("Id,Username,Score")] LeaderBoardEntry leaderBoardEntry)
        {
            if (id != leaderBoardEntry.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(leaderBoardEntry);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!LeaderBoardEntryExists(leaderBoardEntry.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(leaderBoardEntry));
        }
예제 #2
0
    private void Awake()
    {
        entryContainer = transform.Find("leaderboardEntryContainer");
        entryTemplate  = transform.Find("leaderboardEntryTemplate");

        entryTemplate.gameObject.SetActive(false);

        //AddLeaderBoardEntry(10000, "CMK");


        string      jsonString  = PlayerPrefs.GetString("leaderboardTable");
        Leaderboard leaderboard = JsonUtility.FromJson <Leaderboard>(jsonString);

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


        leaderboardEntryTransformList = new List <Transform>();
        foreach (LeaderBoardEntry leaderboardEntry in leaderboard.leaderboardEntryList)
        {
            CreateLeaderBoardEntryTransform(leaderboardEntry, entryContainer, leaderboardEntryTransformList);
        }
    }
        public async Task <IActionResult> Create([Bind("Id,Username,Score")] LeaderBoardEntry leaderBoardEntry)
        {
            if (ModelState.IsValid)
            {
                _context.Add(leaderBoardEntry);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(leaderBoardEntry));
        }
예제 #4
0
        public async Task <IActionResult> Post([FromBody] LeaderBoardEntry value)
        {
            if (value == null || value.Name == null)
            {
                return(BadRequest());
            }
            value.Index = 0;
            Context.Entries.Add(value);
            await Context.SaveChangesAsync();

            return(Created($"api/leaderboard/{value.Index}", value));
        }
예제 #5
0
    public void AddNewScore(string nameValue, int value)
    {
        LeaderBoardEntry entry = new LeaderBoardEntry(nameValue, value);

        leaderBoard.Add(entry);
        leaderBoard.Sort((s1, s2) => - 1 * s1.score.CompareTo(s2.score));
        if (leaderBoard.Count > 5)
        {
            leaderBoard = leaderBoard.GetRange(0, 5);
        }
        GameDataController.gameDataController.Save();
    }
예제 #6
0
    private void CreateLeaderboardEntry(Score s)
    {
        GameObject       newEntry = entriesPool.GetObject();
        LeaderBoardEntry entry    = newEntry.GetComponent <LeaderBoardEntry>();

        entry.enabled = true;

        entry.score.name  = s.name;
        entry.score.score = s.score;

        newEntry.transform.SetParent(contentPanel);
        newEntry.transform.position = new Vector3(newEntry.transform.position.x, newEntry.transform.position.y, -1.0f);
    }
예제 #7
0
    void AddToLeaderboard()
    {
        LeaderBoardEntry p1 = gameObject.AddComponent <LeaderBoardEntry>();

        p1.AddEntry("Player 1", scoreManager.p1Score);

        LeaderBoardEntry p2 = gameObject.AddComponent <LeaderBoardEntry>();

        p2.AddEntry("Player 2", scoreManager.p2Score);

        LeaderboardManager.entries.Add(p1);
        LeaderboardManager.entries.Add(p2);
    }
예제 #8
0
    /// <summary>
    /// check the new score against the board
    /// </summary>
    /// <param name="newEntry"></param>
    public void CheckAgainstLeaderBoard(LeaderBoardEntry newEntry)
    {
        //empty score list, so just add it in
        if (leaderBoards.Count == 0)
        {
            leaderBoards.Add(newEntry);
            SaveScoresToFile();
            return;
        }

        //for future refernce, building bottom  up seems like a bad idea
        for (int i = 0; i < leaderBoards.Count; i++)
        {
            //current score is less than a value on the board, so insert it under that score
            if (leaderBoards[i].finalScore < newEntry.finalScore)
            {
                leaderBoards.Insert(i, newEntry);
                SaveScoresToFile();
                break;
            }
            //if the scores are the same, check by time survived
            if (leaderBoards[i].finalScore == newEntry.finalScore)
            {
                //compare by time Longer is better
                // then do a replace
                if (leaderBoards[i].timeSpent < newEntry.timeSpent)
                {
                    //the new score has a higher time, so put it in the normal place above the score
                    leaderBoards.Insert(i, newEntry);
                    SaveScoresToFile();
                }
                else
                {
                    //the new time is lower, so put keep the existing score in its place
                    leaderBoards.Insert(i++, newEntry);
                    SaveScoresToFile();
                }
                //cull any extra entries from storage
                if (leaderBoards.Count == 11)
                {
                    leaderBoards.RemoveAt(11);
                }
                break;
            }
        }
    }
예제 #9
0
    private void AddLeaderBoardEntry(int score, string name)

    {
        // Create Leaderboardentry
        LeaderBoardEntry leaderboardEntry = new LeaderBoardEntry {
            score = score, name = name
        };

        //Load saved Leaderboard
        string      jsonString  = PlayerPrefs.GetString("leaderboardTable");
        Leaderboard leaderboard = JsonUtility.FromJson <Leaderboard>(jsonString);

        // Add new entry to Leaderboard
        leaderboard.leaderboardEntryList.Add(leaderboardEntry);

        //Save updated Leaderboard
        string json = JsonUtility.ToJson(leaderboard);

        PlayerPrefs.SetString("leaderboardTable", json);
        PlayerPrefs.Save();
    }
예제 #10
0
    private void CreateLeaderBoardEntryTransform(LeaderBoardEntry leaderBoardEntry, Transform container, List <Transform> transformList)
    {
        float         templateHeight     = 30f;
        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 = leaderBoardEntry.score;

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

        string name = leaderBoardEntry.name;

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

        transformList.Add(entryTransform);
    }
예제 #11
0
    /*Function: AddHighScores
     * Purpose: To take the strings laoded from file and input them into the highscore list.
     *
     * Arguments: HighScoresEntry string array
     *
     * Description: create a leaderboardEntry and then take the 2 strings from the string array argument and input string 1
     * 				into the name field of the LeaderboardEntry adn then convert the second string to a int and input that value
     * 				into the leaderboardEntry score field
     */
    private void AddToHighScores(string[] highScoreEntry)
    {
        LeaderBoardEntry temp = new LeaderBoardEntry();

        temp.name = highScoreEntry[0];
        temp.score = Int32.Parse(highScoreEntry[1]);

        highScores.Add(temp);
    }
예제 #12
0
    /*Function: UpdateHighScoreList
     * Purpose: To add the new highscore list entry
     *
     * Arguments: name - score
     *
     * Description: Iterates through the high score list and updates the list of highscores with the new entry
     */
    private void UpdateHighScoreList(string name, int score)
    {
        if (highScores.Count == highScoreMAX)
            highScores.RemoveAt(highScoreMAX - 1);
        LeaderBoardEntry tempEntry = new LeaderBoardEntry();
        tempEntry.name = name;
        tempEntry.score = score;

        if (highScores.Count == 0)
            highScores.Add(tempEntry);

        for (int i = 0; i < highScores.Count; i++)
        {
            if (score > highScores[i].score)
            {
                highScores.Insert(i, tempEntry);
                break;
            }
        }
    }