Exemplo n.º 1
0
 protected override void Initialize()
 {
     Directory.CreateDirectory(AppDirectory);
     Settings = FileManager.LoadSettings(SettingsPath);
     Scores   = FileManager.LoadHighscores(ScoresPath);
     CompressScores(); // TODO temp solution (see below)
     MySqlHelper.Instance.Sync(this);
     FileManager.SaveHighscores(ScoresPath, Scores);
     if (Settings == null)
     {
         Settings = CreateDefaultSettings();
     }
     base.Initialize();
 }
Exemplo n.º 2
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);
            }
        }