I'm building a text-RPG and, while everything's working fine for now, I'm concerned that my structure sucks. The primary objects in play are:
- Characters
- Rooms
- Items
- Notifiers
- Handlers (Attack, Item, and Movement handlers)
- World (stores handlers, notifiers and events)
The basic process is something like this:
- Character.move() from Room A to Room B
- World registers a move-event
- MoveNotifier.notify()
- Registered handlers receive notification and do their thing (i.e. - MoveHandler takes the pointer to Character stored in a member of Room A and moves it to the respective member in Room B. DescriptionHandler prints out the appropriate Room B description, what items it contains, etc.)
(I know the notifier-handler thing may be a bit overkill for a single-player text-RPG, but this is all practice for the big picture—please think of this as early practice for creating a larger, multi-player game.)
Here's my worry: Many of these objects store pointers to other objects. Character has a pointer to the Room in which it stands, while Room has a vector of pointers to every Character contained within it. This doesn't feel right. Part of me thinks that Character should know what Room it stands in, but another part of me wants every object to be totally independent and self contained. If everything should be self-contained, then my question is:
Is there a standard line of containment? Should Room know what Character is in it? Should a Character know what Item it has equipped? Should an Item know what Enhancements it's infused with?
If nothing should be aware of anything else, then should everything be stored in a relational database? I've been looking into object storage w/ MySQL or some SQL variant anyway.