From 4fa78e69f33a6597822418749b9552c7805d0172 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sun, 15 Jan 2012 01:51:05 +0000 Subject: [PATCH] clear screen works now --- dart/Dart.pm | 29 +++++++++++++++++------------ dart/dart-cricket.pl | 17 +++++++++-------- dart/dart-red-x01.pl | 15 ++++++++------- dart/dart-schiffe.pl | 36 ++++++++++++++++++------------------ dart/dart-x01.pl | 17 ++++++++++------- dart/start-dart.sh | 11 +++++++---- 6 files changed, 69 insertions(+), 56 deletions(-) mode change 100644 => 100755 dart/dart-x01.pl diff --git a/dart/Dart.pm b/dart/Dart.pm index 51f3554..ac7775d 100644 --- a/dart/Dart.pm +++ b/dart/Dart.pm @@ -3,6 +3,10 @@ package Dart; use strict; use base 'Exporter'; use Clone; +use POSIX; +use Term::Cap; +use FileHandle; + # new Dart(player_names=>[ 'lala', 'popo' ]); ## Player, Rank, Active, @@ -20,6 +24,13 @@ sub new $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; } @@ -83,19 +94,14 @@ sub callback 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 = ) { - #print STDERR $schuss; my ($mult,$number) = split /\s+/, $shoot_data; if ($mult =~/^\d$/) @@ -118,7 +124,7 @@ sub run next; } push @history, Clone::clone($self); - print "\033[2J"; + $self->{term}->Tputs('cl', 1, $STDOUT); $self->callback('before_shoot'); } } @@ -178,14 +184,13 @@ sub shout { 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 diff --git a/dart/dart-cricket.pl b/dart/dart-cricket.pl index f96b0b9..55b4d02 100755 --- a/dart/dart-cricket.pl +++ b/dart/dart-cricket.pl @@ -6,9 +6,10 @@ our $sieb =1; # Spielmodus Zahlensieb $|=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, @@ -115,25 +116,25 @@ sub 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}); } } diff --git a/dart/dart-red-x01.pl b/dart/dart-red-x01.pl index af4491c..b06b8a6 100755 --- a/dart/dart-red-x01.pl +++ b/dart/dart-red-x01.pl @@ -5,9 +5,10 @@ use Dart; $|=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, @@ -61,16 +62,16 @@ sub 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"; } diff --git a/dart/dart-schiffe.pl b/dart/dart-schiffe.pl index 9687de2..7fa1b67 100755 --- a/dart/dart-schiffe.pl +++ b/dart/dart-schiffe.pl @@ -10,10 +10,10 @@ our %y = array_to_hash(@y); 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, @@ -205,9 +205,9 @@ sub prcl { 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 @@ -243,20 +243,20 @@ sub print_score 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}; @@ -267,13 +267,13 @@ sub print_score &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"; } diff --git a/dart/dart-x01.pl b/dart/dart-x01.pl old mode 100644 new mode 100755 index 8a73306..de5a7f3 --- a/dart/dart-x01.pl +++ b/dart/dart-x01.pl @@ -5,9 +5,10 @@ use Dart; $|=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, @@ -15,6 +16,8 @@ my $dart = new Dart(player_names=>\@player, init=>\&init, } ); + + exit $dart->run(); ### =============================== @@ -63,16 +66,16 @@ sub 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"; } diff --git a/dart/start-dart.sh b/dart/start-dart.sh index e73380c..db7a080 100755 --- a/dart/start-dart.sh +++ b/dart/start-dart.sh @@ -11,8 +11,10 @@ mode=$1 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 @@ -23,9 +25,10 @@ signal_handler() 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 -- 1.7.10.4