如何解决在游戏中继承2个抽象类的问题?

Fra*_*pie 4 c# inheritance abstract

我的问题在于继承可玩角色的属性.我有一个名为Being的抽象类,声明所有继承类都需要包含诸如Strength,Dexterity等属性.玩家需要选择一个种族,例如Orc,它将力量从0提升到10.然后玩家需要选择一个像暴徒这样的阶级,为英雄的力量增加了7点.据我所知,我会坚持我的Hero类继承2个抽象类?这是我的Orc类的摘录:

public abstract class Orc:Being
{
     private int _strength = 10;



     //Another question, is it okay to declare an abstract property in my base abstract
     //class to force the inheriting class Orc to override the property? I wanted to 
     //find a way to force subclasses to have strength attributes

     public override int Strength
     {
            get {return _strength;}
            set {_strength = value;}
     }
}
Run Code Online (Sandbox Code Playgroud)

Var*_*ant 5

您可以使用Composition作为多重继承的解决方案:

这里的答案解释得最好:https://stackoverflow.com/a/178368/340128