/// <summary>
        ///     Save the top five players that are holded in the scoreboard instance to file.
        /// </summary>
        /// <param name="memento">Instance of scoreboard that holds information about the top five players.</param>
        public void SaveRecordsToFile(ScoreboardMemento memento)
        {
            string encodedFile = Encoder.GetEncodedFile(memento);

            // Display file so it can be written in and hide it again
            File.SetAttributes(FilePath, File.GetAttributes(FilePath) & ~FileAttributes.Hidden);
            File.WriteAllText(FilePath, encodedFile);
            File.SetAttributes(FilePath, File.GetAttributes(FilePath) | FileAttributes.Hidden);
        }
        /// <summary>
        ///     Save the top five players that are holded in the scoreboard instance to file.
        /// </summary>
        /// <param name="memento">Instance of scoreboard that holds information about the top five players.</param>
        public void SaveRecordsToFile(ScoreboardMemento memento)
        {
            string encodedFile = Encoder.GetEncodedFile(memento);

            // Display file so it can be written in and hide it again
            File.SetAttributes(FilePath, File.GetAttributes(FilePath) & ~FileAttributes.Hidden);
            File.WriteAllText(FilePath, encodedFile);
            File.SetAttributes(FilePath, File.GetAttributes(FilePath) | FileAttributes.Hidden);
        }
Esempio n. 3
0
        internal static string GetEncodedFile(ScoreboardMemento memento)
        {
            string[] lines = memento.TopFiveRecords
                             .Select(p => p.PlayerName + "=" + p.Score)
                             .ToArray();

            string[] encodedLines = new string[lines.Length];
            for (int i = 0; i < lines.Length; i++)
            {
                encodedLines[i] = Base64Encode(lines[i]);
            }

            string encodedFile = Base64Encode(string.Join(Environment.NewLine, encodedLines));

            return(encodedFile);
        }
        internal static string GetEncodedFile(ScoreboardMemento memento)
        {
            string[] lines = memento.TopFiveRecords
             .Select(p => p.PlayerName + "=" + p.Score)
             .ToArray();

            string[] encodedLines = new string[lines.Length];
            for (int i = 0; i < lines.Length; i++)
            {
                encodedLines[i] = Base64Encode(lines[i]);
            }

            string encodedFile = Base64Encode(string.Join(Environment.NewLine, encodedLines));

            return encodedFile;
        }