I'm writing a MUD engine and I've just started on the game object model, which needs to be extensible.
I need help mainly because what I've done feels messy, but I can't think of a another solution that works better.
I have a class called MudObject
, and another class called Container
, A container can contain multiple MudObjects
, but is a MudObject
itself, however MudObject
s need to know what they are contained in.
So they look something like this:
public abstract class MudObject
{
Container containedBy;
}
public abstract class Container : MudObject
{
List<MudObject> Contains;
}
(please note these are just example and some qualifiers and access modifiers, properties and such are missed off)
Now just this in itself seems messy, but lets add something else to the mix:
Item
is a MudObject
that all visual items (such as weapons) will be inherited from, however some of these need to be containers too (like chests). But theres no such as multiple inheritance in c#, So it comes down to interfaces, the best choice would be to make the container an interface (as far as I can see) However there was a reason I didn't want it to be, that being that adding an MudObject
to a container will cause the container to update the MudObject
s .containedBy
value.
Any ideas that would make this work, or am I falling into the trap of making things too complicated?
If so what else could you suggest?