Created
July 31, 2011 22:04
-
-
Save anonymous/1117266 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use v6; | |
my @map = ( | |
[< + + + + + + + + + >], # + represents walls | |
[< + . + . . . . . + >], # . represents floors | |
[< + . . . + . + e + >], # e represents the exit | |
[< + + + + + + + + + >]); | |
class Player { | |
has $.xpos; | |
has $.ypos; | |
method walk { | |
my $bump = 1; | |
$_ = prompt '> '; | |
if (/north/ && @map[$!ypos - 1][$!xpos] ne '+') { $!ypos--; $bump = 0; } | |
if (/south/ && @map[$!ypos + 1][$!xpos] ne '+') { $!ypos++; $bump = 0; } | |
if (/east/ && @map[$!ypos][$!xpos + 1] ne '+') { $!xpos++; $bump = 0; } | |
if (/west/ && @map[$!ypos][$!xpos - 1] ne '+') { $!xpos--; $bump = 0; } | |
say "Ouch! You bumped into a wall. (or I don't know what you said.)" if $bump == 1; | |
} | |
method display { | |
$_ = @map[$!ypos][$!xpos]; | |
say "You are currently located at ($!ypos,$!xpos) in the array of doom."; | |
if (/\./) { say "You are on a floor."; } | |
if (/e/) { say "You found the exit!"; exit; } | |
} | |
} | |
my $player = Player.new( | |
xpos => 1, | |
ypos => 1, | |
); | |
say "JOURNEYS IN THE ARRAY OF DOOM"; | |
say "-----------------------------"; | |
while (1) { | |
$player.display; | |
$player.walk; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment