NAME

Games::PMM::Arena - represents the playing arena of a PMM Game

SYNOPSIS

use Games::PMM::Arena;
use Games::PMM::Monster;

my $arena = Games::PMM::Arena->new();

my $m1    = Games::PMM::Monster->new();
my $m2    = Games::PMM::Monster->new();

$arena->add_monster( $m1, x => 0, y => 0 );
$arena->add_monster( $m2, x => 9, y => 9 );

$m1->facing( 'north' );
$m1->facing( 'south' );

DESCRIPTION

Games::PMM::Arena represents the arena in which monsters battle. It controls the coordinate system and all related issues, including monster movement.

METHODS

Several of these methods are private, used mostly within this module (and, presumably, any subclasses).

  • new

    Creates and returns a new Arena object.

  • coordinates

    Private. Returns the current coordinate structure of this object. You probably don't want to use this directly.

  • monsters

    Private. Returns the current monsters structure of this object. You probably don't want to use this directly.

  • x_limit

    Returns the highest allowed position of the arena along the x axis.

  • y_limit

    Returns the highest allowed position of the arena along the y axis.

  • add_monster( $monster, x => $x, y => $y )

    Adds the given monster to the arena at coordinates $x and $y.

  • validate_position( x => $x, y => $y )

    Returns true if the given position is available for a monster to move to or false otherwise.

    Note: this method's name may change.

  • within_bounds( x => $x, y => $y )

    Returns true if the given position is within the bounds of the arena or false otherwise.

  • get_position( $monster )

    Returns the coordinates of the given $monster, if it exists within the arena. If not, this will return undef. Coordinates are returned as a hash reference, keyed on x and y.

  • update_position( $monster, x => $x, y => $y )

    Updates the position of the given $monster within the arena.

  • get_monster( x => $x, y => $x )

    Retrieves and returns the monster in the arena at the given coordinates. This will return nothing if there's no monster at the coordinates.

  • forward( $monster )

    Moves the given $monster forward one step, where "forward" depends on the monster's current facing.

  • reverse( $monster )

    Moves the given $monster backwards one step, where "backwards" depends on the monster's current facing.

  • scan( $monster )

    Looks for other monsters in the arena relative to the $monster's current facing. Monsters can only see directly ahead of them and only one position to either side. They are not limited to how far they can see along the perpendicular axis, however.

    This will return a list of data structures, one for each other monster seen. These data structures will contain x and y coordinates for the monster, the id of the seen monster, and the distance to the monster.

    Note: the distance is the number of moves it would take to reach the other monster's position. This does not count the number of turns it would take. As well, this is not updated as other monsters move.

  • move_monster( $monster, x => $x, y => $y )

    Moves the monster based on the given coordinates, where $x and $y are positions to move, not absolute coordinates. For example, if $monster is currently at 3, 3, passing coordinates of -1, 1 would move the monster to 2,4.

    This will return false and will not move the monster if the destination coordinates are out of range or if there is something at that position already.

  • attack( $monster )

    Causes the given $monster to attack the first thing it finds in front of or beside it. This will return undef if nothing was in range. Otherwise, it will return true if something was damaged and zero if something was damaged past its last point of health.

AUTHOR

chromatic, chromatic@wgz.org

BUGS

No known bugs.

COPYRIGHT

Copyright (c) 2003, chromatic. All rights reserved. This module is distributed under the same terms as Perl itself, in the hope that it is useful but certainly under no guarantee.