| Games-Risk documentation | Contained in the Games-Risk distribution. |
Games::Risk::Continent - continent object
version 3.103040
my $id = Games::Risk::Continent->new(\%params);
This module implements a map continent, with all its characteristics.
Create a new continent. Mandatory params are id, name and bonus
(see below in Accessors for a quick definition).
The following accessors (acting as mutators, ie getters and setters) are
available for Games::Risk::Continent objects:
number of bonus armies given when a player controls every country in the continent.
unique id assigned to the continent.
continent name.
Store $country (a Games::Risk::Country object) as a country
located within the $continent.
Remove all circular references of $continent, to prevent memory leaks.
Return the list of countries located in $continent.
Return true if $player is the owner of all $continent's countries.
Jerome Quelin
This software is Copyright (c) 2008 by Jerome Quelin.
This is free software, licensed under:
The GNU General Public License, Version 3, June 2007
| Games-Risk documentation | Contained in the Games-Risk distribution. |
# # This file is part of Games-Risk # # This software is Copyright (c) 2008 by Jerome Quelin. # # This is free software, licensed under: # # The GNU General Public License, Version 3, June 2007 # use 5.010; use strict; use warnings; package Games::Risk::Continent; BEGIN { $Games::Risk::Continent::VERSION = '3.103040'; } # ABSTRACT: continent object use List::MoreUtils qw{ all }; use base qw{ Class::Accessor::Fast }; __PACKAGE__->mk_accessors( qw{ id bonus name _countries } ); #-- # METHODS # -- public methods # # $continent->add_country( $country ); # # Store C<$country> (a C<Games::Risk::Country> object) as a country # located within the continent. # sub add_country { my ($self, $country) = @_; my $countries = $self->_countries // []; push @$countries, $country; $self->_countries($countries); } # # my @countries = $continent->countries; # # Return the list of countries located in $continent. # sub countries { my ($self) = @_; return @{ $self->_countries // [] }; } # # $continent->destroy; # # Remove all circular references of $continent, to prevent memory leaks. # #sub DESTROY { say "destroy: $_[0]"; } sub destroy { my ($self) = @_; $self->_countries([]); } # # my $p0wned = $continent->is_owned( $player ); # # Return true if $player is the owner of all $continent's countries. # sub is_owned { my ($self, $player) = @_; return all { $_->owner eq $player } $self->countries; } 1;
__END__