Created
October 6, 2012 21:34
-
-
Save Coleoid/3846209 to your computer and use it in GitHub Desktop.
quest-solving by typing Perl 6 code
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
class quest { | |
has $.description; | |
method embark { | |
say "You may pass when you $.description."; | |
self.cast_loop; | |
self.reward; | |
} | |
method cast_loop { | |
my Bool $victory = Bool:False; | |
loop { | |
print "~~~:"; | |
my $spell = $*IN.get; | |
try { | |
eval $spell; | |
CATCH { | |
default { | |
say $_; | |
} | |
} | |
} | |
last if self.success_check; # $goblin ~~ "fireball"; | |
say "Nope. Cast again." | |
} | |
} | |
method reward { | |
say "Congratulations, you $.description!"; | |
} | |
has Bool $.success = Bool:False; | |
method success_check { | |
$.success; | |
} | |
} | |
class quest_foo_to_bar is quest { | |
my $foo = ""; # "our $foo" didn't work either | |
has $.description = "set \$foo to 'bar'"; | |
method success_check { | |
$foo ~~ "bar"; | |
} | |
} | |
my $q = quest_foo_to_bar.new(); | |
$q.embark(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment