Games::PMM::Arena - represents the playing arena of a PMM Game
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' );
Games::PMM::Arena represents the arena in which monsters battle. It controls the coordinate system and all related issues, including monster movement.
Several of these methods are private, used mostly within this module (and, presumably, any subclasses).
Creates and returns a new Arena object.
Private. Returns the current coordinate structure of this object. You probably don't want to use this directly.
Private. Returns the current monsters structure of this object. You probably don't want to use this directly.
Returns the highest allowed position of the arena along the x axis.
Returns the highest allowed position of the arena along the y axis.
Adds the given monster to the arena at coordinates
Returns true if the given position is available for a monster to move to or false otherwise.
Note: this method's name may change.
Returns true if the given position is within the bounds of the arena or false otherwise.
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
Updates the position of the given
$monster within the arena.
Retrieves and returns the monster in the arena at the given coordinates. This will return nothing if there's no monster at the coordinates.
Moves the given
$monster forward one step, where "forward" depends on the monster's current facing.
Moves the given
$monster backwards one step, where "backwards" depends on the monster's current facing.
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
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.
Moves the monster based on the given coordinates, where
$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
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.
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.
No known bugs.
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.