Games-Bowling-Scorecard
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Games/Bowling/Scorecard.pm view on Meta::CPAN
use v5.24.0;
use warnings;
package Games::Bowling::Scorecard 0.106;
# ABSTRACT: score your bowling game easily
#pod =head1 SYNOPSIS
#pod
#pod use Games::Bowling::Scorecard;
#pod
#pod my $card = Games::Bowling::Scorecard->new;
#pod
#pod $card->record(6,1); # slow start
#pod $card->record(7,2); # getting better
#pod $card->record(10); # strike!
#pod $card->record(9,1); # picked up a spare
#pod $card->record(10) for 1 .. 3; # turkey!
#pod $card->record(0,0); # clearly distracted by something
#pod $card->record(8,2); # amazingly picked up 7-10 split
#pod $card->record(10, 9, 1); # pick up a bonus spare
#pod
#pod printf "total score: %u\n", $card->score; # total score: 156, lousy!
#pod
#pod =head1 DESCRIPTION
#pod
#pod Scoring ten-pin bowling can be confusing for new players. Frames can't always
#pod be scored until several frames later, and then there's that weird tenth frame.
#pod Modern bowling alleys incorporate computer scoring into the pin cleanup
#pod mechanism, so it's easy to just concentrate on throwing a perfect game and not
#pod on grease-pencilling the sheet for the overhead.
#pod
#pod What's one to do, though, when bowling cantaloupes at beer bottles in one's
#pod back yard? Now, with Games::Bowling::Scorecard, it's easy to improvise a
#pod scoring device -- maybe on a mobile phone running Symbian Perl.
#pod
#pod =cut
use Games::Bowling::Scorecard::Frame;
#pod =method new
#pod
#pod This returns a new scorecard object. It does not take any arguments.
#pod
#pod =cut
sub new {
my ($class) = @_;
my $self = bless { frames => [ ] } => $class;
return $self;
}
#pod =method frames
#pod
#pod my @frames = $card->frames;
#pod
#pod This method returns all of the frames for the game. This will return all
#pod frames in which scores have been recorded, and possibly one final frame with no
#pod recorded balls. It will never return any frames after that.
#pod
#pod Frames are returned as Games::Bowling::Scorecard::Frame objects.
#pod
#pod =cut
sub frames {
my ($self) = @_;
return @{ $self->{frames} };
}
#pod =method current_frame
#pod
#pod The current frame is the frame into which the next ball will be recorded. If
#pod the card is done, this method returns false.
#pod
#pod =cut
sub current_frame {
my ($self) = @_;
return if $self->is_done;
my @frames = $self->frames;
my $frame = pop @frames;
return $self->_next_frame if !$frame || $frame->is_done;
return $frame;
}
sub _next_frame {
my ($self) = @_;
my $frame = $self->frames == 9
? do {
require Games::Bowling::Scorecard::Frame::TenPinTenth;
Games::Bowling::Scorecard::Frame::TenPinTenth->new;
}
: Games::Bowling::Scorecard::Frame->new;
push @{ $self->{frames} }, $frame;
return $frame;
}
#pod =method pending_frames
#pod
view all matches for this distributionview release on metacpan - search on metacpan
( run in 0.734 second using v1.00-cache-2.02-grep-82fe00e-cpan-503542c4f10 )