forked from DizzyDogg/Wilderness
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplay
executable file
·54 lines (47 loc) · 1.53 KB
/
play
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/perl
use strict;
use warnings;
use World;
use Player;
use Data::Dumper;
my $world = World->new();
my $player = Player->new(location => $world->{'grid'}->{'0,0,0'});
$world->{'grid'}->{'0,0,0'}->add_item($player);
print "\n\nWelcome to the World of Awesome.\n";
print "So far, the most advanced thing you can do is make fire\n";
print "You may type 'help' for an overwhelming list of available commands\n\n";
# The introductory statement
$player->look();
print "\n";
$player->inventory();
while ( my ($verb, @arguments) = prompt() ) {
if ( $verb =~ /^\_/ ) {
warn "\tFor your own safety, I would recommend against using '_'\n"
. "\tThe last time a player used that, they were stepped on by Big Foot\n"
if $verb eq '_';
warn "\tYou have to actually TYPE what you want to do.\n"
. "\tMy crystal ball broke, so I gave up on the mind-reading thing\n"
if $verb eq '_empty_';
next;
}
my $command = $player->get_verb($verb);
if ( my $m = defined $command && $player->can($command) ) {
my @args = $player->str2obj(@arguments);
$player->$m(@args);
}
else {
warn "\tYou do not know how to $verb\n";
}
}
sub prompt {
print "\nWhat would you like to do? ";
my $command = <STDIN>;
chomp $command;
return "_" if $command =~ /\_/;
return "_empty_" if $command =~ /^\s*$/;
$command = lc $command;
$command =~ s/\bthe\b//;
$command =~ s/\ba\b//;
$command =~ s/\bat\b//;
return split /\s+/, $command;
}