Я пытаюсь проверить систему инвентаризации, которую я создаю, но я хочу сделать это с помощью XML. положить в кодексах и такие, как:Система инвентаризации XML
<Item>
<ItemName ItemName = "Apple">
<ItemQuantity>1</ItemQuantity>
<ItemMaxQuantity>64</ItemMaxQuantity>
<ItemState>PERFECT</ItemState>
</ItemName>
<ItemName ItemName = "Sword">
<ItemQuantity>1</ItemQuantity>
<ItemMaxQuantity>1</ItemMaxQuantity>
<ItemState>BROKEN</ItemState>
</ItemName>
</Item>
Я знаю, как сериализовать и тому подобное. Но не знаю, как добавить их в игру, имея несколько предметов, как я показал. У меня есть класс инвентаря. Вот так:
namespace inventory_test
{
class Inventory
{
public enum ItemState
{
NONE,
PERFECT,
FINE,
BROKEN,
DESTROYED
};
/*public enum ItemType
{
FOOD,
USEABLE,
WEAPON,
KEY,
TOOL
}; Implement this in the test later*/
[XmlElement("ItemName")]
public string ItemName
{ get; set; }
[XmlElement("ItemState")]
public string ItemState
{ get; set; }
[XmlElement("ItemQuantity")]
public string Quantity
{ get; set; }
[XmlElement("ItemMaxQuantity")]
public string MaxQuantity
{ get; set; }
static void AddItem(int itemID, string itemState, int quantity, int maxquantity)
{
}
}
}
Это мой Program.cs:
namespace inventory_test
{
class Program
{
static void Main(string[] args)
{
}
//Serialization
static public void Serialize(Inventory inventory)
{
XmlSerializer serializer = new XmlSerializer(typeof(Inventory));
using (TextWriter writer = new StreamWriter(@"C:\Xml.xml"))
{
serializer.Serialize(writer, inventory);
}
}
}
}
Я понятия не имею, что я должен делать. Я действительно застрял прямо сейчас и не знаю, что делать. Помогите мне :)?
есть вопросы? Вы хотите десериализовать содержимое xml в список объекта «Inventory»? – har07
Вот что я хочу делать, да. С атрибутами. – Stepepper