Okay, I've never done this in perl. All of my mud coding was ~10 years ago on various LPC / MudOS varients.

However, what we did have was a more abstracted exit system -- after all, who's to say you're not going to way 'northwest' and the like? Or 'up' 'down', etc. (or any other direction 'in', 'out', etc...

sub addexit { my ($self, $exit, $direction) = @_; $self->{'_exits'}->{$direction} = $exit; } sub addhiddenexit { my ($self, $exit, $direction) = @_; $self->{'_hiddenexists'}->{$direction} = $exit; } sub showexits { my ($self) = @_; my $message = join "\n", 'The following exits are available:', map { ' $_\n' } sort keys %{ $self->{'_exits'} }; return $message; } sub exit { my ($self, $direction) = @_; if ( exists($self->{'_hiddenexits'}->{$direction}) ) { return $self->{'_hiddenexits'}->{$direction}; } if ( exists($self->{'_exits'}->{$direction}) ) { return $self->{'_exits'}->{$direction}; } return undef; }

Now we get to the difficult part ... I didn't like writing rooms the way you're doing it (all in code). The lib we were used filenames for the most part to load objects, but if you specified something of the format 'filename:arg', it would pass the argument to the init?new? function in the file. So I wrote an engine to generate the rooms from various configuration files (partially inspired by one on another mud I had done some coding on). For example, in your case:

# map file A-B # key file KEY : A NAME : Town Square KEY : B NAME : store

There was then a 'main' file, which inherited from the engine, and contained the following

The key file could handle naming, items to look at in the room, objects cloned in the room (monsters, removable objects, etc.), and the x/y file could also add extra exits / hidden exits.

The map file use a series of symbols to add exits

- : east / west | : north/south \ : nw/se / : ne/sw X : ne/sw/nw/se ^ : north v : south > : east < : west . : hidden (n/s or e/w, depending on placement)

Oh -- and a room should probably inherit from 'container' or something similar -- no reason to duplicate the same code for keeping track of people in a room, as for keeping track of items in a bag, items in a person's inventory, etc.

And the exit code is simplified -- you might want to add support for common abbreviations (n:north, nw:northwest, etc.)


In reply to Re: Building a room system for an adventure game by jhourcle
in thread Building a room system for an adventure game by yoda54

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.