paj*_*ajm 4 c# inheritance interface
我正试图在我的游戏中创建一个灵活的系统来装扮我的角色.现在我已经有了一个基类,所有的儿童服装类都将从这个基类扩展,还有一些额外的接口可以将它们实际所穿的身体部位带入等式中.这是我的代码:
public class Clothing
{
public EClothingBind[] Types;
public int ID;
public int Priority;
public bool HidesUnderlying;
public AnimatedSpriteMap Graphic;
public Color Blend = Color.White;
public virtual void Update(GameTime gameTime)
{
Graphic.Update(gameTime);
}
public virtual void Draw(Vector2 position)
{
Graphic.Tint = Blend;
Graphic.Draw(position);
}
}
public interface IClothingHead { ... }
public interface IClothingChest { ... }
public interface IClothingLegs { ... }
public interface IClothingFeet { ... }
Run Code Online (Sandbox Code Playgroud)
现在这不好用,因为设计并没有真正限制可以实现我的IClothing接口的东西.有没有办法将接口实现限制为某些类型?我不想把我的界面变成班级,因为我想要一件衣服,比如长袍,以覆盖整个身体(实施所有四个).对于这样做的最佳方式我有点失落,所有的输入都非常感激.谢谢.
我认为你正在通过这种方法为自己做好准备.当然,长袍覆盖了所有,并且图形上它将会并且可能影响4个区域的"护甲"值.但是像这样实现它看起来非常麻烦.您可能只需要一个IClothing接口,并且可以对其放置位置进行一些识别(例如:Hands/Feet等).传统上,长袍通常是胸部,但在图形上它们覆盖了整个角色.
enum PositionType
{
Head,
Chest,
Hand,
Feet,
Finger,
Neck
}
public interface IClothing
{
PositionType Type { get; }
// Other things you need IClothing-classed to implement
}
Run Code Online (Sandbox Code Playgroud)
我认为这可能是一种更好的方法,而不是试图通过实现多个界面来精确调整特定服装项目的身体部位.