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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |