|We don't bite newbies here... much|
Re: Re: Re: Re: Re: Modules: Building blocks for the Daft Adventureby dragonchild (Archbishop)
|on Jun 12, 2001 at 18:44 UTC||Need Help??|
API = Application Programming Interface. It's often used to describe the way a given module is meant to be used.
Ok. Here's how I'd begin designing this from an OO perspective:
You'll end up re-writing a lot of this for your first time. Don't be afraid of that! Re-writing is good for the soul.
Now, you have the first type of object down - the "thing". The second type is more difficult, intuitively. This is the object-as-process. Maybe a little discussion will help.
A battle between 4 players and 4 orcs is a very defined thing. It has a start, a middle, and an end. It takes given input (combatants, time/weather, map, etc) and transforms that input into output (orcs dead, players victorious).
Based on that, it makes sense to make a Combat class. You instantiate a new Combat object every time you have a battle.
Given that, run through the steps above again, but this time for processes instead. Do every single step. It's more critical to do that here. For example, would you consider a skill or a spell to be a class? I would, because they have a beginning and an end.
Yes, this sounds like you're going to have a lot of classes, and you will. But, if you do it right, it makes maintenance really easy. For example, if you want to change how all spells work, you have to go to Spell::Generic and make the change there. Voila! All spells do this new way. Same with skills, or combat, or weather, or whatever.
What if you wanted to add a new skill? The way you do it right now, you'd have to add a line to a table, then modify another line in the character classes to say who's allowed to use it, then add a function to handle how it works. Instead, you just add a class. The skill knows who is allowed to use it or not. The skill knows how to "do its thing." Once you add the new class, everything is added and you've added a file and changed a file (to link in the new skill, wherever it has to be linked in to).
I hope this makes sense. I would be very interested in working with you on this, either on perlmonks or via email, if you'll have me. (I wouldn't want to take over the project ... it's yours! But, I'd like to be sort of a ... design consultant, so to speak. *grins*)