Games-Board
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Games/Board/Space.pm view on Meta::CPAN
use strict;
use warnings;
package Games::Board::Space 1.014;
# ABSTRACT: a parent class for spaces on game board
use Carp;
#pod =head1 SYNOPSIS
#pod
#pod use Games::Board;
#pod
#pod my $board = Games::Board->new;
#pod
#pod $board->add_space(Games::Board::Space->new(
#pod id => 'go',
#pod dir => { next => 'mediterranean', prev => 'boardwalk' },
#pod cost => undef
#pod ));
#pod
#pod my $tophat = Games::Board::Piece->new(id => 'tophat')->move(to => 'go');
#pod
#pod =head1 DESCRIPTION
#pod
#pod This module provides a base class for representing the spaces on a game board.
#pod
#pod =cut
#pod =method new
#pod
#pod This method constructs a new space and returns it.
#pod
#pod =cut
sub new {
my $class = shift;
my %args = @_;
return unless $args{id};
croak "no board supplied in space creation"
unless eval { $args{board}->isa('Games::Board') };
my $space = {
id => $args{id},
board => $args{board},
};
$space->{dir} = $args{dir}
if $args{dir} and (ref $args{dir} eq 'HASH');
bless $space => $class;
}
#pod =method id
#pod
#pod This method returns the id of the space.
#pod
#pod =cut
sub id {
my $space = shift;
return $space->{id};
}
#pod =method board
#pod
#pod This method returns board on which this space sits.
#pod
#pod =cut
sub board {
my $space = shift;
$space->{board};
}
#pod =method dir_id
#pod
#pod my $id = $space->dir_id($dir);
#pod
#pod This method returns the id of the space found in the given direction from this
#pod space.
#pod
#pod =cut
sub dir_id {
my ($space, $dir) = @_;
return $space->{dir}{$dir} if (ref $space->{dir} eq 'HASH');
}
#pod =method dir
#pod
#pod my $new_space = $space->dir($dir);
#pod
#pod This method returns the space found in the given direction from this space.
#pod
#pod =cut
sub dir {
my ($space, $dir) = @_;
$space->board->space($space->dir_id($dir));
}
#pod =method contains
#pod
#pod my $bool = $space->contains($piece);
#pod
#pod This method returns a true value if the space contains the passed piece.
#pod
#pod =cut
view all matches for this distributionview release on metacpan - search on metacpan
( run in 1.418 second using v1.00-cache-2.02-grep-82fe00e-cpan-72ae3ad1e6da )