当前位置: 首页>>代码示例>>C#>>正文


C# StorageDevice.BeginOpenContainer方法代码示例

本文整理汇总了C#中Microsoft.Xna.Framework.Storage.StorageDevice.BeginOpenContainer方法的典型用法代码示例。如果您正苦于以下问题:C# StorageDevice.BeginOpenContainer方法的具体用法?C# StorageDevice.BeginOpenContainer怎么用?C# StorageDevice.BeginOpenContainer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Xna.Framework.Storage.StorageDevice的用法示例。


在下文中一共展示了StorageDevice.BeginOpenContainer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: saveLevel

        void saveLevel(IAsyncResult result)
        {
            SaveLevelData data = new SaveLevelData();
            data.objectList = level.entityList;
            data.currentPosition = level.currentPosition;
            data.multiSelect = level.multiSelect;
            data.upTime = level.upTime;
            data.holdTime = level.holdTime;
            data.filename = level.levelName;

            device = StorageDevice.EndShowSelector(result);
            if (device != null && device.IsConnected)
            {
                IAsyncResult r = device.BeginOpenContainer("MyGamesStorage", null, null);
                result.AsyncWaitHandle.WaitOne();
                StorageContainer container = device.EndOpenContainer(r);
                if (container.FileExists(level.levelName + ".sav"))
                    container.DeleteFile(level.levelName + ".sav");
                Stream stream = container.CreateFile(level.levelName + ".sav");

                XmlSerializer serializer = new XmlSerializer(typeof(SaveLevelData));
                serializer.Serialize(stream, data);
                stream.Close();
                container.Dispose();
                result.AsyncWaitHandle.Close();
            }
        }
开发者ID:oh-team-machine,项目名称:Target-Tapping,代码行数:27,代码来源:saveLevel.cs

示例2: SaveToFile

        private void SaveToFile(IAsyncResult result)
        {
            device = StorageDevice.EndShowSelector(result);

            // Open a storage container.
            IAsyncResult r = device.BeginOpenContainer(containerName, null, null);
            result.AsyncWaitHandle.WaitOne();
            StorageContainer container = device.EndOpenContainer(r);
            result.AsyncWaitHandle.Close();

            // Delete old file and create new one.
            if (container.FileExists(fileName))
            {
                container.DeleteFile(fileName);
            }
            Stream fileStream = container.CreateFile(fileName);

            // Write data to file.
            XmlSerializer serializer = new XmlSerializer(typeof(SaveGameData));
            serializer.Serialize(fileStream, saveGameData);

            // Close file.
            fileStream.Close();
            container.Dispose();
        }
开发者ID:ProfChaos,项目名称:Immunity,代码行数:25,代码来源:StorageHandler.cs

示例3: LoadSaveData

        public void LoadSaveData(StorageDevice device)
        {
            result = device.BeginOpenContainer("Storage", null, null);
            result.AsyncWaitHandle.WaitOne();

            StorageContainer container = device.EndOpenContainer(result);

            result.AsyncWaitHandle.Close();
            string filename = "savegame.sav";

            // Check to see whether the save exists.
            if (!container.FileExists(filename))
            {
                // If not, dispose of the container and return.
                container.Dispose();
                return;
            }
            //Open file.
            Stream stream = container.OpenFile(filename, FileMode.Open);
            XmlSerializer serializer = new XmlSerializer(typeof(SaveGameData));
            loadedData = (SaveGameData)serializer.Deserialize(stream);
            //close file
            stream.Close();
            container.Dispose();
        }
开发者ID:Stanimir-b,项目名称:Youkai,代码行数:25,代码来源:StartMenuScreen.cs

示例4: LoadGame

        /// <summary>
        /// This method gets the filenames from the universal storage file LbKTileData.sav
        /// </summary>
        /// <param name="device"></param>
        /// <param name="gamer"></param>
        /// <param name="fileNamesOnly"></param>
        public static void LoadGame(StorageDevice device, SignedInGamer gamer, bool fileNamesOnly)
        {
            // Open a storage container.
            // name of container is LbK Storage Device
            IAsyncResult result =
                device.BeginOpenContainer(gamer.Gamertag, null, null);

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

            StorageContainer container = device.EndOpenContainer(result);

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

            string filename = "LbKTileData.sav";

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

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

            // Read the data from the file.
            XmlSerializer serializer = new XmlSerializer(typeof(SaveGameData));
            SaveGameData data = (SaveGameData)serializer.Deserialize(file);

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

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

            // Report the data to the console.
            if (fileNamesOnly)
            {
                fileNames = data.Names;
            }
            else
            {
                position = data.TilePosition;
                type = data.TileType;
                objectNumber = data.TileObjectNumber;
                count = data.TileCount;
                fileNames = data.Names;
            }

            GamePlayScreen.storageDevice = device;
            // load up game with respective device
        }
