我有点困惑,这是我到目前为止所做的:
public class SaveLoadSystem
{
String SAVEFILENAME = "gameSave2.sav";
Stats stats = new Stats();
GameProgressInformation gameInfo = new GameProgressInformation();
public SaveLoadSystem()
{
IsolatedStorageFile savegameStorage = IsolatedStorageFile.GetUserStoreForApplication();
// open isolated storage, and write the savefile.
if (savegameStorage.FileExists(SAVEFILENAME))
{
IsolatedStorageFileStream fs = null;
try
{
fs = savegameStorage.OpenFile(SAVEFILENAME, System.IO.FileMode.Open);
}
catch (IsolatedStorageException e)
{
}
if (fs != null)
{
byte[] saveBytes = new byte[256];
int count = fs.Read(saveBytes, 0, 256);
if (count > 0)
{
for (int i = 0; i < stats.GetLevels; i++)
{
GameProgressInformation.LevelUnlockInfo levelInfo = new GameProgressInformation.LevelUnlockInfo();
// Think line below is wrong.
levelInfo.score = saveBytes[i * 4];
GameProgressInformation.levels.Add(levelInfo);
}
fs.Close();
}
}
}
else
{
for (int i = 0; i < stats.GetLevels; i++)
{
GameProgressInformation.LevelUnlockInfo levelInfo = new GameProgressInformation.LevelUnlockInfo();
GameProgressInformation.levels.Add(levelInfo);
}
}
}
public void Save()
{
// Save the game.
IsolatedStorageFile savegameStorage = IsolatedStorageFile.GetUserStoreForApplication();
// open isolated storage, and write the savefile.
IsolatedStorageFileStream fs = null;
fs = savegameStorage.OpenFile(SAVEFILENAME, System.IO.FileMode.Create);
if (fs != null)
{
for (int i = 0; i < GameProgressInformation.levels.Count; i++)
{
byte[] scoreBytes = System.BitConverter.GetBytes(GameProgressInformation.levels[i].score);
fs.Write(scoreBytes, 0, scoreBytes.Length);
}
fs.Close();
}
}
}
我的困惑是如何在加载时获取所有必要的二进制数据,同时确保将正确的数据分配到正确的级别。我认为它必须采取4组。任何帮助表示赞赏。
答案 0 :(得分:0)
制定了如何做到这一点。对流阅读器的工作方式有错误的理解。