RCRPG/Raku: Difference between revisions

m
→‎{{header|Perl 6}}: a few minor tweaks and bug fixs
m (→‎{{header|Perl 6}}: minor bug fix - needs a positional)
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 %commands;
my %rooms;
 
Line 56 ⟶ 55:
 
my class Room {
has $.stuff = (my $roll = 1.rand) > .2585 ?? [@random_items.roll(2)] !!
$roll > .8525 ?? [@random_items.roll(2)] !! [];
has $.name = "The Unnamed Room";
has $.links = [];
Line 85 ⟶ 84:
 
sub serial_and(*@list) {
my %stuffthings;
map { %stuffthings{$_}++ }, @list;
my $items = (map { "{%stuffthings{$_} > 1 ?? %stuffthings{$_} !! 'a'} {plural($_" }, %stuff.keysthings{$_}).join:}" '}, ';
%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{', +!(@$stuff >== 1 ?? 's' !! ''))} to the floor then fades away." if @$stuff;
~ " 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>
10,327

edits