Пример #1
0
        static void RecUpdate(Score score, int points, string player, int i)
        {
            // Abort recursion
            if (i == score.Scores.Length)
            {
                return;
            }

            // Get to next entry
            if (score.Scores[i].score >= points)
            {
                i++;

                RecUpdate(score, points, player, i);
            }
            // Update entry and arrange entries
            else
            {
                int tmpScore = score.Scores[i].score;
                string tmpName = score.Scores[i].name;

                score.Scores[i].score = points;
                score.Scores[i].name = player;

                i++;
                RecUpdate(score, tmpScore, tmpName, i);
            }
        }
Пример #2
0
        private static void SaveScore(Score score)
        {
            for(int i = 0; i < score.Scores.Length; i++)
            {
                if(score.Scores[i].name != null)
                    score.Scores[i].name = RijndaelSimple.Encrypt(score.Scores[i].name);
            }
            // Create a binary formatter
            IFormatter bformatter = new BinaryFormatter();
            // Create a stream-object and save it as a file
            Stream stream = new FileStream("Score.dat", FileMode.Create, FileAccess.Write, FileShare.None);
            try
            {
                // Serialize
                bformatter.Serialize(stream, score);

                // Close the file
                stream.Close();
            }
            catch (Exception e)
            {
                throw e;
                    //System.Windows.Forms.MessageBox.Show(e.Message, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);

            #if DEBUG
                    Console.WriteLine(e.ToString());
            #endif
            }
        }
Пример #3
0
        public static Score LoadScore()
        {
            // Create a binary formatter
            IFormatter bformatter = new BinaryFormatter();

            try
            {
                // Create a stream-object and open the file
                Stream stream = new FileStream("Score.dat", FileMode.Open, FileAccess.Read, FileShare.Read);

                // Deserialize
                Score score = (Score)bformatter.Deserialize(stream);
                stream.Close();

                for (int i = 0; i < score.Scores.Length; i++)
                {
                    if(score.Scores[i].name != null)
                        score.Scores[i].name = RijndaelSimple.Decrypt(score.Scores[i].name);
                }

                return score;
            }
            catch (Exception e)
            {
            #if DEBUG
                Console.WriteLine(e.ToString());
            #endif
            }

            // Return default score when no data file is found
            Score defaultScore = new Score();

            return defaultScore;
        }