Saturday, November 05, 2005

Rules Object

We all want our code to modular. Even in an advanced project it would be nice to be able to:


Orc orc = new Orc();
Man man = new Man();
Write(man.Health);
Write(orc.Health);

RenderSystem.Render(man, x,y);


Something as simple as the above using only very light code. We don't have to locate graphics files each time we load a man, or pass in a sound system pointer, or a input object, or rendering system, or skill tree object - As much as possible we strive to make our classes as independant and modular as possible.

Among other things that what I'm striving for today.

How?



Well one of the ways to do this, especially with Actors and the like is by using a mediator class. For actors, sprites, beings, gameobjects ... this mediator class is often called: Rules or GameMaster. That's where you put your interaction rules - how things will interact with each other and the world.

So instead of each actor have something like:

actor.Attack(IAttackable a)


You have:

Rules.Attack(Actor actor, Actor target);


This way your game pieces are more modular and your game logic is kept tight and together.


*Renamed extremely unhelpfully named class (that's been here since near the start).
*Fixed a GUI object so it works as you'd expect
*Pulled loads of stuff out of my Globe class and pushed it back in utility classes of pre-existing objects

[This month i decided my never ending game project wasn't enough and decided to see if I could write a novel in a month with the happy crew of nanowrimo. It's fun, if you think you can catch up you should give it a go.]

No comments: