public void playerLevel() { if (File.Exists(Level_DATA_FILE_NAME)) { _playerLevelStats = LevelStats.CreatePlayerFromXmlString(File.ReadAllText(Level_DATA_FILE_NAME)); } else { _playerLevelStats = LevelStats.CreateDefaultPlayer(); } }
public static LevelStats CreatePlayerFromXmlString(string xmlLevelData) { try { XmlDocument levelData = new XmlDocument(); levelData.LoadXml(xmlLevelData); int strength = Convert.ToInt32(levelData.SelectSingleNode("/Player/Stats/strength").InnerText); int magic = Convert.ToInt32(levelData.SelectSingleNode("/Player/Stats/Magic").InnerText); int dexerity = Convert.ToInt32(levelData.SelectSingleNode("/Player/Stats/Dexerity").InnerText); int defense = Convert.ToInt32(levelData.SelectSingleNode("/Player/Stats/Defense").InnerText); int levelPoints = Convert.ToInt32(levelData.SelectSingleNode("/Player/Stats/LevelPoints").InnerText); LevelStats level = new LevelStats(strength, magic, dexerity, defense, levelPoints); return level; } catch { // If there was an error with the XML data, return a default player object return LevelStats.CreateDefaultPlayer(); } }
public static LevelStats CreateDefaultPlayer() { LevelStats level = new LevelStats(1, 1, 1, 1, 0); return level; }