use strict;
use base 'Exporter';
use Clone;
+use POSIX;
+use Term::Cap;
+use FileHandle;
+
# new Dart(player_names=>[ 'lala', 'popo' ]);
## Player, Rank, Active,
$self->add_player(&create_player(name=>$player_name,rank=>undef,active=>1));
}
$self->{callbacks}=$params{callbacks};
+
+ open($self->{shout_fifo}, '>>', $params{shout_fifo}) or die $!;
+ $self->{shout_fifo}->autoflush(1);
+
+ my $termios = new POSIX::Termios;
+ $termios->getattr;
+ $self->{term} = Term::Cap->Tgetent( { OSPEED => $termios->getospeed } );
$self->init();
return $self;
}
+sub trace_shoot
+{
+ my $self=shift;
+ my ($property)=@_;
+ push @{$self->{trace_shoot}},$property;
+}
sub get_color
{
$self->{current_player}=0;
$self->{player_count}=@{$self->{player}};
$self->{active_player_count}=$self->{player_count};
+ $self->{trace_shoot_data}={};
$self->callback('init');
}
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);
+ my $STDOUT = new FileHandle '>-';
+ $self->{term}->Tputs('cl', 1, $STDOUT);
$self->callback('before_shoot');
- #while ( my $shoot_data = <$data_in_fh>)
while ( my $shoot_data = <STDIN>)
{
- #print STDERR $schuss;
my ($mult,$number) = split /\s+/, $shoot_data;
if ($mult =~/^\d$/)
next;
}
push @history, Clone::clone($self);
+ $self->{term}->Tputs('cl', 1, $STDOUT);
$self->callback('before_shoot');
}
}
{
$self->{current_shoot}={mult=>$mult,number=>$number};
$self->{current_shoot_count}++;
- return $self->callback('shoot',$mult,$number);
+ my $result = $self->callback('shoot',$mult,$number);
+ for my $trace_prop ( @{$self->{trace_shoot}})
+ {
+ push @{$self->{trace_shoot_data}{$self->{current_player}}},$self->get_current_player()->{$trace_prop};
+ }
+ return $result;
} else {
return 0;
}
}
+sub plot_trace_shoot
+{
+ my $self=shift;
+ my $datastr;
+ for my $player_num (keys %{$self->{trace_shoot_data}})
+ {
+ $datastr.=$self->get_player($player_num)->{name}.':';
+ $datastr.= join ',',@{$self->{trace_shoot_data}{$player_num}};
+ $datastr.="\n";
+ }
+ chomp $datastr;
+ my $plotter;
+ open($plotter,"|./plot.py") or return;
+ print $plotter $datastr;
+ close $plotter;
+}
+
sub shout_last_shoot
{
my $self=shift;
{
my $self=shift;
my ($what)=@_;
- my $fh = $self->{sound_out_fh};
+ my $fh = $self->{shout_fifo};
if ($what eq 25)
{
- print "bull\n";
+ print $fh "bull\n";
} else {
- print "$what\n";
+ print $fh "$what\n";
}
-#print $fh "$what\n";
}
sub get_current_player