Exemplo n.º 1
0
    /// <summary>
    /// 构造函数
    /// </summary>
    /// <param name="parent">父类</param>
    /// <param name="health">生命值,填0表示从父类继承</param>
    /// <param name="attack">攻击表现</param>
    public Breed(Breed parent, int health, string attack)
    {
        health_ = health;
        attack_ = attack;
        parent_ = null;

        //复制“代理”,在创建一个类型时将继承的特性复制到类的内部
        //注意我们不再需要parent类中的属性,一旦构造结束,就可以忘掉基类
        if (parent != null)
        {
            parent_ = parent;

            //是0,从父层拿
            if (health == 0)
            {
                health_ = parent.GetHealth();
            }
            //是null,从父层拿
            if (attack == null)
            {
                attack_ = parent.GetAttack();
            }
        }
    }
    /// <summary>
    /// Constructor
    /// </summary>
    /// <param name="parent">father</param>
    /// <param name="health">Life value, fill with 0 means inherit from the parent class</param>
    /// <param name="attack">Attack performance</param>
    public Breed(Breed parent, int health, string attack)
    {
        health_ = health;
        attack_ = attack;
        parent_ = null;

        //Copy the "agent", copy the inherited characteristics to the inside of the class when creating a type
        //Note that we no longer need the attributes in the parent class, once the construction is over, you can forget the base class
        if (parent != null)
        {
            parent_ = parent;

            //It is 0, taken from the parent layer
            if (health == 0)
            {
                health_ = parent.GetHealth();
            }
            //Is null, taken from the parent layer
            if (attack == null)
            {
                attack_ = parent.GetAttack();
            }
        }
    }
Exemplo n.º 3
0
 public Monster(Breed breed)
 {
     health_ = breed.GetHealth();
     breed_  = breed;
     attack_ = breed.GetAttack();
 }