From d96e3a99d81c498c26e7f000a0bd98953fc40e22 Mon Sep 17 00:00:00 2001 From: Othmar Gsenger Date: Mon, 4 Jul 2011 18:55:11 +0000 Subject: [PATCH] added end game, win, lose --- dart/Dart.pm | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/dart/Dart.pm b/dart/Dart.pm index 2f38988..7352fc2 100644 --- a/dart/Dart.pm +++ b/dart/Dart.pm @@ -177,6 +177,34 @@ sub next_round return $self->callback('next_round'); } +sub win +{ + my $self=shift; + $self->deactivate_current_player($self->{player_count}-$self->{active_player_count}+1); + $self->shout('win'); + if ($self->{active_player_count}==1) + { + $self->next_player(); + $self->lose(); + } elsif (not $self->{active_player_count}) { + $self->end_game(); + } +} + +sub lose +{ + my $self=shift; + $self->deactivate_current_player($self->{active_player_count}); + $self->shout('lose'); + if ($self->{active_player_count}==1) + { + $self->next_player(); + $self->win(); + } elsif (not $self->{active_player_count}) { + $self->end_game(); + } +} + sub deactivate_current_player { my $self=shift; @@ -191,6 +219,7 @@ sub deactivate_current_player sub end_game { my $self=shift; + $self->shout('end_game'); return $self->callback('end_game'); } -- 1.7.10.4