Skip to content

Instantly share code, notes, and snippets.

@Coleoid
Created October 6, 2012 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Coleoid/3846209 to your computer and use it in GitHub Desktop.
Save Coleoid/3846209 to your computer and use it in GitHub Desktop.
quest-solving by typing Perl 6 code
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