public override string ToString() { string stats = Health.ToString() + "\n" + Strength.ToString() + "\n" + Dexterity.ToString() + "\n" + Agility.ToString() + "\n" + Inteligence.ToString() + "\n" + Luck.ToString() + "\n" + Statpoints.ToString() + "\n" + Level.ToString() + "\n" + ExperiencePoints.ToString(); string hash = GetSha1("Blin113" + stats); //blin113 is just here to make sure you can't cheat without access to the code. stats += "\n" + hash; return(stats); }
public string ToXmlString() { XmlDocument playerData = new XmlDocument(); //Create the top-level node XmlNode player = playerData.CreateElement("Player"); playerData.AppendChild(player); //Create the "Stats" child node to hold the other player stats nodes XmlNode stats = playerData.CreateElement("Stats"); player.AppendChild(stats); //Create the child nodes for the "Stats" nodes XmlNode currentHitPoints = playerData.CreateElement("CurrentHitPoints"); currentHitPoints.AppendChild(playerData.CreateTextNode(CurrentHitPoints.ToString())); stats.AppendChild(currentHitPoints); XmlNode maximumHitPoints = playerData.CreateElement("MaximumHitPoints"); maximumHitPoints.AppendChild(playerData.CreateTextNode(MaximumHitPoints.ToString())); stats.AppendChild(maximumHitPoints); XmlNode gold = playerData.CreateElement("Gold"); gold.AppendChild(playerData.CreateTextNode(Gold.ToString())); stats.AppendChild(gold); XmlNode experiencePoints = playerData.CreateElement("ExperiencePoints"); experiencePoints.AppendChild(playerData.CreateTextNode(ExperiencePoints.ToString())); stats.AppendChild(experiencePoints); XmlNode currentLocation = playerData.CreateElement("CurrentLocation"); currentLocation.AppendChild(playerData.CreateTextNode(CurrentLocation.ID.ToString())); stats.AppendChild(currentLocation); if (CurrentWeapon != null) { XmlNode currentWeapon = playerData.CreateElement("CurrentWeapon"); currentWeapon.AppendChild(playerData.CreateTextNode(CurrentWeapon.ID.ToString())); stats.AppendChild(currentWeapon); } //Create the "InventoryItems" child node to hold each InventoryItem node XmlNode inventoryItems = playerData.CreateElement("InventoryItems"); player.AppendChild(inventoryItems); //Create an "InventoryItem" node for each item in the player inventory foreach (InventoryItem item in this.Inventory) { XmlNode inventoryItem = playerData.CreateElement("InventoryItem"); XmlAttribute idAttribute = playerData.CreateAttribute("ID"); idAttribute.Value = item.Details.ID.ToString(); inventoryItem.Attributes.Append(idAttribute); XmlAttribute quantityAttribute = playerData.CreateAttribute("Quantity"); quantityAttribute.Value = item.Quantity.ToString(); inventoryItem.Attributes.Append(quantityAttribute); inventoryItems.AppendChild(inventoryItem); } //Create the "PlayerQuests" child node to hold each PlayerQuest node XmlNode playerQuests = playerData.CreateElement("PlayerQuests"); player.AppendChild(playerQuests); //Create a "PlayerQuest" node for each quest the player has acquired foreach (PlayerQuest quest in this.Quests) { XmlNode playerQuest = playerData.CreateElement("PlayerQuest"); XmlAttribute idAttribute = playerData.CreateAttribute("ID"); idAttribute.Value = quest.Details.ID.ToString(); playerQuest.Attributes.Append(idAttribute); XmlAttribute isCompletedAttribute = playerData.CreateAttribute("IsCompleted"); isCompletedAttribute.Value = quest.IsCompleted.ToString(); playerQuest.Attributes.Append(isCompletedAttribute); playerQuests.AppendChild(playerQuest); } return(playerData.InnerXml); //The XML document, as a string, so we can save the data to disk }