예제 #1
0
        public ScoreStat add(Scores newscore)
        {
            //ScoreStat curstat;
            if (isLoaded)
            {
                if (newscore.playerScore > 0)
                {
                    var oldscore = scores.FindIndex(s => s.playerName.Equals(newscore.playerName) && s.passkey.Equals(newscore.passkey));
                    if (oldscore > -1)
                    {
                        if (scores[oldscore].playerScore > newscore.playerScore)
                        {
                            return(ScoreStat.NotUpdated);
                        }
                        else
                        {
                            scores[oldscore].playerScore = newscore.playerScore;
                            scores[oldscore].playerTime  = newscore.playerTime;
                            scores = scores.OrderByDescending(s => s.playerScore)
                                     .ThenBy(s => s.playerTime)
                                     .ToList();
                            try { saveScores(); }
                            catch (IOException)
                            { return(ScoreStat.Missing); }

                            return(ScoreStat.Updated);
                        }
                    }
                    else
                    {
                        if (scores.Count() > 40)
                        {
                            if (scores.Last().playerScore > newscore.playerScore)
                            {
                                return(ScoreStat.NoAdd);
                            }
                            else
                            {
                                scores.RemoveAt(scores.Count - 1);
                                scores.Add(newscore);
                                scores = scores.OrderByDescending(s => s.playerScore)
                                         .ThenBy(s => s.playerTime)
                                         .ToList();
                                try { saveScores(); }
                                catch (IOException)
                                { return(ScoreStat.Missing); }

                                return(ScoreStat.NewScore);
                            }
                        }
                        else
                        {
                            scores.Add(newscore);
                            scores = scores.OrderByDescending(s => s.playerScore)
                                     .ThenBy(s => s.playerTime)
                                     .ToList();
                            try { saveScores(); }
                            catch (IOException)
                            { return(ScoreStat.Missing); }

                            return(ScoreStat.NewScore);
                        }
                    }
                }
                else
                {
                    return(ScoreStat.NoAdd);
                }
            }
            else
            {
                return(ScoreStat.Missing);
            }
        }
예제 #2
0
 public int playerPosition(Scores sc)
 {
     return(scores.FindIndex(s => s.Equals(sc)) + 1);
 }