예제 #1
0
파일: HighScore.cs 프로젝트: Genjo15/Snake
        //Retrieve the leaderboard or create a sample one if none exist
        public static HighScoreData LoadHighScores()
        {
            HighScoreData? hsLoad = HighScore._LoadHighScores();
            HighScoreData sample;
            if (hsLoad.Equals(null))
            {
                sample = new HighScoreData(HighScore.MAX_HighScores);
                sample.PlayerName[0] = "Test";
                sample.Score[0] = 2;
                sample.PlayerName[1] = "JohnTheCrazy";
                sample.Score[1] = 20;
                sample.PlayerName[2] = "Doe";
                sample.Score[2] = 120;
                sample.Count = 3;
                HighScore.SaveHighScores(sample);
            }
            else
            {
                sample = (HighScoreData) hsLoad;
            }

            return sample;
        }
예제 #2
0
파일: HighScore.cs 프로젝트: Genjo15/Snake
 private static void sort(HighScoreData data)
 {
     int maxScoreIndex = 0;
     int oldScore;
     string oldNick;
     for (int i = 0; i < data.Count; i++)
     {
         maxScoreIndex = i;
         for (int j = i; j < data.Count; j++)
         {
             if (data.Score[j] >= data.Score[maxScoreIndex])
             {
                 maxScoreIndex = j;
             }
         }
         oldScore = data.Score[i];
         oldNick = data.PlayerName[i];
         data.PlayerName[i] = data.PlayerName[maxScoreIndex];
         data.Score[i] = data.Score[maxScoreIndex];
         data.PlayerName[maxScoreIndex] = oldNick;
         data.Score[maxScoreIndex] = oldScore;
         Console.Out.WriteLine("dump : dataScore["+i+"]="+data.Score[i]);
     }
 }
예제 #3
0
파일: HighScore.cs 프로젝트: Genjo15/Snake
        public static int SaveHighScores(HighScoreData data)
        {
            HighScore.sort(data);
            int success = 0;
            try
            {
                using (Stream file = new FileStream(HighScoresFilename, FileMode.Create))
                {
                    try
                    {
                        // Convert the object to XML data and put it in the stream
                        XmlSerializer serializer = new XmlSerializer(typeof(HighScoreData));
                        serializer.Serialize(file, data);
                        success = 1;
                    }
                    finally
                    {
                        file.Close();
                    }
                }
            }
            catch (Exception e)
            {
                success = -1;
            }

            return success;
        }