3
\$\begingroup\$

I'm writing a C# game in Mono, and I want the game to be as modular as possible.
I've started by writing the whole Item (inventory) System of the game in a seperate .dll library
But I've hit a problem. I want Items to have effects, so I've written a base Interface for this:

interface IBehavior
{
    bool ApplyBehavior(Player destinationPlayer);
}

I'm following guidelines from the answer on this post regarding the (Unit, Effect, Behavior, Ability [Lets call it UEBA]) structure. Problem is that Player is a class from like the main module in the game so I assume this breaks modularity in the code.
What would be the best solution to fix this conflict?
I'm considering writing another, separate module, of UBEA, that will use Player and then the Item System module will use that module instead of the main module, and then the UBEA module will break modularity.
Should I also move Player to another module?
Am I even able to create full modularity if this is the model of things I want to create?

Thanks for the answers!

\$\endgroup\$
0
1
\$\begingroup\$

You could introduce the interface IUnit (if you don't already have it). Place it in the Item-Lib or even in a third lib which is referenced by your main/item/../module then just implement the IUnit interface in your Player class.

interface IBehavior
{
    bool ApplyBehavior(IUnit destinationPlayer);
}
\$\endgroup\$
2
  • \$\begingroup\$ Yeah, that's probably a good idea, the problem that I'm facing is what If i want to change specific things about that unit? how would an Interface like this look like? My player class (before the refactoring I'm doing now) is a mess of implementations from Inventory related shit to UI related shit to Keyboard related shit, like you can see in my github \$\endgroup\$ Sep 17 '15 at 9:52
  • \$\begingroup\$ @GioraGuttsait You want the Component pattern: gameprogrammingpatterns.com/component.html \$\endgroup\$ Nov 9 '16 at 17:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.