Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Synonyms! #1

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 32 additions & 0 deletions bin/crypt
Expand Up @@ -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() { multi MAIN() {
say "CRYPT"; say "CRYPT";
say "====="; say "=====";
Expand Down Expand Up @@ -1015,6 +1031,20 @@ multi MAIN() {
up down in out 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' { given 'clearing' {
say .ucfirst; say .ucfirst;
say ""; say "";
Expand All @@ -1035,6 +1065,8 @@ multi MAIN() {
$command .= lc; $command .= lc;
$command .= trim; $command .= trim;


$command = expand_cmd($command, %synonyms); # general synonym handler

when /^help>>/|"h"|"?" { when /^help>>/|"h"|"?" {
say "Here are some (made-up) examples of commands you can use:"; say "Here are some (made-up) examples of commands you can use:";
say ""; say "";
Expand Down