/// <summary> /// Resets highscores and saves to file /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ResetHighscores(object sender, RoutedEventArgs e) { highscores.Reset(); SaveAndLoad.WriteToBinaryFile("highscores.sav", highscores); HighScores.Children.Clear(); SortScores(); }
/// <summary> /// Displays end game window and saves high scores /// </summary> private void Winner() { EndWindow.Visibility = Visibility.Visible; WinnerScore.Text = "The score is: " + memoryGrid.HighestScore().ToString(); WinnerName.Text = memoryGrid.WinnerName(); string name = memoryGrid.OnlyNameWinner(); if (name != null) { highscores.AddNewHighscore(memoryGrid.OnlyNameWinner(), memoryGrid.HighestScore()); SaveAndLoad.WriteToBinaryFile("highscores.sav", highscores); } }
/// <summary> /// Reset the been clicked bool for every card that isn't a pair yet (otherwise you won't be able to click that card again, if you've only clicked one card and then saved) /// Save the rows, colums, current cards, order in which the cards are shuffled and all the player information /// Write this to the save file /// </summary> public void SaveGame() { for (int i = 0; i < GameCards.Count; i++) { GameCards[i].beenClicked = GameCards[i].beenUsed; } SaveData.rows = rows; SaveData.colums = colums; SaveData.GameCards = GameCards; SaveData.MemoryCards = MemoryCards; player.SaveGame(out SaveData.namePlayerOne, out SaveData.scorePlayerOne, out SaveData.namePlayerTwo, out SaveData.scorePlayerTwo, out SaveData.playerTwo); SaveData.timer = savedTime; SaveAndLoad.WriteToBinaryFile("memory.sav", SaveData); }
/// <summary> /// Reset everything so you can use it again, /// Load the savefile with the right data, /// Set all the values with the data from the save file /// </summary> public void LoadGame() { grid.Children.Clear(); GameCards.Clear(); MemoryCards.Clear(); TurnedCards.Clear(); player.ClearMemory(); player.SetPlayerOne(); canClick = true; secondClick = false; SaveData = SaveAndLoad.ReadFromBinaryFile <SaveData>("memory.sav"); rows = SaveData.rows; colums = SaveData.colums; player.LoadGame(SaveData.playerTwo, SaveData.namePlayerOne, SaveData.namePlayerTwo, SaveData.scorePlayerOne, SaveData.scorePlayerTwo); savedTime = SaveData.timer; LoadCards(); }
/// <summary> /// Loads highscores from file /// </summary> private void LoadHighscore() { highscores = SaveAndLoad.ReadFromBinaryFile <HighScore>("highscores.sav"); }