Chess-GameClock-GameClock

 view release on metacpan or  search on metacpan

lib/Chess/GameClock/GclkCounter.pm  view on Meta::CPAN

  }
  # set the new counters state
  if ( $mouse eq $whites->[0]{mouse}) {
    $whites->[0]{newstate} ="Off" ;
    $blacks->[0]{newstate} ="On" ;
  } else {
    $whites->[0]{newstate} ="On" ;
    $blacks->[0]{newstate} ="Off" ;
  }
  $whites->cntupdate($tod) ;
  $blacks->cntupdate($tod) ;

  # print into the log

  my $str=sprintf("%02d:%02d:%02d",$hour,$min,$sec) ;
  print
    "Time: $str \n
     Whites move: $whites->[0]{mvt} whites time Av.:$whites->[0]{ct} #$whites->[0]{mv}\n 
     Blacks move: $blacks->[0]{mvt} Blacks time Av.:$blacks->[0]{ct} #$blacks->[0]{mv}\n" ;

   }

sub print{
  my $self=shift ;
  #print " Counter elem: $$self[0]{state} \n" ; 
  #print " Counter elem: $self->[0]->{state} \n" ; 
  #print " Counter elem: $self->[0]{state} \n" ;  
  # print the whole thing with refs
  for my $href ( @{$self} ) {
    print "{ ";
    for my $t ( keys %$href ) {
      print "$t=$href->{$t} ";
    }
    print "}\n";
  }
}


=head1 NAME

  GclkCounter - The Heart of GameClock

=head1 VERSION

Version 1.0

=cut

=head1 SYNOPSIS

This module does everythings at counter level.
It makes counters,inits them, update them, captures events,
start , halt , eventually print the internal datas

    use GclkCounter;

    $whites=GclkCounter->new ;
    $whites->init($arg,$color) ;
    $whites-> cntupdate{$timestamp);
    $whites->print ;
#  the functions hereafter are only used  inside callbacks
    &start($whites,$blacks,$mainwindow,$white_move_button,$black_move_button)= ;
    &stop($halt_button,$whites,$blacks) ;
    &capture($mouse_event,$whites,$blacks ) ;

=head1 EXPORT

&capture
&stop
$start

=head1 FUNCTIONS

=head2 new ;

Create object GclkCounter 

=cut
 
=head2 init

  Get the parameters from GameClock directly or via Gamesettings
  and adapts the datas for the counters

=head2 cntupdate

When an event more precisely a mouse button is
released the state of the counter changes.
This determines the following actions:

=over 4

=item * Change the counter states.

=item * Check times

=item * Update the time counters

=item * Update the move counters

=item * Update the sequence pointers

=back

=head2 capture

When a mouse event occurs the first time
after enabling the start mode, it determines
the mouse button for each player, knowing that
the Blacks must push the button at first.
It set the newsate of each counter accorging
to the mouse button pressed, and after that,
it gets a timestamp for calling the methode cntupdate.

=cut

=head2 start

Initialization of the program to begin
the counting mode.



( run in 0.682 second using v1.01-cache-2.11-cpan-39bf76dae61 )