Uncategorized

Design Awry

I was going along, working on a iPhone port of HamQuest, when I wandered into the same goofy chain of dependencies that I ran into the first time.  This time, I hope I have done better, but you can be the judge.

Player specific information(equipment, statistics, etc) is stored in a class called, appropriately, Player.

The representation of the Player on the map is a MapCreature, as are all other types of creature.

MapCreature has some creature instance information(wounds, mostly).

The Player class knows about the MapCreature instance for the player.

The MapCreature instance has a reference to a CreatureDescriptorBase, for which there exists a special PlayerCreatureDescriptor as a subclass.  For normal creatures, CreatureDescriptors are used (another subclass of CreatureDescriptorBase).

All of the various CreatureDescriptor instances and the PlayerCreatureDescriptor exist in a CreatureTable, which is used to populate a maze.

The PlayerCreatureDescriptor knows about the Player, so it can query it for statistics important to the operation of a MapCreature (mainly attacking and defending).

So, unfortunately, there is a circle: Player->MapCreature->PlayerCreatureDescriptor->Player.  I get around having an actual circular dependency by using a base class.

It is improved from the last time, however.  MapCreature only held a CreatureIdentifier, which would then be used to look up the CreatureDescriptor in the CreatureTable.  I realized today that it was silly, because then a MapCreature needed a reference to the CreatureTable.  So, cut out the middle man.

Thanks for listening.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s