public static HighScoreData LoadHighScores() { HighScoreTracker.InitializeHighScores(); HighScoreData data = null; try { IAsyncResult result = HighScoreTracker.device.BeginOpenContainer("StorageDemo", null, null); result.AsyncWaitHandle.WaitOne(); container = HighScoreTracker.device.EndOpenContainer(result); result.AsyncWaitHandle.Close(); // Open the file Stream stream = container.OpenFile("highscores.sav", FileMode.Open); //FileStream stream = File.Open(highScorePath, FileMode.OpenOrCreate, //FileAccess.Read); try { // Read the data from the file XmlSerializer serializer = new XmlSerializer(typeof(HighScoreData)); data = (HighScoreData)serializer.Deserialize(stream); if (data != null) { cachedData = data; } } catch (Exception e) { } finally { // Close the file stream.Close(); } } catch { } finally { if (container != null) { container.Dispose(); } if (data == null) { data = cachedData; } } return(data); }
public static LevelData GetHighScoresForLevel(GameMode mode, int level) { HighScoreTracker.InitializeHighScores(); HighScoreData data = LoadHighScores(); if (mode == GameMode.Puzzle) { return(data.puzzleLevels[level]); } else if (mode == GameMode.TimeAttack) { return(data.timeAttackLevels[level]); } else { return(data.moveChallengeLevels[level]); } }