开发者ID:Harmonickey,项目名称:AlexCSPortfolio,代码行数:61,代码来源:LbKStorageLevelCreation.cs

示例5: OpenContainer

        internal static StorageContainer OpenContainer(StorageDevice storageDevice, string saveGameName)
        {
            IAsyncResult result = storageDevice.BeginOpenContainer(saveGameName, null, null);

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

            StorageContainer container = storageDevice.EndOpenContainer(result);

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

            return container;
        }
开发者ID:fanthos,项目名称:Game-Heal,代码行数:14,代码来源:XnaFixes.cs

示例6: LoadGame

        /// <summary>
        /// This method loads a serialized data object
        /// from the StorageContainer for this game.
        /// </summary>
        /// <param name="device"></param>
        public static void LoadGame(StorageDevice device, SignedInGamer gamer)
        {
            // Open a storage container.
            // name of container is LbK Storage Device
            IAsyncResult result =
                device.BeginOpenContainer("LbK Storage Device", null, null);

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

            StorageContainer container = device.EndOpenContainer(result);

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

            string filename = "LbKSavedItems.sav";

            // Check to see whether the save exists.
            if (!container.FileExists(filename))
            {
                // If not, dispose of the container and return.
                container.Dispose();
                nothingLoaded = true;
                return;
            }

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

            // Read the data from the file.
            XmlSerializer serializer = new XmlSerializer(typeof(SaveGameData));
            SaveGameData data = (SaveGameData)serializer.Deserialize(file);

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

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

            // Report the data to the console.
            playerName = data.PlayerName;
            level = data.Level;
            score = data.PlayerScore;
            position = new Vector2(data.playerPosition.X, data.playerPosition.Y);
            checkPoint = data.CheckPoint;

            GamePlayScreen.storageDevice = device;
            // load up game with respective device
        }
开发者ID:Harmonickey,项目名称:AlexCSPortfolio,代码行数:54,代码来源:LbKStorage.cs

示例7: loadGame

        public void loadGame(StorageDevice device)
        {
            Console.WriteLine("loading");
            IAsyncResult result = device.BeginOpenContainer("Container", null, null);
            result.AsyncWaitHandle.WaitOne();
            StorageContainer container = device.EndOpenContainer(result);
            result.AsyncWaitHandle.Close();

            string filename = "savegame.sav";

            if (!container.FileExists(filename))
            {
                container.Dispose();
                return;
            }

            Stream stream = container.OpenFile(filename, FileMode.Open);

            XmlSerializer serializer = new XmlSerializer(typeof(SaveGameData));
            SaveGameData data = (SaveGameData)serializer.Deserialize(stream);

            stream.Close();

            container.Dispose();

            game.getZoneFactory().loadZones(game.getContentHandler(), data.currentPlayerZone);
            game.getZoneFactory().setCurrentZoneFromNumber(data.currentPlayerZone);
            game.getPlayer().setZoneLevel(data.currentPlayerLevel);
            game.getPlayer().setGlobalLocation(data.playerPosition);
            game.getKeyHandler().getMovementHandler().updateDrawLocations(game.getPlayer(), game.getZoneFactory().getCurrentZone());
            game.getPlayer().getStats().setFireEnergy(data.fireEnergy);
            game.getPlayer().getStats().setCurrentFireEnergy(data.currentFireEnergy);
            game.getPlayer().getStats().setWaterEnergy(data.waterEnergy);
            game.getPlayer().getStats().setCurrentWaterEnergy(data.currentWaterEnergy);
            game.getPlayer().getStats().setNatureEnergy(data.natureEnergy);
            game.getPlayer().getStats().setCurrentNatureEnergy(data.currentNatureEnergy);

            Console.WriteLine("Zone number: " + data.currentPlayerZone);
            Console.WriteLine("Player level: " + data.currentPlayerLevel);
            Console.WriteLine("Position: " + data.playerPosition);

            loadRequested = false;
            Console.WriteLine("load completed");

            game.getGameState().setGameState();
            game.getKeyHandler().updateKeys(Keyboard.GetState());
        }
开发者ID:rpallarino3,项目名称:Test2DGame,代码行数:47,代码来源:Game1.cs

