读取XML解析装备种类
XML文件:
对XML操作:
Item.ItemType type = (Item.ItemType)System.Enum.Parse(typeof(Item.ItemType), nnnodeList[2].InnerText);
switch (type)
{
case Item.ItemType.Consumable:
int Hp = int.Parse(nnnodeList[9].InnerText);
int Mp = int.Parse(nnnodeList[10].InnerText);
item = new Consumable(ID, Name,type,quality,Description,Capacity,BuyPrice, SellPrice, Sprite,Hp,Mp);
break;
case Item.ItemType.Equipment:
int Attack = int.Parse(nnnodeList[11].InnerText);
int Defend = int.Parse(nnnodeList[12].InnerText);
int Speed = int.Parse(nnnodeList[13].InnerText);
item = new Equipment(ID, Name, type, quality, Description, Capacity, BuyPrice, SellPrice, Sprite, Attack, Defend, Speed, equipmentType);
break;
case Item.ItemType.Weapon:
int Damage = int.Parse(nnnodeList[14].InnerText);
item = new Weapon(ID, Name, type, quality, Description, Capacity, BuyPrice, SellPrice, Sprite,Damage);
break;
case Item.ItemType.None:
item.Type = Item.ItemType.None;
break;
}
Item.cs:
//基类属性
public int ID { set; get; }
public string Name { set; get; }
public ItemType Type { set; get; }
public ItemQuality Quality { set; get; }
public string Description { set; get; }
public int Capacity { set; get; }
public int BuyPrice { set; get; }
public int SellPrice { set; get; }
public string Sprite { set; get; }
//基类构造函数
public Item(int iD, string name, ItemType type, ItemQuality quality, string description, int capacity, int buyPrice, int sellPrice, string sprite)
{
ID = iD;
Name = name;
Type = type;
Quality = quality;
Description = description;
Capacity = capacity;
BuyPrice = buyPrice;
SellPrice = sellPrice;
Sprite = sprite;
}
//Item类型枚举
public enum ItemType
{
None,
Consumable, //消耗品
Equipment, //装备
Weapon, //武器
}
//Item品质枚举
public enum ItemQuality
{
None,
Common, //一般
UnCommon, //不一般
Rare, //稀有
Epic, //史诗
Lengendary, //传说
}