yoda54 has asked for the wisdom of the Perl Monks concerning the following question:
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Building a room system for an adventure game
by Joost (Canon) on Aug 05, 2006 at 09:56 UTC | |
|
Re: Building a room system for an adventure game
by jhourcle (Prior) on Aug 05, 2006 at 12:32 UTC | |
|
Re: Building a room system for an adventure game
by gellyfish (Monsignor) on Aug 07, 2006 at 09:48 UTC |