diff --git a/bin/crypt b/bin/crypt index 99306d3..6a0cb78 100755 --- a/bin/crypt +++ b/bin/crypt @@ -983,6 +983,22 @@ class Crypt::Game { } } +sub expand_cmd($syncmd, %synonyms) { + my @expandedcmd; + + # loop through all the words in the command and expand synonyms. Might cause + # problems if objects are named the same as synonyms, for "look" commands etc. + @expandedcmd = gather for $syncmd.words { + when any %synonyms.keys { + take %synonyms{$_}; + } + # well, it wasn't a synonym, so just return it. + take $_; + } + + return @expandedcmd.join(" "); +} + multi MAIN() { say "CRYPT"; say "====="; @@ -1015,6 +1031,20 @@ multi MAIN() { up down in out >; + # command synonyms (object synonyms (e.g. "ball" and "old ball" for "the old + # red ball") should not go here) + my %synonyms = { "n" => "north", + "s" => "south", + "e" => "east", + "w" => "west", + "u" => "up", + "d" => "down", + "l" => "look", + "go" => "walk", + "x" => "examine", + #"i" => "inventory", inventory nyi + }; + given 'clearing' { say .ucfirst; say ""; @@ -1035,6 +1065,8 @@ multi MAIN() { $command .= lc; $command .= trim; + $command = expand_cmd($command, %synonyms); # general synonym handler + when /^help>>/|"h"|"?" { say "Here are some (made-up) examples of commands you can use:"; say "";