Greetings Monks, I'm currently building a adventure game and I'm bit stuck on how to build a room system. How would I generate a series of connected rooms? Here is what my package looks like so far. Each object has four exit attributes which I store references to other rooms.

Thanks for any advice!

package main: use Room; # this is how I generate rooms and add exits my $townsquare = Room->new(name => "Town Square"); my $training = Room->new(name => "store"); $townsquare->addeast($store); $store->addwest($townsquare); package Room; use strict; use warnings; sub new { my ($class, %arg) = @_; my $objref = { _name => $arg{name} || "Town S +quare", _collection => $arg{collection} || [], _enemies => $arg{enemies} || "off", _exiteast => $arg{exiteast} || "none", _exitwest => $arg{exitwest} || "none", _exitsouth => $arg{exitsouth} || "none", _exitnorth => $arg{exitnorth} || "none", _engine => $arg{engine} || 0 }; bless $objref, $class; return $objref; } sub enter { #add person to collection my $self = shift; my $ref = shift; my $aref = $self->{_collection}; push @$aref, $ref; } sub leave { my $self = shift; my $ref = shift; my $aref = $self->{_collection}; my $count = 0; #remove person from collection foreach(@$aref) { if ($ref == $_) { splice @$aref, $count, 1; } $count++; } } sub addeast { my $self = shift; my $exit = shift; $self->{_exiteast} = $exit; } sub addwest { my $self = shift; my $exit = shift; $self->{_exitwest} = $exit; } sub addsouth { my $self = shift; my $exit = shift; $self->{_exitsouth} = $exit; } sub addnorth { my $self = shift; my $exit = shift; $self->{_exitnorth } = $exit; } sub name { $_[0]->{_name}; } sub exitwest { $_[0]->{_exitwest}; } sub exiteast { $_[0]->{_exiteast}; } sub exitsouth { $_[0]->{_exitsouth}; } sub exitnorth { $_[0]->{_exitnorth}; } 1;

In reply to 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.