예제 #1
0
 /** Load any high scores we currently have */
 public void Load()
 {
     InitScore();
       Scores = new Dictionary<int, HighScore>();
       var count = PlayerPrefs.GetInt(HSKeys.HS_RECORD_COUNT);
       for (var i = 0; i < count; ++i) {
     var pnts = PlayerPrefs.GetInt(HSKeys.HS_POINTS_BASE + i);
     var date = PlayerPrefs.GetString(HSKeys.HS_DATE_BASE + i);
     var item = new HighScore() {
       Points = pnts,
       Date = date
     };
     Scores[i] = item;
       }
 }
예제 #2
0
        /** Update score, and save */
        public void Update(int points)
        {
            Load();
              var queue = new Queue<HighScore>();
              var count = Scores.Keys.Count;
              var added = false;
              for (var i = 0; i < count; ++i) {
            if (!added && (Scores [i].Points < points)) {
              var item = new HighScore {
            Points = points,
            Date = DateTime.Now.ToShortDateString()
              };
              queue.Enqueue(item);
              added = true;
            }
            queue.Enqueue(Scores [i]);
              }
              if (!added && (queue.Count < HSKeys.HS_MAX_SCORES)) {
            var item = new HighScore {
              Points = points,
              Date = DateTime.Now.ToShortDateString()
            };
            queue.Enqueue(item);
              }

              Scores = new Dictionary<int, HighScore>();
              var counter = 0;
              while (counter < HSKeys.HS_MAX_SCORES) {
            if (queue.Count > 0) {
              var item = queue.Dequeue();
              Scores[counter] = item;
              ++counter;
            }
            else
              break;
              }

              Save();
        }
예제 #3
0
 /** Returns the style and content for a single high score */
 public static LData ScoreHighscoreItem(HighScore s, int i, int total)
 {
     var factor = 1f - (float)i / (float)total;
       var size = 5f;
       if (nLayout.Distance(100) > Screen.width) {
     size = 3f;
       }
       var st = _fonts.Fixed(size, new Color(0.5f, factor, factor + 0.5f));
       st.alignment = TextAnchor.MiddleCenter;
       return new LData() {
     Msg = String.Format("{1} {0,10} POINTS", s.Points, s.Date),
     Style = st
       };
 }