我试图这样做,当用户获得高于高分的分数时,它将自动继续计入高分,如果这是有意义的,这里是我正在使用的一些代码。< / p>
Dim Score As Integer = 0
Dim Attempted As Integer = 0
Dim HighScoreiso As Integer = 0
Dim AppScores As IsolatedStorageSettings = IsolatedStorageSettings.ApplicationSettings
If Score >= HighScoreiso Then
HighScoreText.Text = "HighScore: " & Score.ToString
AppScores.Remove("HighScore")
AppScores.Add("HighScore", HighScoreText.Text)
End If
答案 0 :(得分:0)
如果要将此分数保存在本地存储中,可以使用以下代码:
Private Async Function WriteToFileAsync(content As String, folder As String, filename As String) As Task
Dim fileBytes As Byte() = System.Text.Encoding.UTF8.GetBytes(content.ToCharArray())
Dim local As StorageFolder = Windows.Storage.ApplicationData.Current.LocalFolder
Dim dataFolder = Await local.CreateFolderAsync(folder, CreationCollisionOption.OpenIfExists)
Dim file = Await dataFolder.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting)
Using stream = Await file.OpenStreamForWriteAsync()
stream.Write(fileBytes, 0, fileBytes.Length)
End Using
End Function
Private Async Function ReadFromFileAsync(folder As String, filename As String) As Task(Of String)
Dim local As StorageFolder = Windows.Storage.ApplicationData.Current.LocalFolder
Dim result As String = String.Empty
If local IsNot Nothing Then
Dim dataFolder = Await local.GetFolderAsync(folder)
Dim file = Await dataFolder.OpenStreamForReadAsync(filename)
Using streamReader As New StreamReader(file)
result = result + streamReader.ReadToEnd()
End Using
End If
Return result
End Function