示例8: LoadFromDevice

        void LoadFromDevice(IAsyncResult result)
        {
            device = StorageDevice.EndShowSelector(result);
            IAsyncResult r = device.BeginOpenContainer(ContainerName, null, null);
            result.AsyncWaitHandle.WaitOne();
            StorageContainer container = device.EndOpenContainer(r);
            result.AsyncWaitHandle.Close();
            if (container.FileExists(Filename))
            {
                Stream stream = container.OpenFile(Filename, FileMode.Open);
                XmlSerializer serializer = new XmlSerializer(typeof(SaveGame));
                SaveGame SaveData = (SaveGame)serializer.Deserialize(stream);
                stream.Close();
                container.Dispose();
                //Update the game based on the save game file

            }
            Replace();
        }
开发者ID:TDRubikCube,项目名称:RubicCubeMain,代码行数:19,代码来源:save.cs

示例9: LoadFromDevice

        /// <summary>
        /// Loads the save when StorageDevice is ready.
        /// </summary>
        /// <param name="result">gives the StorageDevice to use</param>
        void LoadFromDevice(IAsyncResult result)
        {
            _device = StorageDevice.EndShowSelector(result);
            var r = _device.BeginOpenContainer(containerName, null, null);
            result.AsyncWaitHandle.WaitOne();
            var container = _device.EndOpenContainer(r);
            result.AsyncWaitHandle.Close();
            if (!container.FileExists(filename)) return;

            var stream = container.OpenFile(filename, FileMode.Open);
            var bfm = new BinaryFormatter();
            var saveData = (SaveData)bfm.Deserialize(stream);
            stream.Close();
            container.Dispose();

            //Update the game based on the save game file
            // Hero
            _inGame.Hero.gold = saveData.HeroData.gold;
            _inGame.Hero.Position = saveData.HeroData.Position;
            _inGame.Hero.CurrentMana = saveData.HeroData.CurrentMana;
            _inGame.Hero.CurrentHitPoints = saveData.HeroData.CurrentHitPoints;
            _inGame.Hero.MaxHitPoints = saveData.HeroData.MaxHitPoints;
            _inGame.Hero.MaxMana = saveData.HeroData.MaxMana;
            _inGame.Hero.exp = saveData.HeroData.exp;
            _inGame.Hero.level = saveData.HeroData.level;
            _inGame.Hero.tnl = saveData.HeroData.tnl;

            // mapGrid
            _inGame.mapGrid._tiles = saveData.mapgrid;
            _inGame.mapGrid.Initialize();

            // liveGrid
            _inGame._game.Components.Remove(_inGame.liveGrid);
            _inGame.liveGrid = new LiveGrid(_inGame._game, ref _inGame.mapGrid);
            _inGame._game.Components.Add(_inGame.liveGrid);

            // monsters
            UnserializeMonsters(saveData.MonstersData);

            // missiles
            UnserializeMissiles(saveData.MissilesData);
        }
开发者ID:ArghyV,项目名称:Peliohjelmointi-s2011,代码行数:46,代码来源:SaveGame.cs

示例10: save

        void save(IAsyncResult result)
        {
            device = StorageDevice.EndShowSelector(result);
            if (device != null && device.IsConnected)
            {
                SaveLevelNames data = new SaveLevelNames();
                data.levelName = levelNames;
                data.timeScore = timeScores;
                data.hitsScore = hitsScores;

                IAsyncResult r = device.BeginOpenContainer("MyGamesStorage", null, null);
                StorageContainer container = device.EndOpenContainer(r);
                if (container.FileExists("ListofScores.sav"))
                    container.DeleteFile("ListofScores.sav");
                Stream stream = container.CreateFile("ListofScores.sav");
                XmlSerializer serializer = new XmlSerializer(typeof(SaveLevelNames));
                serializer.Serialize(stream, data);
                stream.Close();
                container.Dispose();
            }
        }
开发者ID:oh-team-machine,项目名称:Target-Tapping,代码行数:21,代码来源:SaveScore.cs

示例11: DoLoadGame

        public void DoLoadGame(StorageDevice device)
        {
            // Open a storage container.
            IAsyncResult result =
                device.BeginOpenContainer("StorageDemo", null, null);

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

            StorageContainer container = device.EndOpenContainer(result);

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

            string filename = "testlevel.txt";

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

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

            // Read the data from the file.
            XmlSerializer serializer = new XmlSerializer(typeof(testidata));
            testidata = (int)serializer.Deserialize(stream);

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

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

            // Report the data to the console.
            Debug.WriteLine("Leveldata: " + testidata);
        }
