sub reset_game
{
my $self=shift;
- my @sort_player = sort { $a->{rank} <=> $b->{rank} } @{$self->{player}};
+ my @sort_player = sort { $b->{rank} <=> $a->{rank} } @{$self->{player}};
$self->{player}=[];
for my $player (@sort_player)
{
if ($mult =~/^\d$/)
{
die "Unexpected input" if not $number=~/^\d+$/;
+ next if not $self->{current_shoot_count} < $self->{max_shoots_per_player};
$self->shoot($mult,$number);
} elsif ($mult eq 'btn') {
$self->next_player();
$self->callback('undo');
} elsif ($mult eq 'reset') {
$self->reset_game();
+ } elsif ($mult eq 'quit') {
+ return;
+ } else {
+ # shitty input
+ next;
}
push @history, Clone::clone($self);
$self->callback('before_shoot');
$new_round=1;
}
}
- while (not $players_ref->[$current_player]{active});
+ while (not $self->{player}->[$current_player]{active});
return ($current_player,$new_round);
}
+sub finish_player_round
+{
+ my $self=shift;
+ $self->{current_shoot_count} = $self->{max_shoots_per_player};
+}
+
sub next_round
{
my $self=shift;
sub win
{
my $self=shift;
- $self->deactivate_current_player($self->{player_count}-$self->{active_player_count}+1);
$self->shout('win');
+ $self->deactivate_current_player($self->{player_count}-$self->{active_player_count}+1);
if ($self->{active_player_count}==1)
{
$self->next_player();
- $self->lose();
- } elsif (not $self->{active_player_count}) {
- $self->end_game();
+ $self->shout('lose');
+ $self->deactivate_current_player($self->{player_count}-$self->{active_player_count}+1);
}
}
sub lose
{
my $self=shift;
- $self->deactivate_current_player($self->{active_player_count});
$self->shout('lose');
+ $self->deactivate_current_player($self->{active_player_count});
if ($self->{active_player_count}==1)
{
$self->next_player();
- $self->win();
- } elsif (not $self->{active_player_count}) {
- $self->end_game();
+ $self->shout('win');
+ $self->deactivate_current_player($self->{active_player_count});
}
}