根据我在现实生活中认识的程序员和讲师以及互联网上的一些教程,我的代码应该可以正常工作正如我想要的那样,但是每当我开始我的游戏时,我的高分都没有加载,下面是我读取和写入文件的函数,我犯了什么愚蠢的错误吗?
public void ReadHighScore()
{
byte[] myByteArray = new byte[64]; // Creates a new local byte array with a length of 64
using (var store = IsolatedStorageFile.GetUserStoreForApplication()) // Creates an IsolatedStorageFile within the User Storage
using (var stream = new IsolatedStorageFileStream("highscore.txt", System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite, store)) // Creates a new filestream attatched to the storage file
{
if (stream != null) // Checks to see if the filestream sucessfully read the file
{
int streamLength = (int)stream.Length; // Gets the length of the filestream
stream.Read(myByteArray, 0, streamLength); // Parses the filestream to the byte array
}
else
myState = (int)game_state.Terminate; // Temporary Error checking, the function gets though this without triggering the 'terminate' gamestate
}
string ScoreString = myByteArray.ToString(); // Parses the byte array to a string
Int32.TryParse(ScoreString, out highScore.score); // Parses the string to an integer
}
public void SaveHighScore()
{
byte[] myByteArray = new byte[64]; // Creates a new local byte array with a length of 64
using (var store = IsolatedStorageFile.GetUserStoreForApplication()) // Creates an IsolatedStorageFile within the User Storage
using (var stream = new IsolatedStorageFileStream("highscore.txt", System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite, store)) // Creates a new filestream attatched to the storage file
{
if (stream != null) // Checks to see if the filestream sucessfully read the file
{
int streamLength = (int)stream.Length; // Gets the length of the filestream
stream.Write(myByteArray, 0, streamLength); // Parses the byte array to the filestream
}
else
myState = (int)game_state.Terminate; // Temporary Error checking, the function gets though this without triggering the 'terminate' gamestate
}
}
}