/// <summary> /// Restores GameInstance from a JSON file /// </summary> public void RestoreHighScoreData() { //Get data from file //string path = "..\\..\\JSON\\GameInstance.json"; if (File.Exists(InstancePathHighScore)) { HighScoreViewModel JSONHighScoreData = new HighScoreViewModel(); string output = File.ReadAllText(InstancePathHighScore); //Deserialize from JSON to .NET and put into HighScoreData JSONHighScoreData = JsonConvert.DeserializeObject <HighScoreViewModel>(output); EasyScore = JSONHighScoreData.EasyScore; IntermediateScore = JSONHighScoreData.IntermediateScore; DifficultScore = JSONHighScoreData.DifficultScore; ScoreShowing = EasyScore; } }
/// <summary> /// Default constructor /// </summary> public MenuViewModel() { // Load Scores HighScoreInstance = new HighScoreViewModel(); HighScoreInstance.RestoreHighScoreData(); // Commands for buttons StartEasyCommand = new RelayCommand(async() => await StartAsync(Difficulty.Easy)); StartIntermediateCommand = new RelayCommand(async() => await StartAsync(Difficulty.Medium)); StartDifficultCommand = new RelayCommand(async() => await StartAsync(Difficulty.Hard)); ContinueCommand = new RelayCommand(ContinueButton); HighScoreCommand = new RelayCommand(HighScoreButton); ExitCommand = new RelayCommand(ExitButton); // Commands for navigation in MenuPage NewGameCommand = new RelayCommand(NewGameButton); HideNewGameCommand = new RelayCommand(HideNewGame); }