/// <summary> /// Load saved game information. /// </summary> /// <exception cref="ArgumentNullException">When no filepath to data file is given</exception> /// <exception cref="FileNotFoundException">When gamedata file is not found at the given location</exception> /// <param name="filepath"></param> public bool LoadGameData(string filepath) { var wasDataLoaded = false; if (string.IsNullOrEmpty(filepath) == false) { if (DoesGameDataExist(filepath)) { XmlSerializer serializerObj = new XmlSerializer(typeof(Datastore)); using (TextReader tr = new StreamReader(filepath)) { datastore = (Datastore)serializerObj.Deserialize(tr); tr.Close(); wasDataLoaded = true; UnsavedChanges = false; } } else { throw new FileNotFoundException("Gamedata file was not found at " + filepath); } } else { throw new ArgumentNullException("Must specify where to load file"); } return(wasDataLoaded); }
public GameController() { datastore = new Datastore(); }