Unity3d背包系统系统(二)—— 开发消耗品、装备、武器材料

上节开发了背包系统物品的基类,这节继续开发它的子类---消耗品、装备、武器材料类

Unity3d背包系统系统(二)—— 开发消耗品、装备、武器材料_第1张图片
各个子类继承了基类并且有各自的属性及构造方法,子类的拷贝参构造是拷贝的父类的属性在加上子类的属性;下面上代码:
Consumable类的:
public class Consumable : Item
{
    #region 属性

    /// 
    /// HP
    /// 
    public int HP { get; set; }

    /// 
    /// MP
    /// 
    public int MP { get; set; }

    #endregion 属性

    /// 
    /// 构造方法
    /// 
    /// 父类构造
    /// ID
    /// 名称
    /// 物品类型
    /// 品质
    /// 描述
    /// 容量
    /// 购买价格
    /// 出售价格
    /// 图标
    /// 本身构造
    /// HP
    /// MP
    public Consumable(int id, string name, ItemType itemType, QualityType quality, string des, int capacity, int buyPrice, int sellPrice, string sprite,
        int hp, int mp)
        : base(id, name, itemType, quality, des, capacity, buyPrice, sellPrice, sprite)
    {
        this.HP = hp;
        this.MP = mp;
    }

    /// 
    /// 拷贝构造函数
    /// 
    /// 待拷贝的属性
    /// 本身构造
    /// HP
    /// MP
    public Consumable(Item item, int hp, int mp)
    {
        this.ID          = item.ID;
        this.Name        = item.Name;
        this.Type        = item.Type;
        this.Quality     = item.Quality;
        this.Description = item.Description;
        this.Capacity    = item.Capacity;
        this.BuyPrice    = item.BuyPrice;
        this.SellPrice   = item.SellPrice;
        this.Sprite      = item.Sprite;

        this.HP = hp;
        this.MP = mp;
    }

Equipment类的:

public class Equipment : Item
{
    #region 属性

    /// 
    /// 力量
    /// 
    public int Strength { get; set; }

    /// 
    /// 智力
    /// 
    public int Intellect { get; set; }

    /// 
    /// 敏捷
    /// 
    public int Agility { get; set; }

    /// 
    /// 体力
    /// 
    public int Stamina { get; set; }

    /// 
    /// 等级
    /// 
    public int Level { get; set; }

    /// 
    /// 装备类型
    /// 
    public EquipmentType EquipType { get; set; }

    #endregion 属性

    #region 枚举类型

    /// 
    /// 装备类型
    /// 
    public enum EquipmentType
    {
        None,       //空
        Head,       //头部
        Neck,       //项链
        Chest,      //胸甲
        Ring,       //戒指
        Leg,        //护腿
        Bracelet,   //手镯
        Boots,      //靴子
        Shoulder,   //护肩
        Belt,       //腰带
    }

    #endregion 枚举类型

    /// 
    /// 构造方法
    /// 
    /// 父类构造
    /// ID
    /// 名称
    /// 物品类型
    /// 品质
    /// 描述
    /// 容量
    /// 购买价格
    /// 出售价格
    /// 图标
    /// 本身构造
    /// 等级
    /// 力量
    /// 智力
    /// 敏捷
    /// 体力
    /// 装备类型
    public Equipment(int id, string name, ItemType itemType, QualityType quality, string des, int capacity, int buyPrice, int sellPrice, string sprite,
        int level, int strength, int intellect, int agility, int stamina, EquipmentType equipType)
        : base(id, name, itemType, quality, des, capacity, buyPrice, sellPrice, sprite)
    {
        this.Level = level;
        this.Strength = strength;
        this.Intellect = intellect;
        this.Agility = agility;
        this.Stamina = stamina;
        this.EquipType = equipType;
    }

    /// 
    /// 拷贝构造函数
    /// 
    /// 待拷贝的属性
    ///  本身构造
    /// 等级
    /// 力量
    /// 智力
    /// 敏捷
    /// 体力
    /// 装备类型
    public Equipment(Item item,int level, int strength, int intellect, int agility, int stamina, EquipmentType equipType)
    {
        this.ID = item.ID;
        this.Name = item.Name;
        this.Type = item.Type;
        this.Quality = item.Quality;
        this.Description = item.Description;
        this.Capacity = item.Capacity;
        this.BuyPrice = item.BuyPrice;
        this.SellPrice = item.SellPrice;
        this.Sprite = item.Sprite;

        this.Level = level;
        this.Strength = strength;
        this.Intellect = intellect;
        this.Agility = agility;
        this.Stamina = stamina;
        this.EquipType = equipType;
    }

Weapon类的:

public class Weapon : Item
{
    #region 属性

    /// 
    /// 伤害
    /// 
    public int Damage { get; set; }

    /// 
    /// 等级
    /// 
    public int Level { get; set; }

    /// 
    /// 武器类型
    /// 
    public WeaponType WpType { get; set; }

    #endregion 属性

    #region 枚举类型

    /// 
    /// 武器类型
    /// 
    public enum WeaponType
    {
        None,         //空
        MainWeapon,   //主武器
        OffWeapon     //副武器
    }

    #endregion 枚举类型

    /// 
    /// 构造方法
    /// 
    /// 父类构造
    /// ID
    /// 名称
    /// 物品类型
    /// 品质
    /// 描述
    /// 容量
    /// 购买价格
    /// 出售价格
    /// 图标
    /// 本身构造
    /// 等级
    /// 伤害
    /// 武器类型
    public Weapon(int id, string name, ItemType itemType, QualityType quality, string des, int capacity, int buyPrice, int sellPrice, string sprite,
        int level, int damage, WeaponType weaponType)
        : base(id, name, itemType, quality, des, capacity, buyPrice, sellPrice, sprite)
    {
        this.Level = level;
        this.Damage = damage;
        this.WpType = weaponType;
    }

    /// 
    /// 拷贝构造函数
    /// 
    /// 待拷贝的属性
    /// 本身构造
    /// 等级
    /// 伤害
    /// 武器类型
    public Weapon(Item item, int level, int damage, WeaponType weaponType)
    {
        this.ID = item.ID;
        this.Name = item.Name;
        this.Type = item.Type;
        this.Quality = item.Quality;
        this.Description = item.Description;
        this.Capacity = item.Capacity;
        this.BuyPrice = item.BuyPrice;
        this.SellPrice = item.SellPrice;
        this.Sprite = item.Sprite;

        this.Level = level;
        this.Damage = damage;
        this.WpType = weaponType;
    }
Material类的:
public class Material : Item
{
    /// 
    /// 拷贝构造函数
    /// 
    /// 待拷贝的属性
    public Material(Item item)
    {
        this.ID = item.ID;
        this.Name = item.Name;
        this.Type = item.Type;
        this.Quality = item.Quality;
        this.Description = item.Description;
        this.Capacity = item.Capacity;
        this.BuyPrice = item.BuyPrice;
        this.SellPrice = item.SellPrice;
        this.Sprite = item.Sprite;
    }
}


物品类的各个子类暂时全部编写完毕,
本节结束,下节继续。。。。。。

你可能感兴趣的:(Unity3d学习之路)