本文整理汇总了C#中Microsoft.Xna.Framework.Storage.StorageDevice.EndOpenContainer方法的典型用法代码示例。如果您正苦于以下问题:C# StorageDevice.EndOpenContainer方法的具体用法?C# StorageDevice.EndOpenContainer怎么用?C# StorageDevice.EndOpenContainer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Xna.Framework.Storage.StorageDevice
的用法示例。
在下文中一共展示了StorageDevice.EndOpenContainer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例2: 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();
}
}
示例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();
}
示例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
}
示例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;
}
示例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(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 = "LbKSavedInfo.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.
level = data.CurrentLevel;
score = data.SavedPlayerScore;
checkPoint = data.SavedCheckPoint;
GamePlayScreen.storageDevice = device;
// load up game with respective device
}
示例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());
}
示例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();
}
示例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);
}
示例10: 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);
}
示例11: 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;
}
}
示例12: 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();
}
}
示例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;
}
示例14: LoadHighScores
/// <summary>
/// Ładowanie listy najlepszych wyników dla danego poziomu
/// </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 HighScoreData LoadHighScores(IAsyncResult result, int gameLevel)
{
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[gameLevel - 1]))
{
container.Dispose();
return new HighScoreData(0);
}
// Open the file.
Stream stream = container.OpenFile(filename[gameLevel - 1], FileMode.Open);
// Read the data from the file.
XmlSerializer serializer = new XmlSerializer(typeof(HighScoreData));
HighScoreData data = (HighScoreData)serializer.Deserialize(stream);
// Close the file.
stream.Close();
// Dispose the container.
container.Dispose();
//Return HighScoreData
return data;
}
示例15: DoLoadGame
/// <summary>
/// This method loads a game save object
/// from the StorageContainer for this game.
/// By: Joseph Shaw
/// </summary>
/// <param name="device">The device we are loading from</param>
/// <param name="fileName">The file we are loading</param>
public static CharacterSaveFile DoLoadGame(StorageDevice device, string fileName)
{
// Open a storage container.
IAsyncResult result = device.BeginOpenContainer("DungeonCrawler", null, null);
// Wait for the WaitHandle to become signaled.
result.AsyncWaitHandle.WaitOne();
StorageContainer container = device.EndOpenContainer(result);
// Close the wait handle.
result.AsyncWaitHandle.Close();
// Check to see whether the save exists.
if (!container.FileExists(fileName))
{
// If not, dispose of the container and return.
container.Dispose();
return new CharacterSaveFile();
}
// Open the file.
Stream stream = container.OpenFile(fileName, FileMode.Open);
// Read the data from the file.
BinaryFormatter binaryFormatter = new BinaryFormatter();
CharacterSaveFile characterSaveData = (CharacterSaveFile)binaryFormatter.Deserialize(stream);
// Close the file.
stream.Close();
// Dispose the container.
container.Dispose();
if (characterSaveData.quests == null)
characterSaveData.quests = new List<Quest>();
DungeonCrawlerGame.game.Quests = characterSaveData.quests;
return characterSaveData;
}