NAME

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

SYNOPSIS

use Games::Battleship;

$g = Games::Battleship->new(
    player_1 => 'Gene',
    player_2 => 'Aeryk',
);

# This method is handy, but only used in the test script.
$player_obj = $g->player($name);
$player_obj = $g->player($key);
$player_obj = $g->player($number);

$winner = $g->play;
print "$winner->{name} wins!\n";

ABSTRACT

Battleship game implementation

DESCRIPTION

A Games::Battleship object represents a battleship game with players, fleets and playing grids.

No, I did not do this for a school assignment, but rather because I played it one night with my friend, Aeryk, and decided that it might be fun to implement.

NOTE: Currently, this module's play feature is not especially functional for the sole reason that the game type attribute does not exist yet. Please bear with me. The next release will rock.

The game can definitely be played with by using the individual methods in the Games::Battleship* modules.

Please see the distribution test script for working code.

PUBLIC METHODS

new [%ARGUMENTS]
  • player_1 => $STRING

  • player_2 => $STRING

    Specify the player names. If not given, explicitly, "player_1" and "player_2" are used as the names, by default.

  • type => text | cgi | gui

    The type of game we are playing. This argument is optional. If not given, a random coodinate is chosen based on the dimensions attribute.

    This argument is used by the _get_coordinate method to properly request input of the coordinates.

    For text (and curses), this is an interactive console request. For CGI programs, this is a call to the CGI::param method.

    * I have not determined the most appropriate functionality for the gui type, yet. There are many many GUIs out there...

    * NOTE: Currently, this argument is not implemented, so don't get your hopes up just yet. I will add this to the next release, and there will be happiness in the valley.

play [%ARGUMENTS]
$winner = $g->play;

Take a turn for each player, striking all the opponents, until there is only one player left alive.

Return the Games::Battleship::Player object that is the game winner.

player $STRING
$player_obj = $g->player($name);
$player_obj = $g->player($key);
$player_obj = $g->player($number);

Return the Games::Battle::Player object that matches the given name, key or number (where the key is a player_* key of the Games::Battleship instance and the number is just the numeric part of the key).

PRIVATE METHODS

_get_coordinate
($x, $y) = $g->_get_coordinate;

Return a grid position (as integers).

TO DO

Allow more than 2 players in the constuctor and add an add_player method.

Allow network play.

Keep pending games and personal scores in a couple handy text files.

Make a simple eg/ program with text.

Make an eg/ Curses program with colored text.

Make an eg/ CGI program both as text and with Imager.

Make an eg/ standalone GUI program too.

Enhance to include the features in Hasbro's "Advanced Mission Game": (2) exocet missles fired from your aircraft carrier; (1) tomahawk missle with a massive footprint fired from your battleship; (2) apache missles fired from your destroyer; (2) torpedoes fired from your sub; (2) recon airplanes for surveillance; sonar imaging from your sub. This means implementing weapon and recon classes with name, quantity, footprint, etc.

SEE ALSO

Games::Battleship::Player

http://www.hasbro.com/pl/page.viewproduct/product_id.9388/dn/default.cfm

AUTHOR

Gene Boggs <gene@cpan.org>

COPYRIGHT AND LICENSE

Copyright 2003, Gene Boggs

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.