From: realraum Date: Tue, 5 Jul 2011 23:34:09 +0000 (+0000) Subject: added x01 mode X-Git-Url: https://git.realraum.at/?a=commitdiff_plain;h=fd324a0bfe9ee3b2a2b0ddcb89b39986071b6215;p=svn42.git added x01 mode --- diff --git a/dart/Dart.pm b/dart/Dart.pm index 8ceee17..ebb36bb 100644 --- a/dart/Dart.pm +++ b/dart/Dart.pm @@ -188,6 +188,12 @@ sub get_next_active_player 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; diff --git a/dart/dart-301.pl b/dart/dart-301.pl new file mode 120000 index 0000000..1b31b1c --- /dev/null +++ b/dart/dart-301.pl @@ -0,0 +1 @@ +dart-x01.pl \ No newline at end of file diff --git a/dart/dart-42.pl b/dart/dart-42.pl new file mode 120000 index 0000000..1b31b1c --- /dev/null +++ b/dart/dart-42.pl @@ -0,0 +1 @@ +dart-x01.pl \ No newline at end of file diff --git a/dart/dart-501.pl b/dart/dart-501.pl new file mode 120000 index 0000000..1b31b1c --- /dev/null +++ b/dart/dart-501.pl @@ -0,0 +1 @@ +dart-x01.pl \ No newline at end of file diff --git a/dart/dart-701.pl b/dart/dart-701.pl new file mode 120000 index 0000000..1b31b1c --- /dev/null +++ b/dart/dart-701.pl @@ -0,0 +1 @@ +dart-x01.pl \ No newline at end of file diff --git a/dart/dart-x01.pl b/dart/dart-x01.pl new file mode 100644 index 0000000..22bcbcb --- /dev/null +++ b/dart/dart-x01.pl @@ -0,0 +1,76 @@ +#!/usr/bin/perl +use strict; +use Dart; + +$|=1; +my $maxScore = $0; +$maxScore =~ s/.*\-(\d+).pl$/\1/; +my (@player) = @ARGV; + +my $dart = new Dart(player_names=>\@player, + callbacks => { + shoot=>\&shoot, + next_player=>\&next_player, + before_shoot=>\&print_score, + init=>\&init, + } + ); +exit $dart->run(); + +### =============================== + +sub init +{ + my $self=shift; + + for my $player_idx (0..($self->{player_count}-1)) + { + $self->get_player($player_idx)->{score} = $maxScore; + } +} + +sub win_condition +{ + my ($self) = @_; + return $self->get_current_player()->{score} == 0; +} + +sub shoot +{ + my $self=shift; + my ($mult,$zahl)=@_; + + if ($self->get_current_player()->{score} >= $mult * $zahl) + { + $self->get_current_player()->{score} -= $mult * $zahl; + $self->shout_last_shoot(); + $self->win() if &win_condition($self); + } + else + { + $self->shout("miss"); + $self->finish_player_round(); + } +} + +sub next_player +{ + my $self=shift; +} + +sub print_score +{ + my ($self)=@_; + printf STDERR "\n\n"; + printf STDERR "Runde\t%d\n\n",$self->{round}; + for my $player_idx (0..($self->{player_count}-1)) + { + printf STDERR "%s\t", ($player_idx == $self->{current_player})?"(".$self->get_player($player_idx)->{name}.")":$self->get_player($player_idx)->{name}; + } + print STDERR "\n"; + for my $player_idx (0..($self->{player_count}-1)) + { + printf STDERR "%s\t", $self->get_player($player_idx)->{score}; + } + print STDERR "\n"; +}