Ejemplo n.º 1
0
        private void HentUsers()
        {
            foreach (User user in Shared.Users)
            {
                HighScores.Add(new Highscore(1, user.Username, user.HighScore));
            }

            HighScores.Sort((x, y) => x.Score.CompareTo(y.Score));
            int rankCounter = 1;

            foreach (Highscore user in HighScores)
            {
                user.Rank = rankCounter;
                rankCounter++;
            }

            //List<Highscore> SortedHighScores = HighScores.OrderBy(o => o.Rank).ToList();

            //Highscore tempHighScore = new Highscore(1000, "Dummy", 1000);
            //int j = HighScores.Count+1;
            //for (int i = 1; i < j; i++)
            //{
            //   tempHighScore = new Highscore(1000, "Dummy", 1000);
            //   foreach (Highscore obj in HighScores)
            //   {
            //      if (obj.Score < tempHighScore.Score)
            //      {
            //         tempHighScore = obj;
            //      }
            //   }
            //   SortedHighScores.Add(new Highscore(i, tempHighScore.Name, tempHighScore.Score));
            //   HighScores.Remove(tempHighScore);
            //}
        }
Ejemplo n.º 2
0
 public void added_20_scores_to_highscores_result_10_scores()
 {
     var highScores = new HighScores();
     for (int i = 0; i < 20; i++)
     {
         highScores.Add(new Score(i));
     }
     Assert.AreEqual(10, highScores.Count());
 }
Ejemplo n.º 3
0
 public void added_20_scores_to_highscores_result_10_scores()
 {
     var highScores = new HighScores();
     for (int i = 0; i < 20; i++)
     {
         highScores.Add(new Score(i.ToString(CultureInfo.InvariantCulture), i));
     }
     Assert.AreEqual(10, highScores.Count());
 }
Ejemplo n.º 4
0
        public void highscore_cleared_highscore_is_empty()
        {
            var highScores = new HighScores();
            for (int i = 0; i < 20; i++)
            {
                highScores.Add(new Score(i));
            }
            highScores.Clear();

            CollectionAssert.IsEmpty(highScores);
        }
Ejemplo n.º 5
0
        public void highscore_cleared_highscore_is_empty()
        {
            var highScores = new HighScores();
            for (int i = 0; i < 20; i++)
            {
                highScores.Add(new Score(i.ToString(CultureInfo.InvariantCulture), i));
            }
            highScores.Clear();

            CollectionAssert.IsEmpty(highScores);
        }
Ejemplo n.º 6
0
    public bool Add(string player, int score)
    {
        if (!CanBeAdded(score))
        {
            return(false);
        }

        m_highScores.Add(player, score);

        NotifyListeners();
        return(true);
    }
Ejemplo n.º 7
0
        private void OnEnable()
        {
            MyScore = new ExampleScore
            {
                IsSelf   = true,
                Score    = UnityEngine.Random.Range(100, 1000),
                Username = Options.UserName
            };

            HighScores.Add(MyScore);

            StartCoroutine(NewScoreAsync());
        }
Ejemplo n.º 8
0
        public void only_highest_scores_are_stored_in_highscores()
        {
            var highScores = new HighScores();
            var randomGenerator = new Random();
            var generatedNumbers = new List<int>();
            for (int i = 0; i < 20; i++)
            {
                var number = randomGenerator.Next();
                highScores.Add(new Score(number));
                generatedNumbers.Add(number);
            }

            Assert.AreEqual(generatedNumbers.OrderByDescending(x => x).Take(10).Min(), highScores.Min().Points);
        }
