NAME

Game::Battleship - "You sunk my battleship!"

VERSION

version 0.0601

SYNOPSIS

  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";

DESCRIPTION

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.

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. See the distribution test script for working code examples.

NAME

Game::Battleship - "You sunk my battleship!"

METHODS

new()

  $g = Game::Battleship->new;
  $g = Game::Battleship->new( players => [$player1, $player2] );

Construct a new Game::Battleship object.

add_player()

  $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.

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()

  $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).

play()

  $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.

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.

SEE ALSO

* The code in the t/ directory.

* Game::Battleship::Craft, Game::Battleship::Grid, Game::Battleship::Player

* http://en.wikipedia.org/wiki/Battleship_%28game%29

AUTHOR

Gene Boggs <gene@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2015 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.