Beispiel #1
0
        public bool LoadLevel()
        {
            Initialize();

            _filename = "Level_" + _filename;

            //Open a storage container
            _result = _storagedevice.BeginOpenContainer("Level", null, null);

            //Wait for the WaitHandle to become signaled
            _result.AsyncWaitHandle.WaitOne();

            StorageContainer container = _storagedevice.EndOpenContainer(_result);

            //Close the wait handle.
            _result.AsyncWaitHandle.Close();

            _filename = _filename + ".sav";

            //Check to see whether the save exists.
            if (!container.FileExists(_filename))
            {
                //If not, dispose of the container an return.
                container.Dispose();
                return false;
            }

            //Open the file.
            Stream stream = container.OpenFile(_filename, FileMode.Open);

            XmlSerializer serializer = new XmlSerializer(typeof(GameLevelData));

            _level = (GameLevelData)serializer.Deserialize(stream);

            //Close the file.
            stream.Close();

            //Dispose the Container.
            container.Dispose();

            return true;
        }