Give this a shot... I played with this when I was first got started...
use 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); }
Have fun... :) JamesNC

In reply to Re: array games?? by JamesNC
in thread array games?? by eoin

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.