Have fun... :) JamesNCuse strict; my @items; my $move; my $treasure = "gold, gold... it's all mine!"; my @map= ( #possible moves by area # |_0|_1|_2|_3| [qw ( e swe we ws) ], # 0 |__ __ | [qw ( se new sw ns)], # 1 | __ | | [qw ( ns - ns n ) ], # 2 | T|__| |__| [qw ( ne w ne w ) ], # 3 |_____|___X_| ); my %direction = ( n=>[-1,0], s=>[1,0], e=>[0,1], w=>[0,-1], ); my %dir_names = (e=> 'East', n=>'North', w=>'West', s=>'South'); my ($new_x, $new_y, $x, $y) =(0,0,3,3); sub disp_location { my ($nx, $ny) = @_; print "You may move "; while($map[$nx][$ny]=~/([nsew])/g){ print "$dir_names{$1}"; } print "($map[$nx][$ny])\n"; } sub move_to { my ($new, $xref, $yref) = @_; $new = substr(lc($new),0,1); if ($map[$$xref][$$yref]!~/$new/){ print "Invalid direction $new.\n"; return; } $$xref += $direction{$new}[0]; $$yref += $direction{$new}[1]; } while(1){ if ($new_x == $x && $new_y == $y){ print "You died a horrible death!\n +"; exit(0); } if ( $map[$new_x][$new_y]=~ /ns/ && (! map {/gold/ig } @items )){ prin +t "You found treasure!\n"; push @items, $treasure; print "Items: @ite +ms\n"; } if( $map[$new_x][$new_y]=~ /se/ && ( map {/gold/ig } @items ) ) { print "Someone yells..\"Thief!...you will pay with your life for steal +ing my gold!\"...\n"; } disp_location($new_x, $new_y); print "Where to? "; chomp($move=<stdin>); exit if ($move =~ /q/ig); move_to($move, \$new_x, \$new_y); }
In reply to Re: array games??
by JamesNC
in thread array games??
by eoin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |