Game-Battleship
view release on metacpan or search on metacpan
lib/Game/Battleship.pm view on Meta::CPAN
while ($res == -1) {
$res = $player->strike(
$opponent,
$self->_get_coordinate($opponent)
);
}
}
}
# Do we have a winner?
my @alive = grep { $self->{players}{$_}->life } keys %{ $self->{players} };
$winner = @alive == 1 ? shift @alive : undef;
}
#warn $winner->name ." is the winner!\n";
return $winner;
}
# Return a coordinate from a player's grid.
sub _get_coordinate {
my ($self, $player) = @_;
lib/Game/Battleship.pm view on Meta::CPAN
Return the C<Game::Battle::Player> object that matches the given
name, key or number (where the key is C</player_\d+/> and the number
is just the numeric part of the key).
=head2 play
$winner = $g->play;
Take a turn for each player, striking all the opponents, until there
is only one player left alive.
Return the C<Game::Battleship::Player> object that is the game
winner.
=head1 TO DO
Implement the "number of shots" measure. This may be based on life
remaining, shots taken, hits made or ships sunk (etc?).
Enhance weaponry and sensing.
( run in 1.813 second using v1.01-cache-2.11-cpan-39bf76dae61 )