public void CreateFile() { // Create dummy data to save. HiScoreData data = new HiScoreData(); data.AllTimeKills = 0; data.HighestWave = 0; data.HighestWaveKills = 0; SaveData(data); }
public void SaveData(HiScoreData data) { // Get the path of the save game string fullPath = "hiscores.dat"; // Open the file, creating it if necessary FileStream stream = File.Open(fullPath, FileMode.Create); try { // Convert the object to XML data and put it in the stream XmlSerializer serializer = new XmlSerializer(typeof(HiScoreData)); serializer.Serialize(stream, data); } finally { // Close the file stream.Close(); } }