开发者ID:Kauko,项目名称:fallingGGJ12,代码行数:40,代码来源:LevelLoader.cs

示例12: SaveToDevice

 private void SaveToDevice(IAsyncResult result)
 {
     device = StorageDevice.EndShowSelector(result);
     if (device != null && device.IsConnected)
     {
         SaveGame SaveData = new SaveGame()
         {
             IsFirstTime = false,
         };
     IAsyncResult r = device.BeginOpenContainer(ContainerName,null,null);
     result.AsyncWaitHandle.WaitOne();
     StorageContainer container = device.EndOpenContainer(r);
     if(container.FileExists(Filename))
         container.DeleteFile(Filename);
     Stream stream = container.CreateFile(Filename);
     XmlSerializer serializer = new XmlSerializer(typeof(SaveGame));
     serializer.Serialize(stream,SaveData);
     stream.Close();
     container.Dispose();
     result.AsyncWaitHandle.Close();
     }
 }
开发者ID:TDRubikCube,项目名称:RubicCubeMain,代码行数:22,代码来源:save.cs

示例13: LoadGameState

        /// <summary>
        /// Ładowanie listy zapisanych stanów gry dla danego playera
        /// </summary>
        /// <param name="result">obiekt typu IAsyncResult dający dostęp do XNA Storage</param>
        /// <param name="gameLevel">poziom gry</param>
        /// <returns></returns>
        public static GameStateData LoadGameState(IAsyncResult result,string playerName)
        {
            filename = playerName;
            device = StorageDevice.EndShowSelector(result);

            // Open a storage container.
            IAsyncResult result2 = device.BeginOpenContainer(containerName, null, null);

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

            StorageContainer container = device.EndOpenContainer(result2);

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

            // Check to see whether the save exists.
            if (!container.FileExists(filename))
            {
                container.Dispose();
                return new GameStateData(0);
            }

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

            // Read the data from the file.
            XmlSerializer serializer = new XmlSerializer(typeof(GameStateData));
            GameStateData data = (GameStateData)serializer.Deserialize(stream);

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

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

            //Return SettingsData
            return data;
        }
开发者ID:kuzawskak,项目名称:DungeonVandal,代码行数:45,代码来源:GameState.cs

示例14: loadLevelName

 void loadLevelName(IAsyncResult result)
 {
     device = StorageDevice.EndShowSelector(result);
     IAsyncResult r = device.BeginOpenContainer("MyGamesStorage", null, null);
     StorageContainer container = device.EndOpenContainer(r);
     if (container.FileExists("ListofScores.sav"))
     {
         Stream stream = container.OpenFile("ListofScores.sav", FileMode.Open);
         XmlSerializer serializer = new XmlSerializer(typeof(SaveLevelNames));
         stream.Seek(0, SeekOrigin.Begin);
         SaveLevelNames data = (SaveLevelNames)serializer.Deserialize(stream);
         levelNames = data.levelName;
         timeScores = data.timeScore;
         hitsScores = data.hitsScore;
         stream.Close();
         container.Dispose();
     }
     else
     {
         check = false;
     }
 }
开发者ID:oh-team-machine,项目名称:Target-Tapping,代码行数:22,代码来源:SaveScore.cs

示例15: loadLevel

 void loadLevel(IAsyncResult result)
 {
     device = StorageDevice.EndShowSelector(result);
     IAsyncResult r = device.BeginOpenContainer("MyGamesStorage", null, null);
     result.AsyncWaitHandle.WaitOne();
     StorageContainer container = device.EndOpenContainer(r);
     result.AsyncWaitHandle.Close();
     if (container.FileExists(filename))
     {
         Stream stream = container.OpenFile(filename, FileMode.Open);
         XmlSerializer serializer = new XmlSerializer(typeof(SaveLevelData));
         SaveLevelData data = (SaveLevelData)serializer.Deserialize(stream);
         level.entityList = data.objectList;
         level.currentPosition = data.currentPosition;
         level.multiSelect = data.multiSelect;
         level.holdTime = data.holdTime;
         level.upTime = data.upTime;
         level.levelName = data.filename;
         stream.Close();
         container.Dispose();
     }
 }
开发者ID:oh-team-machine,项目名称:Target-Tapping,代码行数:22,代码来源:levelLoad.cs


注:本文中的Microsoft.Xna.Framework.Storage.StorageDevice.BeginOpenContainer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。