Game::Battleship - "You sunk my battleship!"
version 0.0602
use Game::Battleship; my $g = Game::Battleship->new; $g->add_player('Aaron'); $g->add_player('Tabi'); my $winner = $g->play; print $winner->name, " wins!\n";
A Game::Battleship object represents a battleship game between players. Each has a fleet of vessels and operates with a pair of playing grids. One grid is for their own fleet and the other for the seen enemy positions.
Game::Battleship
Everything is an object with default but mutable attributes. This way games can have two or more players each with a single fleet of custom vessels.
A game can be played with the handy play method, or for finer control, use individual methods of the Game::Battleship::* modules.
play
Game::Battleship::*
$g = Game::Battleship->new; $g = Game::Battleship->new( players => [$player1, $player2] );
Construct a new Game::Battleship object.
$g->add_player; $g->add_player($name); $g->add_player({ name => $name, fleet => \@fleet, dimensions => [$w, $h], }); $g->add_player($player, $number);
Add a player to the existing game.
This method can accept either nothing, a string, a Game::Battleship::Player object or a hash reference of meaningful Game::Battleship::Player attributes.
Game::Battleship::Player
This method also accepts an optional numeric second argument that is the player number.
If this number is not provided, the least whole number that is not represented in the player IDs is used. If a player already exists with that number, a warning is emitted and the player is not added.
See Game::Battleship::Player for details on the default and custom settings.
$player_obj = $g->player($name); $player_obj = $g->player($number); $player_obj = $g->player($key);
Return the Game::Battle::Player object that matches the given name, key or number (where the key is /player_\d+/ and the number is just the numeric part of the key).
Game::Battle::Player
/player_\d+/
$winner = $g->play;
Take a turn for each player, striking all the opponents, until there is only one player left alive.
Return the Game::Battleship::Player object that is the game winner.
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.
t/01-methods.t
Game::Battleship::Craft, Game::Battleship::Grid, Game::Battleship::Player
http://en.wikipedia.org/wiki/Battleship_%28game%29
Gene Boggs <gene@cpan.org>
This software is copyright (c) 2020 by Gene Boggs.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Game::Battleship, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Game::Battleship
CPAN shell
perl -MCPAN -e shell install Game::Battleship
For more information on module installation, please visit the detailed CPAN module installation guide.