NAME

Game::TextMapper::Schroeder::Base - a base role for map generators

SYNOPSIS

# 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);

DESCRIPTION

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

METHODS

xy($coordinates)

$coordinates is a string with four digites and interpreted as coordinates and returned, e.g. returns (2, 3) for "0203".

legal($x, $y) or $legal($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.

remove_closer_than($limit, @coordinates)

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.

flat($altitude)

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.

direction($from, $to)

Return the direction (an integer) to step from $from to reach $to.

This depends on Game::TextMapper::Schroeder::Base being used as a role by a class that implements neighbors and neighbor.

SEE ALSO

Game::TextMapper::Schroeder::Hex and Game::TextMapper::Schroeder::Square both use this class to provide common functionality.