From: Othmar Gsenger Date: Mon, 4 Jul 2011 18:33:59 +0000 (+0000) Subject: added undo in perl framework X-Git-Url: https://git.realraum.at/?a=commitdiff_plain;h=adc899317657443237e27bcf81fec5ba6f220f80;p=svn42.git added undo in perl framework anti-tee missing --- diff --git a/dart/Dart.pm b/dart/Dart.pm index 203db46..2f38988 100644 --- a/dart/Dart.pm +++ b/dart/Dart.pm @@ -2,6 +2,7 @@ package Dart; use strict; use base 'Exporter'; +use Clone; # new Dart(player_names=>[ 'lala', 'popo' ]); ## Player, Rank, Active, @@ -52,10 +53,13 @@ sub run { my $self=shift; my ($data_in_fh,$sound_out_fh)=@_; + my @history; # $data_in_fh ||= STDIN; # $sound_out_fh ||= STDOUT; $self->{sound_out_fh}=$sound_out_fh; + push @history, Clone::clone($self); + $self->callback('before_shoot'); #while ( my $shoot_data = <$data_in_fh>) while ( my $shoot_data = ) { @@ -68,7 +72,13 @@ sub run $self->shoot($mult,$number); } elsif ($mult eq 'btn') { $self->next_player(); + } elsif ($mult eq 'undo' and $#history) { + pop @history; + $self= pop @history; + $self->callback('undo'); } + push @history, Clone::clone($self); + $self->callback('before_shoot'); } } @@ -89,7 +99,10 @@ sub shoot sub shout_last_shoot { my $self=shift; - if ($self->{current_shoot}{mult} == 2) { + if ($self->{current_shoot}{mult} == 2 && $self->{current_shoot}{number} == 25) { + $self->shout("bullseye"); + return; + } elsif ($self->{current_shoot}{mult} == 2 ) { $self->shout('double'); } elsif ($self->{current_shoot}{mult} == 3) { $self->shout('triple'); @@ -103,8 +116,13 @@ sub shout my $self=shift; my ($what)=@_; my $fh = $self->{sound_out_fh}; - print "$what\n"; - #print $fh "$what\n"; + if ($what eq 25) + { + print "bull\n"; + } else { + print "$what\n"; + } +#print $fh "$what\n"; } sub get_current_player diff --git a/dart/dart-cricket.pl b/dart/dart-cricket.pl index de18e0e..91431d9 100755 --- a/dart/dart-cricket.pl +++ b/dart/dart-cricket.pl @@ -12,6 +12,7 @@ my $dart = new Dart(player_names=>\@player, callbacks => { shoot=>\&shoot, next_player=>\&next_player, + before_shoot=>\&print_score, } ); exit $dart->run(); @@ -71,13 +72,11 @@ sub shoot $self->shout_last_shoot() if ($scored || $self_scored); $self->shout("scored") if $scored; $self->shout("scho") if $scho && not $scored; - &print_score($self); } sub next_player { my $self=shift; - &print_score($self); } sub print_score