Games-Risk
view release on metacpan or search on metacpan
lib/Games/Risk/Controller.pm view on Meta::CPAN
my $looser = $dst->owner;
# update the countries
$src->set_armies( $src->armies - $nb );
$dst->set_armies( $nb );
$dst->set_owner( $src->owner );
# update the gui
$h->send_to_all('chnum', $src);
$h->send_to_all('chown', $dst, $looser);
# check if previous $dst owner has lost.
if ( scalar($looser->countries) == 0 ) {
# omg! one player left
$h->player_lost($looser);
$h->send_to_all('player_lost', $looser);
# distribute cards from lost player to the one who crushed her
my @cards = $looser->cards->all;
my $player = $h->curplayer;
lib/Games/Risk/Controller.pm view on Meta::CPAN
my @players = $h->players;
my @countries = shuffle $h->map->countries;
while ( my $country = shift @countries ) {
# rotate players
my $player = shift @players;
push @players, $player;
# store new owner & place one army to start with
$country->set_owner($player);
$country->set_armies(1);
$h->send_to_all('chown', $country);
}
# go on to the next phase
K->yield( '_countries_assigned' );
}
#
# start the attack phase for curplayer
#
lib/Games/Risk/Tk/Continents.pm view on Meta::CPAN
# session destruction.
#
sub STOP {
debug( "gui-continents shutdown\n" );
}
# -- public events
event chown => sub {
my ($self, $country, $looser) = @_[OBJECT, ARG0, ARG1];
my $owner = $country->owner;
# continent information
my $continent = $country->continent;
my $row = 1 + firstidx { $_ eq $continent } $self->_continents;
# mark table as enabled to update it
my $tm = $self->_w('tm');
$tm->configure(enabled);
lib/Games/Risk/Tk/Continents.pm view on Meta::CPAN
=head1 ATTRIBUTES
=head2 parent
A L<Tk> window that will be the parent of the toplevel window created.
This parameter is mandatory.
=head1 METHODS
=head2 chown
$K->post( 'gui-continents' => chown => $country, $looser);
Update the country count of player for a given continent.
=head2 player_add
$K->post( 'gui-continents' => player_add => $player );
Add a new column in the table to display the new player.
=head2 shutdown
lib/Games/Risk/Tk/Main.pm view on Meta::CPAN
$c->CanvasBind('<1>', undef);
$c->CanvasBind('<3>', undef);
$self->_action('attack_redo')->disable;
$self->_action('attack_done')->disable;
$self->_w('lab_step_attack')->configure(disabled);
};
event chnum => \&_do_country_redraw;
event chown => \&_do_country_redraw;
event _country_redraw => \&_do_country_redraw;
sub _do_country_redraw {
my ($self, $country) = @_[OBJECT, ARG0];
my $c = $self->_w('canvas');
my $id = $country->id;
my $owner = $country->owner;
my $fakein = $self->_fake_armies_in->{$id} // 0;
my $fakeout = $self->_fake_armies_out->{$id} // 0;
my $armies = ($country->armies // 0) + $fakein - $fakeout;
lib/Games/Risk/Tk/Main.pm view on Meta::CPAN
C<@defence> dices.
=head2 attack_move
attack_move()
Prevent user to re-attack till he moved the armies.
=head2 chnum
=head2 chown
chnum( $country )
chown( $country )
Force C<$country> to be redrawn: owner and number of armies.
=head2 flash_country
flash_country( $country , [ $state, $left ] )
Request C<$country> to be flashed on the map. This is done by extracting
the country from the greyscale image, and paint it in white on the
canvas.
( run in 1.010 second using v1.01-cache-2.11-cpan-71847e10f99 )