App-Games-Keno

 view release on metacpan or  search on metacpan

lib/App/Games/Keno.pm  view on Meta::CPAN

=head1 SYNOPSIS
 
This package plays a game of Keno.  The number range is 1 to 80 and the payout amounts are for 1 to 10 spots.
 
Sample code to play 1000 draws with 5 spots.  The spots are chosen for you.

 use App::Games::Keno;

 my $first_game = App::Games::Keno->new( num_spots => 5, draws => 1000 );
 $first_game->PlayKeno;
 say "You won \$"
   . $first_game->winnings . " on "
   . $first_game->draws
   . " draws.";

This is how you choose your own spots.  

 my $second_game = App::Games::Keno->new(
   spots => [ 45, 33, 12, 20, 75 ],
   draws => 1000
 );
 $second_game->PlayKeno;
 say "You won \$"
   . $second_game->winnings . " on "
   . $second_game->draws
   . " draws.";

Several verbosity levels exist, use theme like this:

 my $third_game = App::Games::Keno->new(
   spots => [ 45, 33, 12, 20, 75 ],
   draws => 1000,
   verbose => 1

playKenoTest.pl  view on Meta::CPAN

use warnings;
use strict;
use lib 'lib';
use App::Games::Keno;
use feature 'say';

my $first_game = App::Games::Keno->new( num_spots => 5, draws => 1000 );
$first_game->PlayKeno;
say "You won \$"
  . $first_game->winnings . " on "
  . $first_game->draws
  . " draws.";

my $second_game = App::Games::Keno->new(
	spots => [ 45, 33, 12, 20 ],
	draws => 1000
);
$second_game->PlayKeno;
say "You won \$"
  . $second_game->winnings . " on "
  . $second_game->draws
  . " draws.";

my $third_game = App::Games::Keno->new(
	spots => [ 45, 33, 12, 20 ],
	draws => 1000,
	verbose => 1
);
$third_game->PlayKeno;
say "You won \$"
  . $third_game->winnings . " on "
  . $third_game->draws
  . " draws.";

playKenoTestArgs.pl  view on Meta::CPAN

my $first_game = App::Games::Keno->new(
	num_spots => $num_spots,
	draws     => $draws,
	verbose => $verbose
);
$first_game->PlayKeno;
my $net_gain   = $draws - $first_game->winnings;
my $net_gain_d = commify( abs($net_gain) );
my $winnings   = commify( $first_game->winnings );
my $draws_d    = commify($draws);
say "You won \$$winnings on $draws_d draws.";
if ( $net_gain > 0 ) {
	say "That's a loss of \$$net_gain_d";
}
else {
	say "You came out ahead by \$$net_gain_d";
}

sub commify {
	my $text = reverse $_[0];
	$text =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g;
	return scalar reverse $text;
}



( run in 1.405 second using v1.01-cache-2.11-cpan-13bb782fe5a )