示例#1
0
 public bool ManageHighScores(HighScoreRecord record)
 {
     if (HighScores.Count == 10)
     {
         if (HighScores[9].GuessingTime > record.GuessingTime)
         {
             HighScores.Add(record);
             HighScores = HighScores.OrderBy(record => record.GuessingTime).ToList();
             HighScores.RemoveAt(10);
             WriteRecords(HighScores);
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         HighScores.Add(record);
         HighScores = HighScores.OrderBy(record => record.GuessingTime).ToList();
         WriteRecords(HighScores);
         return(true);
     }
 }
示例#2
0
        /// <summary>
        /// Calculate the high score.
        /// </summary>
        /// <returns></returns>
        string CalculateHighScores()
        {
            // Sort lifetimeStats info
            lifetimeStats.HighScores = lifetimeStats.HighScores.OrderBy(highScoreRecord => highScoreRecord.time).ToList();
            lifetimeStats.HighScores = lifetimeStats.HighScores.OrderByDescending(highScoreRecord => highScoreRecord.difficulty).ToList();

            // Local Declarations
            StringBuilder sb = new StringBuilder();

            // Print info
            sb.AppendLine("--- Lifetime Stats ---");
            sb.AppendLine("Rank\tName\t\tTime\t\tDifficulty\t");
            for (int i = 0; i < lifetimeStats.HighScores.Count; i++)
            {
                HighScoreRecord hs = lifetimeStats.HighScores[i];

                if (i <= 10)
                {
                    sb.AppendLine($"[{i + 1}]\t{hs.name}\t\t{CreateSecondsString(hs.time)}\t\t{hs.difficulty}\t");
                }
            }
            sb.AppendLine();
            sb.AppendLine($"Lifetime win/loss:  {lifetimeStats.LifetimeWins}/{lifetimeStats.LifetimeLosses}");

            return(sb.ToString());
        }
示例#3
0
        /// <summary>Writes information to XML.</summary>
        /// <param name="newFile">The new file.</param>
        /// <param name="info">The information.</param>
        public static async void WriteToXml(IStorageFile newFile, HighScoreRecord info)
        {
            var serializer  = new XmlSerializer(typeof(HighScoreRecord));
            var writeStream = await newFile.OpenStreamForWriteAsync();

            serializer.Serialize(writeStream, info);

            writeStream.Close();
        }
        void StoreStat()
        {
            // Create new score
            HighScoreRecord tmp = new HighScoreRecord(nameFieldBox.Text, time, difficulty);

            lifetimeStats.HighScores.Add(tmp);
            lifetimeStats.LifetimeWins++;

            Util.SerializeOut(lifetimeStats, filePath);
        }
示例#5
0
 public static int Compare(HighScoreRecord a, HighScoreRecord b)
 {
     if (a.score == b.score)
     {
         return(a.name.CompareTo(b.name));
     }
     else
     {
         return(a.score.CompareTo(b.score));
     }
 }
示例#6
0
    public void AddHighScore(float score, string playerName = "Adam")
    {
        var record = new HighScoreRecord {
            PlayerName = playerName,
            Score      = score
        };

        // új eredményt hozzáadjuk a listához, majd a 10 legnagyobb pontszámúból csökkenő sorrendű listát készítünk
        HighScores.Add(record);
        HighScores = HighScores
                     .OrderByDescending(r => r.Score)
                     .Take(10)
                     .ToList();

        SaveHighScores();
    }
    public List <HighScoreRecord> ReturnLadderBoard()
    {
        List <HighScoreRecord> savedLadderBoard = new List <HighScoreRecord>();

        for (int i = 0; i < 5; i++)
        {
            HighScoreRecord tempHighScore = new HighScoreRecord(
                PlayerPrefs.GetString("Player" + i, "___"),
                PlayerPrefs.GetInt("Score" + i, 0)
                );


            savedLadderBoard.Add(tempHighScore);
        }

        return(savedLadderBoard);
    }
示例#8
0
        /// <summary>
        ///     Writes the high score to file.
        /// </summary>
        /// <param name="info">The information object.</param>
        public static async void FindFileAndWriteHighScoreToFile(HighScoreRecord info)
        {
            try
            {
                var savePicker = new FileSavePicker();
                savePicker.FileTypeChoices.Add("xml", new List <string> {
                    ".xml"
                });
                savePicker.SuggestedFileName = "FroggerHighScores";

                IStorageFile newFile = await savePicker.PickSaveFileAsync();

                WriteToXml(newFile, info);
            }
            catch (IOException)
            {
                //TODO make new file and write xml to it
            }
        }
示例#9
0
 private String FormatScoreRecord(HighScoreRecord score)
 {
     return(String.Format("{0} {1}", score.score, score.name));
 }
 public void RegisterScore(HighScoreRecord currentPlayerScore)
 {
     highScoreRecords.Add(currentPlayerScore);
     SortLadderBoard();
     SaveLadderBoard();
 }