Ejemplo n.º 9
0
        private void SetScoreInfo(ScoreInfo scoreInfo)
        {
            var lastScoreInfo = currentScoreInfo;

            currentScoreInfo = scoreInfo;
            lastTime         = 0;
            dispatcher.Invoke((Action)(() =>
            {
                ResetZoom();
                HighScores.Clear();
                WebHighScores.Clear();
                HighScores.Add(new KeyValuePair <DateTime, int>(XMinimum, scoreInfo.UserHighScore));
                HighScores.Add(new KeyValuePair <DateTime, int>(XMaximum, scoreInfo.UserHighScore));
                WebHighScores.Add(new KeyValuePair <DateTime, int>(XMinimum, scoreInfo.WebHighScore));
                WebHighScores.Add(new KeyValuePair <DateTime, int>(XMaximum, scoreInfo.WebHighScore));
                Score = CoolCount = GoodCount = SafeCount = SadCount = WorstCount = 0;
                UserHighScore = scoreInfo.UserHighScore;
                WebHighScore = scoreInfo.WebHighScore;
                ScoreName = currentScoreInfo.ScoreName;
                Difficulty = currentScoreInfo.Difficulty;
                if (lastScoreInfo != null && lastScoreInfo.ScoreHashAsString != currentScoreInfo.ScoreHashAsString)
                {
                    BestScores = null;
                    bestResult = ExpansionDatabase.Instance.FindResult(currentScoreInfo.ScoreHashAsString);
                    if (bestResult != null)
                    {
                        BestScores = new ObservableCollection <KeyValuePair <DateTime, int> >(bestResult.Data);
                    }
                    Scores.Clear();
                    Results.Clear();
                }
                else
                {
                    if (isBestScore)
                    {
                        BestScores = Scores;
                        bestResultInfo = currentResultInfo;
                    }
                    Scores = new ObservableCollection <KeyValuePair <DateTime, int> >();
                }
                isBestScore = false;
                UpdateScorePercent();
            }));
        }
Ejemplo n.º 10
0
        private IEnumerator NewScoreAsync()
        {
            for (var i = 0; i < 100; i++)
            {
                if (!enabled)
                {
                    yield break;
                }

                var score = new ExampleScore
                {
                    IsSelf   = false,
                    Score    = UnityEngine.Random.Range(100, 1000),
                    Username = Random(DemoNames)
                };

                HighScores.Add(score);


                yield return(new WaitForSeconds(1));
            }
        }
Ejemplo n.º 11
0
    public bool addHighScore(float score)
    {
        HighScores.Add(score);
        HighScores.Sort();
        if (HighScores.Count > 5)
        {
            HighScores.RemoveAt(0);
        }
        FileStream file = File.Create(FilePathScores);

        using (BinaryWriter bw = new BinaryWriter(file)) {
            for (int i = 0; i < HighScores.Count; i++)
            {
                bw.Write((double)HighScores[i]);
            }
        }
        if (HighScores[HighScores.Count - 1] == score)
        {
            return(true);
        }
        return(false);
    }
Ejemplo n.º 12
0
 /// <summary>
 /// Stop Tracking the score and add the score to high scores
 /// </summary>
 public void StopTracking()
 {
     tracking = false;
     HighScores.Add(CurrentScore);
 }
Ejemplo n.º 13
0
 public void when_score_added_is_null_then_highscore_throws_argument_exception()
 {
     var highScores = new HighScores();
     Score score = null;
     Assert.Throws<ArgumentNullException>(() => highScores.Add(score));
 }
Ejemplo n.º 14
0
 public void when_score_added_is_lower_than_zero_throws_argument_exception()
 {
     var highScores = new HighScores();
     var score = new Score(-1);
     Assert.Throws<ArgumentException>(() => highScores.Add(score));
 }
Ejemplo n.º 15
0
 public void add_one_score_results_one_score_in_highscores()
 {
     var highScores = new HighScores();
     highScores.Add(new Score(777));
     Assert.AreEqual(1, highScores.Count());
 }
