Beispiel #1
0
        // TODO can now be simplified alot since
        // duplicate names are not allowed anymore
        public int AddHighscore(Highscore score, out Highscore kicked)
        {
            Highscore lastSpot = null;
            bool      spotFound = false;
            int       curPos = 1, lastPos = 1;

            kicked = null;

            Scores.Where(s => s.Difficulty == score.Difficulty).ToList().ForEach(s => {
                if (score <= s)
                {
                    spotFound = true;
                }
                if (!spotFound)
                {
                    ++curPos;
                }
                lastSpot = s;
                ++lastPos;
            });

            if (curPos < lastPos &&
                lastPos > MAX_SCORES_PER_DIFF)
            {
                Scores.Remove(lastSpot);
                kicked = lastSpot;
            }

            if (curPos <= MAX_SCORES_PER_DIFF &&
                !Scores.Contains(score))
            {
                Scores.Add(score);
            }

            return(curPos);
        }
Beispiel #2
0
        public int AddHighscore(Highscore score)
        {
            Highscore kicked;

            return(AddHighscore(score, out kicked));
        }
Beispiel #3
0
 public GameOverView(MapView parent, Highscore score) : base(parent)
 {
     this.score = score;
     // Init(); // called automatically after added to a manager
 }
Beispiel #4
0
 public void RemoveHighscore(Highscore score)
 {
     Scores.Remove(score);
 }
Beispiel #5
0
        private void SaveScores(TextField nameField, LayoutPane pane)
        {
            MapDifficulty diff = Game.Settings.Difficulty;

            score.Name = nameField.Text;

            int              p    = 1;
            Highscore        best = null;
            List <Highscore> dups = new List <Highscore>();
            var              it   = Game.ScoresOf(diff).GetEnumerator();

            for (it.MoveNext(); it.Current != null; it.MoveNext())
            {
                if (it.Current.Name.Equals(score.Name))
                {
                    if (best == null)
                    {
                        best = it.Current;
                    }
                    else
                    {
                        dups.Add(it.Current);
                    }
                }

                if (best == null)
                {
                    ++p;
                }
            }

            if (score == best)
            {
                Task.Run(() => {
                    mainPane.Remove(pane);
                    dups.ForEach(Game.RemoveHighscore);
                    FileManager.SaveHighscores(Game.ScoresPath, Game.Scores);
                    MySqlHelper.Instance.Sync(Game);
                    mainPane.Add(CreateNavPane());
                });
            }
            else
            {
                Game.Scores.Remove(score);
                if (kicked != null)
                {
                    Game.Scores.Add(kicked);
                }
                var ti = new TextItem(font, string.Format("A better score by {0} already exists at Rank {1}.", best.Name, p));
                var fp = new FadingPane(2000);
                fp.HGrow  = fp.VGrow = 1;
                ti.HAlign = HAlignment.Center;
                ti.VAlign = VAlignment.Center;
                fp.Add(ti);

                fp.FadedOut += (s, a) => {
                    mainPane.Remove(fp);
                    mainPane.Add(CreateNavPane());
                };

                mainPane.Remove(pane);
                mainPane.Add(fp);
            }
        }