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 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);
- print "\033[2J";
+ 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);
- print "\033[2J";
+ $self->{term}->Tputs('cl', 1, $STDOUT);
$self->callback('before_shoot');
}
}
{
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
$|=1;
-my (@player) = @ARGV;
+my ($shout_fifo, @player) = @ARGV;
my $dart = new Dart(player_names=>\@player,
+ shout_fifo=>$shout_fifo,
callbacks => {
shoot=>\&shoot,
next_player=>\&next_player,
sub print_score
{
my ($self)=@_;
- printf STDERR "\n\n";
- printf STDERR "Runde\t%d\n\n",$self->{round};
+ printf "\n\n";
+ printf "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};
+ printf "%s\t", ($player_idx == $self->{current_player})?"(".$self->get_player($player_idx)->{name}.")":$self->get_player($player_idx)->{name};
}
- print STDERR "\n";
+ print "\n";
for my $i (1..21)
{
for my $player_idx (0..($self->{player_count}-1))
{
my $zahl = $i>20?25:$i;
next if not gueltig($zahl);
- printf STDERR ("%2d %s ",$zahl, '#' x $self->get_player($player_idx)->{score}->{$zahl}. '-' x (3-$self->get_player($player_idx)->{score}->{$zahl}));
+ printf ("%2d %s ",$zahl, '#' x $self->get_player($player_idx)->{score}->{$zahl}. '-' x (3-$self->get_player($player_idx)->{score}->{$zahl}));
}
- print STDERR "\n";
+ print "\n";
}
for my $player_idx (0..($self->{player_count}-1))
{
- printf STDERR ("%3d\t", $self->get_player($player_idx)->{score}->{0});
+ printf ("%3d\t", $self->get_player($player_idx)->{score}->{0});
}
}
$|=1;
my $maxScore = $0;
$maxScore =~ s/.*\-(\d+).pl$/\1/;
-my (@player) = @ARGV;
+my ($shout_fifo, @player) = @ARGV;
my $dart = new Dart(player_names=>\@player,
+ shout_fifo=>$shout_fifo,
callbacks => {
shoot=>\&shoot,
next_player=>\&next_player,
sub print_score
{
my ($self)=@_;
- printf STDERR "\n\n";
- printf STDERR "Runde\t%d\n\n",$self->{round};
+ printf "\n\n";
+ printf "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};
+ printf "%s\t", ($player_idx == $self->{current_player})?"(".$self->get_player($player_idx)->{name}.")":$self->get_player($player_idx)->{name};
}
- print STDERR "\n";
+ print "\n";
for my $player_idx (0..($self->{player_count}-1))
{
- printf STDERR "%s\t", $self->get_player($player_idx)->{score};
+ printf "%s\t", $self->get_player($player_idx)->{score};
}
- print STDERR "\n";
+ print "\n";
}
our @schiffe = reverse sort qw/ 4 5 6 /;
$|=1;
-my (@player) = @ARGV;
-
+my ($shout_fifo, @player) = @ARGV;
my $dart = new Dart(player_names=>\@player,
+ shout_fifo=>$shout_fifo,
callbacks => {
shoot=>\&shoot,
before_shoot=>\&print_score,
{
my $self = shift;
my ($color,@what)=@_;
- print STDERR color($color) if defined $color;
- print STDERR @what;
- print STDERR color('reset');
+ print color($color) if defined $color;
+ print @what;
+ print color('reset');
}
sub get_color
my $sel_y= $player->{sel_y};
my $mult_x=$player->{mult_x};
my $mult_y=$player->{mult_y};
- printf STDERR "Runde\t%d\n\n",$self->{round};
- printf STDERR "Player\t%s\t\tSchuss\t%d\n\n",$player->{name},$self->{current_shoot_count};
- printf STDERR "x: %dx%2d\n",$player->{mult_x},$player->{sel_x};
- printf STDERR "y: %dx%2d\n",$player->{mult_y},$player->{sel_y};
+ printf "Runde\t%d\n\n",$self->{round};
+ printf "Player\t%s\t\tSchuss\t%d\n\n",$player->{name},$self->{current_shoot_count};
+ printf "x: %dx%2d\n",$player->{mult_x},$player->{sel_x};
+ printf "y: %dx%2d\n",$player->{mult_y},$player->{sel_y};
- print STDERR " ";
+ print " ";
for my $y (@main::y)
{
- printf STDERR " %2d",$y;
+ printf " %2d",$y;
}
- print STDERR "\n";
+ print "\n";
for my $x (@main::x)
{
- printf STDERR "%2d",$x;
+ printf "%2d",$x;
for my $y (@main::y)
{
my $field = $self->get_current_player()->{score}->{$x}{$y};
&prxy($self,$x,$y," .");
}
}
- printf STDERR " %d",$x;
- print STDERR "\n";
+ printf " %d",$x;
+ print "\n";
}
- print STDERR " ";
+ print " ";
for my $y (@main::y)
{
- printf STDERR " %2d",$y;
+ printf " %2d",$y;
}
- print STDERR "\n\n";
+ print "\n\n";
}
$|=1;
my $maxScore = $0;
$maxScore =~ s/.*\-(\d+).pl$/\1/;
-my (@player) = @ARGV;
+my ($shout_fifo, @player) = @ARGV;
my $dart = new Dart(player_names=>\@player,
+ shout_fifo=>$shout_fifo,
callbacks => {
shoot=>\&shoot,
next_player=>\&next_player,
init=>\&init,
}
);
+
+
exit $dart->run();
### ===============================
sub print_score
{
my ($self)=@_;
- printf STDERR "\n\n";
- printf STDERR "Runde\t%d\n\n",$self->{round};
+ printf "\n\n";
+ printf "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};
+ printf "%s\t", ($player_idx == $self->{current_player})?"(".$self->get_player($player_idx)->{name}.")":$self->get_player($player_idx)->{name};
}
- print STDERR "\n";
+ print "\n";
for my $player_idx (0..($self->{player_count}-1))
{
- printf STDERR "%s\t", $self->get_player($player_idx)->{score};
+ printf "%s\t", $self->get_player($player_idx)->{score};
}
- print STDERR "\n";
+ print "\n";
}
shift
FIFO_D=`mktemp -d`
-FIFO=$FIFO_D/dart.fifo
-mkfifo $FIFO
+FIFO_IN=$FIFO_D/dart-in.fifo
+FIFO_SHOUT=$FIFO_D/dart-out.fifo
+mkfifo $FIFO_IN
+mkfifo $FIFO_SHOUT
trap signal_handler INT TERM
stty -echo
ssh dart killall ttyread 2>&1
-ssh dart ttyread /dev/ttyDart >$FIFO &
+ssh dart ttyread /dev/ttyDart >$FIFO_IN &
cd $MYPATH
-$MYPATH/eet $FIFO | perl -I $MYPATH $MYPATH/dart-$mode.pl $* | $MYPATH/../dart-sounds/src/dart-sounds $MYPATH/../dart-sounds/media > /dev/null
+$MYPATH/../dart-sounds/src/dart-sounds $MYPATH/../dart-sounds/media > /dev/null <$FIFO_SHOUT &
+$MYPATH/eet $FIFO_IN | perl -I $MYPATH $MYPATH/dart-$mode.pl $FIFO_SHOUT $*
rm -rf $FIFO_D
exit 0