From bea4b482b0054d00b47028f0f7445f9888d3e013 Mon Sep 17 00:00:00 2001 From: Edwin Eefting Date: Sat, 9 Aug 2014 03:53:10 +0200 Subject: [PATCH 1/5] added scanfoo game :) --- plugins/game | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 plugins/game diff --git a/plugins/game b/plugins/game new file mode 100644 index 0000000..3d9e023 --- /dev/null +++ b/plugins/game @@ -0,0 +1,38 @@ +#!perl + +#Scan-foo-game for Revbank - (C)Edwin Eefting (psy0rz) + +#Released under GPL or whatever revbank uses as license :) + +use Time::HiRes qw( gettimeofday tv_interval); + +HELP "game" => "Scan-foo game!"; + +sub command :Tab(game) { + my ($self, $cart, $command) = @_; + + return NEXT if $command !~ /^(?:game)$/; + + print "\nWelcome to SCAN-FOO \\o/\n"; + + + my $start_time=[gettimeofday]; + + for (my $i=1; $i<=5; $i++) + { + print "NOW SCAN game_$i: "; + my $scanned=; + if ($scanned ne "game_$i\n") + { + print "\nFAIL! :( *sad trombone*\n"; + + return ACCEPT; + } + } + + my $elapsed = tv_interval ( $start_time, [gettimeofday]); + + print "COMPLETED in $elapsed seconds *tadaah*\n"; + + return ACCEPT; +} From bc103a242a7983f016aae10f1ab9d073f44c8ff7 Mon Sep 17 00:00:00 2001 From: Edwin Eefting Date: Sat, 9 Aug 2014 04:20:36 +0200 Subject: [PATCH 2/5] highscore --- plugins/game | 19 ++++++++++++++++++- revbank.plugins | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/plugins/game b/plugins/game index 3d9e023..db3cf6c 100644 --- a/plugins/game +++ b/plugins/game @@ -8,13 +8,18 @@ use Time::HiRes qw( gettimeofday tv_interval); HELP "game" => "Scan-foo game!"; +my $fastest=1000; +my $fastest_name="nobody"; + sub command :Tab(game) { + my ($self, $cart, $command) = @_; return NEXT if $command !~ /^(?:game)$/; print "\nWelcome to SCAN-FOO \\o/\n"; + print "\nRecord time is $fastest by $fastest_name\n"; my $start_time=[gettimeofday]; @@ -32,7 +37,19 @@ sub command :Tab(game) { my $elapsed = tv_interval ( $start_time, [gettimeofday]); - print "COMPLETED in $elapsed seconds *tadaah*\n"; + print "Completed in $elapsed seconds *tadaah*\n"; + + if ($elapsed < $fastest) + { + print " #####################\n"; + print " #### NEW RECORD! ####\n"; + print " #####################\n"; + print " You did it in $elapsed !!!\n"; + + print "Enter your name: "; + $fastest_name=; + $fastest=$elapsed; + } return ACCEPT; } diff --git a/revbank.plugins b/revbank.plugins index b2ef101..1698288 100644 --- a/revbank.plugins +++ b/revbank.plugins @@ -16,6 +16,7 @@ stock beep_terminal +game # Scan-foo game # Then, plugins that apply heuristics From c14c3356894ccce33417791f0a2852320e72bc1e Mon Sep 17 00:00:00 2001 From: Edwin Eefting Date: Sat, 9 Aug 2014 14:27:26 +0200 Subject: [PATCH 3/5] official input method --- plugins/game | 69 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 21 deletions(-) diff --git a/plugins/game b/plugins/game index db3cf6c..374e374 100644 --- a/plugins/game +++ b/plugins/game @@ -6,10 +6,12 @@ use Time::HiRes qw( gettimeofday tv_interval); -HELP "game" => "Scan-foo game!"; +HELP "game" => "Scan-fu game!"; my $fastest=1000; my $fastest_name="nobody"; +my $start_time; +my $step; sub command :Tab(game) { @@ -17,39 +19,64 @@ sub command :Tab(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"; - 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: "; - my $scanned=; - if ($scanned ne "game_$i\n") + if ($input ne "game_$step") { - print "\nFAIL! :( *sad trombone*\n"; + print "\n\aFAIL! :( *sad trombone*\n"; return ACCEPT; } + + $step++; + + return "NOW SCAN game_$step", \&step; } - - my $elapsed = tv_interval ( $start_time, [gettimeofday]); - - print "Completed in $elapsed seconds *tadaah*\n"; - - if ($elapsed < $fastest) + else { - print " #####################\n"; - print " #### NEW RECORD! ####\n"; - print " #####################\n"; - print " You did it in $elapsed !!!\n"; - print "Enter your name: "; - $fastest_name=; - $fastest=$elapsed; + my $elapsed = tv_interval ( $start_time, [gettimeofday]); + + print "\aCompleted in $elapsed seconds *tadaah*\n"; + + if ($elapsed < $fastest) + { + print " #####################\n"; + print " #### NEW RECORD! ####\n"; + print " #####################\n"; + print " You did it in $elapsed !!!\n"; + + $fastest_name="(unknown)"; + $fastest=$elapsed; + + return "Enter your name for the hall of fame", \&name; + + } + + return ACCEPT; } +} + +sub name :Tab(whatevah) { + my ($self, $cart, $input) = @_; + + $fastest_name=$input; return ACCEPT; } + From eb7f748737f3fb37c5c8919881a30bddb1d06f07 Mon Sep 17 00:00:00 2001 From: Edwin Eefting Date: Sat, 9 Aug 2014 15:45:27 +0200 Subject: [PATCH 4/5] highscores --- plugins/game | 79 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 67 insertions(+), 12 deletions(-) diff --git a/plugins/game b/plugins/game index 374e374..ff4efe5 100644 --- a/plugins/game +++ b/plugins/game @@ -8,12 +8,35 @@ use Time::HiRes qw( gettimeofday tv_interval); HELP "game" => "Scan-fu game!"; -my $fastest=1000; -my $fastest_name="nobody"; my $start_time; my $step; +my $slowest; +my $elapsed=1000; -sub command :Tab(game) { +sub print_highscores() +{ + $slowest=1000; + print "\n---- fastest times ----\n"; + open my $in, "highscores.txt"; + my $nr=0; + while (<$in>) + { + my ($name,$time)=split(" "); + printf "$nr: %f $name\n", $time; + $nr++; + $slowest=$time; + } + if ($nr<10) + { + $slowest=1000; + } + + close($in); + print "-----------------------\n"; +} + +sub command :Tab(game) +{ my ($self, $cart, $command) = @_; @@ -21,7 +44,7 @@ sub command :Tab(game) { print "\nWelcome to SCAN-FU \\o/\n"; - print "\nRecord time is $fastest by $fastest_name\n"; + print_highscores(); $start_time=[gettimeofday]; $step=1; @@ -34,7 +57,7 @@ sub command :Tab(game) { sub step :Tab(whatevah) { my ($self, $cart, $input) = @_; - if ($step<5) + if ($step<1) { if ($input ne "game_$step") { @@ -50,20 +73,17 @@ sub step :Tab(whatevah) { else { - my $elapsed = tv_interval ( $start_time, [gettimeofday]); + $elapsed = tv_interval ( $start_time, [gettimeofday]); print "\aCompleted in $elapsed seconds *tadaah*\n"; - if ($elapsed < $fastest) + if ($elapsed < $slowest) { print " #####################\n"; print " #### NEW RECORD! ####\n"; print " #####################\n"; print " You did it in $elapsed !!!\n"; - $fastest_name="(unknown)"; - $fastest=$elapsed; - return "Enter your name for the hall of fame", \&name; } @@ -72,10 +92,45 @@ sub step :Tab(whatevah) { } } -sub name :Tab(whatevah) { +sub name :Tab(whatevah) +{ my ($self, $cart, $input) = @_; - $fastest_name=$input; + + #store new highscores: + #(ulgy as hell...but hey i'm sleepy :) + + open my $in, "highscores.txt.tmp"; + my $nr=0; + while (<$in>) + { + $nr++; + my ($name,$time)=split(" "); + if ($elapsed!=-1 && $elapsed<=$time) + { + print $out "$input $elapsed\n"; + $elapsed=-1; + $nr++; + } + + print $out "$name $time\n"; + + if ($nr>10) + { + last; + } + } + if ($nr<10 && $elapsed!=-1) + { + print $out "$input $elapsed\n"; + } + + close($in); + close($out); + rename("highscores.txt.tmp", "highscores.txt"); + + print_highscores(); return ACCEPT; } From e617466049b7e95165df5e3d93e2cd0b1b5616ee Mon Sep 17 00:00:00 2001 From: Edwin Eefting Date: Sat, 9 Aug 2014 15:46:32 +0200 Subject: [PATCH 5/5] highscores --- plugins/game | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/game b/plugins/game index ff4efe5..22eecb7 100644 --- a/plugins/game +++ b/plugins/game @@ -57,7 +57,7 @@ sub command :Tab(game) sub step :Tab(whatevah) { my ($self, $cart, $input) = @_; - if ($step<1) + if ($step<5) { if ($input ne "game_$step") {