RCRPG/Raku: Difference between revisions
m
→{{header|Perl 6}}: a few minor tweaks and bug fixs
Thundergnat (talk | contribs) m (→{{header|Perl 6}}: minor bug fix - needs a positional) |
Thundergnat (talk | contribs) m (→{{header|Perl 6}}: a few minor tweaks and bug fixs) |
||
Line 25:
{{works with|niecza|v24}}
{{works with|Rakudo|2013.05}}
<lang perl6>my %commands;
my %rooms;
Line 56 ⟶ 55:
my class Room {
has $.stuff = (my $roll = 1.rand) > .
$roll > .
has $.name = "The Unnamed Room";
has $.links = [];
Line 85 ⟶ 84:
sub serial_and(*@list) {
my %
map { %
my $items = (map { "{%
%things.keys).join: ', ';
$items.subst( /','(<-[,]>+)$ /, -> $/ {" and$0"} );
}▼
sub plural ($item, $count) {
return $count != 1 ?? $item~'s' !! $item
}
Line 120 ⟶ 124:
-> $dir {
if !(%dir_vec{$dir}:exists) {
say "I don't know that direction. Try one of: {sort keys %dir_vec}";
}
elsif grep $dir, @( %rooms{$room}.links ) {
Line 215 ⟶ 219:
{
print 'The Muddy walls dim. ';
say "You glance down as {serial_and( @$stuff )} {plural('clatter
~ " to the floor and {plural('fade', +!(@$stuff == 1))} away." if @$stuff;
say 'It is as if you are awakening from a strange (and extremly low resolution) dream...';
exit;
Line 224 ⟶ 229:
while my $in = $*IN.get {
my @args = $in.words;
if @args && %commands{lc @args[0]} -> $fun {
$fun(|@args);
Line 231 ⟶ 236:
}
%rooms{$room}.greet;
}</lang>▼
▲}
▲</lang>
|