毕业设计之背包系统1

       打算写任务系统,背包系统,战斗系统三部分,但是目前只做过背包系统(跟着siki学的),战斗系统(还不是用FSM写的),决定从背包系统开始,修改下之前的框架。

       先做UI:

      背包系统是由很多小格子构成,每个格子也就是一个图片,创建一个image,加一个button,把所有格子放到一个空物体下面,为了对小格子进行排序所以要有Grid layout Group组件。grid layout group组件设置排序方式偏移等等。

     毕业设计之背包系统1_第1张图片

      写代码:

     整体框架如下

毕业设计之背包系统1_第2张图片

Item基类:

   

public class Item {

    public int ID { get; set; }
    public string Name { get; set; }
    public ItemType Type{get;set;}
    public ItemQualitys Quality { get; set; } 
    public string Description { get; set; } 

    public int Capacity { get; set; }//容量
    public int BuyPrice { get; set; }
    public int SellPrice { get; set; }

    public string Sprite { get; set; }
    public Item()
    {
        this.ID = -1;
    }
    public Item(int id,string name,ItemType type,ItemQualitys quality,string des,int capacity,int buyPrice,int sellPrice,string sprite )
    {
        this.ID = id;
        this.Name = name;
        this.Type = type;
        this.Quality = quality;
        this.Description = des;
        this.Capacity = capacity;
        this.BuyPrice = buyPrice;
        this.SellPrice = sellPrice;
        this.Sprite = sprite;
    }

    /// 
    /// 物品类型
    /// 
   public enum ItemType
    {
        Consumable,//消耗品
        Equipment,//装备类
        Weapon,//武器
        Material//材料
    }
   /// 
   /// 物品品质
   /// 
   public enum ItemQualitys
    {
        white,//白色
        yellow,//黄色
        blue,//蓝色
        Orange//橙色
    }
    /// 
    /// 得到提示面板应该显示什么样的内容
    /// 
    /// 
    public virtual string GetToolTipText()
    {
        string color = "";
        switch(Quality)
        {
            case ItemQualitys.white:
                color = "white";
                break;
            case ItemQualitys.blue:
                color = "blue";
                break;
            case ItemQualitys.Orange:
                color = "orange";
                break;
            case ItemQualitys.yellow:
                color = "yellow";
                break;

        }
        string text = string.Format("{0}\n购买价格:{1}出售价格:{2}\n{3}", Name, BuyPrice, SellPrice, Description, color);

        return text;
    }
消耗品:

public class Consumable : Item
{
    public int HP { get; set; }
    public int MP { get; set; }
    public Consumable(int id, string name, ItemType type, ItemQualitys quality, string des, int capacity, int buyPrice, int sellPrice, string sprite, int hp,int mp) : base(id, name, type, quality, des, capacity, buyPrice, sellPrice,sprite)
    {
        this.HP = hp;
        this.MP = mp;
    }
}
武器类:

public class Weapon : Item
{
    public int Damage { get; set; }


    public Weapon(int id, string name, ItemType type, ItemQualitys quality, string des, int capacity, int buyPrice, int sellPrice,int damage,string sprite) : base(id, name, type, quality, des, capacity, buyPrice, sellPrice,sprite)
    {
        this.Damage = damage;
    }
    public override string GetToolTipText()
    {
        string text= base.GetToolTipText();
        int damage = Damage;
        string newtext = string.Format("{0}\n攻击力:{1}", text, damage);
        return newtext;
    }


}
装备类:

public class Equipment : Item
{
    public int Strength { get; set; }//力量
    public int Intellect { get; set; }//智力
    public int Agility { get; set; }//敏捷
    public int Stamina { get; set; }//体力    
    public EquipmentType equipType { get; set; }



    public enum EquipmentType
    {
        None,
        Head,
        Chest,//胸部
        Leg,//腿
        Boots,//腿
    }
    public Equipment(int id, string name, ItemType type, ItemQualitys quality, string des, int capacity, int buyPrice, int sellPrice,int strength,
        int intellect,int agility,int stamina,EquipmentType equiptype,string sprite) : base(id, name, type, quality, des, capacity, buyPrice, sellPrice,sprite)
    {
        this.Strength = strength;
        this.Intellect = intellect;
        this.Agility = agility;
        this.Stamina = stamina;
        this.equipType = equiptype;

    }
    public override string GetToolTipText()
    {
        string equipTypeText = "";
        switch(equipType)
        {
            case EquipmentType.Head:
                equipTypeText = "头部";
                break;

            case EquipmentType.Chest:
                equipTypeText = "胸部";
                break;
            case EquipmentType.Leg:
                equipTypeText = "腿";
                break;

            case EquipmentType.Boots:
                equipTypeText = "靴子";
                break;
        }
        string text= base.GetToolTipText();
        string newText = string.Format("{0}\n装备类型:{5}\n力量:{1}\n智力:{2}\n敏捷:{3}\n体力:{4}", text,Strength,Intellect,Agility,Stamina,equipTypeText);
        return newText;
    }
}





你可能感兴趣的:(我的游戏)