Game::TextMapper::Schroeder::Base - a base role for map generators
# create a map package World; use Modern::Perl; use Game::TextMapper::Schroeder::Base; use Mojo::Base -base; use Role::Tiny::With; with 'Game::TextMapper::Schroeder::Base'; # use it package main; my $map = World->new(height => 10, width => 10);
Map generators that work for both hex maps and square maps use this role and either the Hex or Square role to provide basic functionality for their regions, such as the number of neighbours they have (six or four).
$coordinates is a string with four digites and interpreted as coordinates and returned, e.g. returns (2, 3) for "0203".
$coordinates
say "legal" if $map->legal(10,10);
Turn $coordinates into ($x, $y), assuming each to be two digits, i.e. "0203" turns into (2, 3).
Return ($x, $y) if the coordinates are legal, i.e. on the map.
Each element of @coordinates is a string with four digites and interpreted as coordinates, e.g. "0203" is treated as (2, 3). Returns a list where each element is no closer than $limit to any existing element.
This depends on Game::TextMapper::Schroeder::Base being used as a role by a class that implements distance.
distance
my $altitude = {}; $map->flat($altitude); say $altitude->{"0203"};
Initialize the altitude map; this is required so that we have a list of legal hex coordinates somewhere.
Return the direction (an integer) to step from $from to reach $to.
$from
$to
This depends on Game::TextMapper::Schroeder::Base being used as a role by a class that implements neighbors and neighbor.
neighbors
neighbor
Game::TextMapper::Schroeder::Hex and Game::TextMapper::Schroeder::Square both use this class to provide common functionality.
To install Game::TextMapper, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Game::TextMapper
CPAN shell
perl -MCPAN -e shell install Game::TextMapper
For more information on module installation, please visit the detailed CPAN module installation guide.