Ejemplo n.º 16
0
    IEnumerator AnimationCoroutine()
    {
        // Assumes the current score is the final score for this user
        int userIndex = highScores.Add(currentScore, "Player " + (highScores.Scores.Count + 1));

        for (int i = 0; i < 10; i++)
        {
            GameObject scoreboardEntry = scoreboardEntries[i];

            GameObject index = scoreboardEntry.transform.Find("Index").gameObject;

            GameObject name = scoreboardEntry.transform.Find("Name").gameObject;

            GameObject score = scoreboardEntry.transform.Find("Score").gameObject;

            // If there is no high score, we leave it blank (users will always get a place at this time)
            if (i < highScores.Scores.Count)
            {
                HighScores.HighScore highScore = highScores.Scores[i];

                name.GetComponent <UnityEngine.UI.Text>().text = highScore.Name;

                score.GetComponent <UnityEngine.UI.Text>().text = FormatScore(highScore.Score);
            }
            else
            {
                index.GetComponent <UnityEngine.UI.Text>().text = "";
                name.GetComponent <UnityEngine.UI.Text>().text  = "";
                score.GetComponent <UnityEngine.UI.Text>().text = "";
            }
        }

        GameObject userEntry;

        if (userIndex >= scoreboardEntries.Length)
        {
            userEntry = scoreboardEntries[scoreboardEntries.Length - 1];
        }
        else
        {
            userEntry = scoreboardEntries[userIndex];
        }

        userScoreboardEntry = userEntry;

        userHighScore = highScores.Scores[userIndex];

        GameObject scoreboardName = userEntry.transform.Find("Name").gameObject;

        GameObject scoreboardScore = userEntry.transform.Find("Score").gameObject;

        GameObject scoreboardIndex = userEntry.transform.Find("Index").gameObject;

        scoreboardName.GetComponent <UnityEngine.UI.Text>().text  = "YOU";
        scoreboardScore.GetComponent <UnityEngine.UI.Text>().text = FormatScore(currentScore);
        scoreboardIndex.GetComponent <UnityEngine.UI.Text>().text = "" + highScores.Scores.Count;

        // We will move the header and user from the bottom to their real positions as we animate
        float headerHeight = scoreboardHeader.transform.localPosition.y;
        float userHeight   = userEntry.transform.localPosition.y;

        // Same as in SetupUI
        float verticalSpacing = resultScale * 1.1f;

        scoreboardHeader.transform.localPosition = new Vector3(scoreboardHeader.transform.localPosition.x, scoreboardEntries[scoreboardEntries.Length - 1].transform.localPosition.y + verticalSpacing, scoreboardHeader.transform.localPosition.z);

        userEntry.transform.localPosition = new Vector3(userEntry.transform.localPosition.x, scoreboardEntries[scoreboardEntries.Length - 1].transform.localPosition.y, userEntry.transform.localPosition.z);

        // TODO: Fix hard transition from center-formatting to right-aligned

        UnityEngine.UI.Text userText = userScore.GetComponent <UnityEngine.UI.Text>();

        Vector2 targetSize = scoreboardScore.GetComponent <UnityEngine.UI.Text>().rectTransform.sizeDelta;

        userText.text = FormatScore(currentScore);

        // Shrink large score and move it towards the scoreboard
        while (true)
        {
            // lerpFactor is redefined for every lerp as Time.deltaTime might change between yields
            float lerpFactor = Time.deltaTime * 2;

            userText.rectTransform.sizeDelta += (targetSize - userText.rectTransform.sizeDelta) * lerpFactor;

            Vector3 diff = (scoreboardScore.transform.position - userScore.transform.position);

            userScore.transform.position += diff * lerpFactor;

            if (Mathf.Abs(diff.y) < 10e-4)
            {
                break;
            }

            yield return(null);
        }

        userScore.SetActive(false);

        scoreboardHeader.SetActive(true);
        userEntry.SetActive(true);

        // Replace shrunk score with scoreboard score (identical appearance)
        SetTextAlpha(scoreboardScore.GetComponent <UnityEngine.UI.Text>(), 1f);

        float shownIndex = highScores.Scores.Count;

        // Slowly move the user's entry as it stands relative the scoreboard
        while (true)
        {
            float lerpFactor      = Time.deltaTime * 2;
            float lerpFactorIndex = Time.deltaTime * 0.5f;

            // Fade in headers and user's entry
            LerpTextAlpha(scoreboardIndex.GetComponent <UnityEngine.UI.Text>(), 1f, lerpFactor);
            LerpTextAlpha(scoreboardName.GetComponent <UnityEngine.UI.Text>(), 1f, lerpFactor);

            foreach (UnityEngine.UI.Text text in scoreboardHeader.GetComponentsInChildren <UnityEngine.UI.Text>())
            {
                LerpTextAlpha(text, 1f, lerpFactor);
            }

            SetTextAlpha(scoreboardIndex.GetComponent <UnityEngine.UI.Text>(), 1f);

            float diffHeader = headerHeight - scoreboardHeader.transform.localPosition.y;

            float mixedLerp = Mathf.Min(diffHeader * 5, 100f) * lerpFactorIndex * 2;

            scoreboardHeader.transform.localPosition += new Vector3(0, mixedLerp, 0);

            // TODO: Sound effect every time the number shown changes?

            float posDiff = userHeight - userEntry.transform.localPosition.y;

            if (shownIndex - 0.5f < 10)
            {
                shownIndex += Mathf.Max((userIndex - shownIndex), -40f) * lerpFactorIndex;

                if (shownIndex < userIndex)
                {
                    shownIndex = userIndex;
                }

                userEntry.transform.localPosition += new Vector3(0, Mathf.Min(posDiff * 5, 100f) * lerpFactorIndex, 0);
            }
            else
            {
                shownIndex += (userIndex - shownIndex) * lerpFactorIndex;
            }

            scoreboardIndex.GetComponent <UnityEngine.UI.Text>().text = string.Format("{0:f0}", shownIndex + 0.5f);

            if (Mathf.Abs(shownIndex - userIndex) < 0.8 && Mathf.Abs(diffHeader) < 10e-1 && Mathf.Abs(posDiff) < 10e-1)
            {
                userEntry.transform.localPosition += new Vector3(0, userHeight - userEntry.transform.localPosition.y, 0);
                break;
            }

            yield return(null);
        }

        // Show all other entries now that we know where the user's is
        for (int i2 = 0; i2 < 10; i2++)
        {
            GameObject scoreboardEntry = scoreboardEntries[i2];

            scoreboardEntry.SetActive(true);
        }

        // Flash continuously for 10 000 frames
        for (int i = 0; i < 10000; i++)
        {
            float lerpFactor = Time.deltaTime * 2;

            // Show all other entries now that we know where the user's is
            if (!IsDisplayingScoreboard)
            {
                for (int i2 = 0; i2 < 10; i2++)
                {
                    GameObject scoreboardEntry = scoreboardEntries[i2];

                    if (scoreboardEntry == userEntry)
                    {
                        continue;
                    }

                    scoreboardEntry.SetActive(true);

                    foreach (UnityEngine.UI.Text text in scoreboardEntry.GetComponentsInChildren <UnityEngine.UI.Text>())
                    {
                        LerpTextAlpha(text, 1f, lerpFactor);

                        if (Mathf.Abs(1 - text.color.a) < 10e-3)
                        {
                            IsDisplayingScoreboard = true;
                        }
                    }
                }
            }

            foreach (UnityEngine.UI.Text text in userEntry.GetComponentsInChildren <UnityEngine.UI.Text>())
            {
                text.color = new Color(text.color.r, text.color.g, text.color.b, text.color.a + (((Mathf.Sin(Time.time * 5) + 1) * 0.25f + 0.5f) - text.color.a) * lerpFactor * 5);
            }

            yield return(null);
        }

        // Set full alpha when stopping the flash
        foreach (UnityEngine.UI.Text text in userEntry.GetComponentsInChildren <UnityEngine.UI.Text>())
        {
            text.color = new Color(text.color.r, text.color.g, text.color.b, 1);
        }

        isAnimating = false;
    }