official input method
This commit is contained in:
parent
bc103a242a
commit
c14c335689
1 changed files with 48 additions and 21 deletions
49
plugins/game
49
plugins/game
|
@ -6,10 +6,12 @@
|
||||||
|
|
||||||
use Time::HiRes qw( gettimeofday tv_interval);
|
use Time::HiRes qw( gettimeofday tv_interval);
|
||||||
|
|
||||||
HELP "game" => "Scan-foo game!";
|
HELP "game" => "Scan-fu game!";
|
||||||
|
|
||||||
my $fastest=1000;
|
my $fastest=1000;
|
||||||
my $fastest_name="nobody";
|
my $fastest_name="nobody";
|
||||||
|
my $start_time;
|
||||||
|
my $step;
|
||||||
|
|
||||||
sub command :Tab(game) {
|
sub command :Tab(game) {
|
||||||
|
|
||||||
|
@ -17,27 +19,40 @@ sub command :Tab(game) {
|
||||||
|
|
||||||
return NEXT if $command !~ /^(?:game)$/;
|
return NEXT if $command !~ /^(?:game)$/;
|
||||||
|
|
||||||
print "\nWelcome to SCAN-FOO \\o/\n";
|
print "\nWelcome to SCAN-FU \\o/\n";
|
||||||
|
|
||||||
print "\nRecord time is $fastest by $fastest_name\n";
|
print "\nRecord time is $fastest by $fastest_name\n";
|
||||||
|
|
||||||
my $start_time=[gettimeofday];
|
$start_time=[gettimeofday];
|
||||||
|
$step=1;
|
||||||
|
|
||||||
for (my $i=1; $i<=5; $i++)
|
return "NOW SCAN game_$step", \&step;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sub step :Tab(whatevah) {
|
||||||
|
my ($self, $cart, $input) = @_;
|
||||||
|
|
||||||
|
if ($step<5)
|
||||||
{
|
{
|
||||||
print "NOW SCAN game_$i: ";
|
if ($input ne "game_$step")
|
||||||
my $scanned=<STDIN>;
|
|
||||||
if ($scanned ne "game_$i\n")
|
|
||||||
{
|
{
|
||||||
print "\nFAIL! :( *sad trombone*\n";
|
print "\n\aFAIL! :( *sad trombone*\n";
|
||||||
|
|
||||||
return ACCEPT;
|
return ACCEPT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$step++;
|
||||||
|
|
||||||
|
return "NOW SCAN game_$step", \&step;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
my $elapsed = tv_interval ( $start_time, [gettimeofday]);
|
my $elapsed = tv_interval ( $start_time, [gettimeofday]);
|
||||||
|
|
||||||
print "Completed in $elapsed seconds *tadaah*\n";
|
print "\aCompleted in $elapsed seconds *tadaah*\n";
|
||||||
|
|
||||||
if ($elapsed < $fastest)
|
if ($elapsed < $fastest)
|
||||||
{
|
{
|
||||||
|
@ -46,10 +61,22 @@ sub command :Tab(game) {
|
||||||
print " #####################\n";
|
print " #####################\n";
|
||||||
print " You did it in $elapsed !!!\n";
|
print " You did it in $elapsed !!!\n";
|
||||||
|
|
||||||
print "Enter your name: ";
|
$fastest_name="(unknown)";
|
||||||
$fastest_name=<STDIN>;
|
|
||||||
$fastest=$elapsed;
|
$fastest=$elapsed;
|
||||||
|
|
||||||
|
return "Enter your name for the hall of fame", \&name;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ACCEPT;
|
return ACCEPT;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sub name :Tab(whatevah) {
|
||||||
|
my ($self, $cart, $input) = @_;
|
||||||
|
|
||||||
|
$fastest_name=$input;
|
||||||
|
|
||||||
|
return ACCEPT;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue