On Feb 20, 2004, at 3:31 PM, Guay Jean-Sébastien wrote:

On Feb 20, 2004, at 2:02 PM, Joel wrote:
Thanks, can you give me some examples of loops like that?
Here's one:

Nice code James, nicely reusable. Just need to add world file loading and
maybe support for items... ;)

Thank you. I'll look forward to your loading/saving additions to be posted... ;)


Items could be easily added with an array reference. Add a get and drop command, some way to track player inventory (a file scoped player info hash, I suspect) and you're off.

But then all you have is a world in which you can move.

Oh ye of little faith! And just when I was starting to like you too... :D


What about actual game flow, as in this room is in a certain state, doing this will switch it to some other state, and at some point (a certain combination of states in
the rooms, I guess) you win the game...


That's a bit harder to generalize, I think... But I can't think about it
right now, head throbbing, only 20 minutes left until the weekend... :)

Daniel's already showed us one good way to handle this. Just add an internal hash reference to hold commands by name, with code reference values. If you don't recognize a command, check the command's hash for the current room and call the proper code reference.


Oh, then do we lose the ability to use external data files? Na. Change code reference values to string of Perl code that gets eval()ed. We should be able to serialize a string easily enough. ;)

These are just quick and dirty solutions to your questions off the top of my head. Needless to say, commands are a touch more complicated in my MUD. I think it gets a lot more fun when you throw objects into the mix though...

James


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to