in reply to
Advice on Perl OO program structure (MUD)
I agree with Joost that this is a perfectly reasonable start.
You'll want to consider various things for getting further from here:
- class structure: you almost certainly want a base class for monsters/people. One important question is whether the characters controlled by players are "just another monster" or a separate class - I favour the first approach, since it means that (for example) it is easy to let players be any sort of creature, and automatically adopt the limitations and capabilities of that creature. However the second approach gives you flexibilities in other ways - you don't have to consider how arbitrary monsters level up, and it's much easier to retain game balance with player-specific tweaks.
- class structure: you'll probably want a base class for locations. If you want consistent physics and large-area effects such as weather, you'll need to know the size of each location and take some care to ensure that things fit together consistently; if not, you can get away with not much more than a description and a list of exits.
- class structure: you'll probably want a base class for items, that gives underlying support for things like weight/size and value.
- namespace: as the number of classes starts to expand, the danger increases that you'll use a classname that clashes with one already in use on CPAN or in the perl core. I'd suggest from the start picking a name for the MUD and putting all your classes under that namespace, like "YourMudName::Peasant".
- communication: you'll soon want to consider what is required to support multiple users (without which you only have an UD :) - each time something occurs that should result in a message, you need somehow to know who is in range to be informed about it: you need in some sense a list of observers of each location. If you can find a nice generalised way to handle that, it would probably be a great help in debugging - you could have (for example) a global monitor that observed everything, that wrote all such messages to a log file.
Hope this helps some,