Пример #1
0
        /// <summary>
        /// Load
        /// </summary>
        public static void Load(int level)
        {
            String filename = "Content" + _levelPathPrefix + level.ToString() + ".xml";
            FileStream file = FileHelper.LoadGameContentFile(filename);

            // If the file is empty, just create a new file with the default
            // settings.
            if (file == null || file.Length == 0)
            {
                throw new Exception("Not yet finished.");
            }
            else
            {
                // Load everything into this class with the help of
                // the xmlserializer
                LevelData loadedLevelData = null;
                loadedLevelData =
                    (LevelData)new XmlSerializer(typeof(LevelData)).Deserialize(file);

                if (loadedLevelData != null)
                {
                    Level loadedLevel = new Level(loadedLevelData, level);
                    _currentLevel = loadedLevel;
                }
                else
                {
                    // Can this even happen if exceptions
                    // are handled?
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Save
        /// </summary>
        public static void Save(Level level, int levelN)
        {
            String filename = _levelPathPrefix + levelN.ToString() + ".xml";
            FileStream file = FileHelper.SaveGameContentFile(
                filename);

            // Save everything in this class with help from the XmlSerializer
            new XmlSerializer(typeof(Level)).Serialize(file, level);

            file.Close();
        }