Acme-GuessNumber
view release on metacpan or search on metacpan
lib/Acme/GuessNumber.pm view on Meta::CPAN
package Acme::GuessNumber;
use strict;
use warnings;
use base qw(Exporter);
our ($VERSION, @EXPORT, @EXPORT_OK);
$VERSION = 0.05;
@EXPORT = qw(guess_number HURRY_UP);
@EXPORT_OK = @EXPORT;
# Prototype declaration
sub guess_number($;$);
our (@GUESS_MSGS, @RESULT_MSGS);
@GUESS_MSGS = split /\n/, << "EOT";
%d?
Is it %d?
It must be %d!
EOT
@RESULT_MSGS = split /\n/, << "EOT";
Any cigarette?
I'm feeling lucky tonight
I'm getting a little tired
It's killing me
I'm gonna faint
EOT
# HURRY_UP: Speed up the game
use constant HURRY_UP => 1;
# guess_number: Play the game
sub guess_number($;$) {
local ($_, %_);
my ($max, $hurry, $to_rest);
($max, $hurry) = @_;
$hurry = 0 if @_ < 2;
# Play the game
$to_rest = 5 + int rand 7 unless $hurry;
while (1) {
my ($num, $guess);
# Generate the number
( run in 0.927 second using v1.01-cache-2.11-cpan-65fba6d93b7 )