ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/kgsueme/kgsueme/game.pl
(Generate patch)

Comparing kgsueme/kgsueme/game.pl (file contents):
Revision 1.103 by pcg, Sun May 30 06:53:29 2004 UTC vs.
Revision 1.104 by pcg, Sun May 30 07:24:06 2004 UTC

78 # and this gives smoother timers ;) 78 # and this gives smoother timers ;)
79 my $timer2 = int $timer + 0.4; 79 my $timer2 = int $timer + 0.4;
80 80
81 if ($timer2 <= 0) { 81 if ($timer2 <= 0) {
82 $timer2 = 0 if $timer2 < 0; 82 $timer2 = 0 if $timer2 < 0;
83 $self->set_text ("TIME OVER"); 83 $self->set_text ("TIME OUT");
84 } else { 84 } else {
85 $self->set_text ($self->{format}->($timer2)); 85 $self->set_text ($self->{format}->($timer2));
86 } 86 }
87 87
88 $timer - int $timer; 88 $timer - int $timer;
254 254
255 $hbox->pack_start ((my $scale = new Gtk2::HScale $self->{moveadj}), 1, 1, 0); 255 $hbox->pack_start ((my $scale = new Gtk2::HScale $self->{moveadj}), 1, 1, 0);
256 $scale->set_draw_value (0); 256 $scale->set_draw_value (0);
257 $scale->set_digits (0); 257 $scale->set_digits (0);
258 258
259 $self->{moveadj}->signal_connect (value_changed => sub { $self->update_board }); 259 $self->{moveadj}->signal_connect (value_changed => sub {
260 $self->{showmove} = int $self->{moveadj}->get_value;
261 $self->update_board;
262 });
260 } 263 }
261 264
262 $vbox->pack_start ((my $hbox = new Gtk2::HBox 1), 0, 1, 0); 265 $vbox->pack_start ((my $hbox = new Gtk2::HBox 1), 0, 1, 0);
263 266
264 $hbox->add ($self->{userpanel}[$_] = new game::userpanel colour => $_) 267 $hbox->add ($self->{userpanel}[$_] = new game::userpanel colour => $_)
347} 350}
348 351
349sub update_cursor { 352sub update_cursor {
350 my ($self) = @_; 353 my ($self) = @_;
351 354
352 my $move = int $self->{moveadj}->get_value;
353 my $cb;
354
355 my $running = $move == @{$self->{path}} && $self->is_active; 355 my $running = $self->{showmove} == @{$self->{path}} && $self->is_active;
356 356
357 delete $self->{board_click}; 357 delete $self->{board_click};
358 358
359 if ($self->{teacher} eq $self->{app}{conn}) { 359 if ($self->{teacher} eq $self->{app}{conn}) {
360 #TODO# # teaching mode not implemented 360 #TODO# # teaching mode not implemented
415 $self->{board}->set (cursor => undef); 415 $self->{board}->set (cursor => undef);
416 #TODO# # implement coordinate-grabbing 416 #TODO# # implement coordinate-grabbing
417 } 417 }
418} 418}
419 419
420sub update_timers {
421 my ($self, $timers) = @_;
422
423 my $running = $self->{showmove} == @{$self->{path}} && !$self->{teacher};
424
425 for my $colour (COLOUR_BLACK, COLOUR_WHITE) {
426 my $t = $timers->[$colour];
427 $self->{userpanel}[$colour]->set_timer (
428 $running && $self->{lastmove_colour} == 1 - $colour && $t->[0],
429 $t->[1], $t->[2]);
430 }
431}
432
420sub update_board { 433sub update_board {
421 my ($self) = @_; 434 my ($self) = @_;
422 return unless $self->{path}; 435 return unless $self->{path};
423 436
424 my $move = int $self->{moveadj}->get_value;
425
426 $self->{board_label}->set_text ("Move " . ($move - 1)); 437 $self->{board_label}->set_text ("Move " . ($self->{showmove} - 1));
427 438
428 $self->{cur_board} = new KGS::Game::Board $self->{size}; 439 $self->{cur_board} = new KGS::Game::Board $self->{size};
429 $self->{cur_board}->interpret_path ([@{$self->{path}}[0 .. $move - 1]]); 440 $self->{cur_board}->interpret_path ([@{$self->{path}}[0 .. $self->{showmove} - 1]]);
430 441
431 $self->{userpanel}[$_]->set_captures ($self->{cur_board}{captures}[$_]) 442 $self->{userpanel}[$_]->set_captures ($self->{cur_board}{captures}[$_])
432 for COLOUR_WHITE, COLOUR_BLACK; 443 for COLOUR_WHITE, COLOUR_BLACK;
433 444
434 if ($move == @{$self->{path}}) { 445 if ($self->{showmove} == @{$self->{path}}) {
435 $self->inject_set_gametime ($self->{gametime}) if $self->{gametime}; 446 $self->{timers} = [
447 [$self->{lastmove_time}, @{$self->{cur_board}{timer}[0]}],
448 [$self->{lastmove_time}, @{$self->{cur_board}{timer}[1]}],
449 ];
450 $self->update_timers ($self->{timers});
436 } else { 451 } else {
437 $self->{userpanel}[$_]->set_timer (0, @{$self->{cur_board}{timer}[$_]}) 452 $self->update_timers ([
438 for COLOUR_WHITE, COLOUR_BLACK; 453 [0, @{$self->{cur_board}{timer}[0]}],
454 [0, @{$self->{cur_board}{timer}[1]}],
455 ]);
439 } 456 }
440 457
441 $self->{board}->set_board ($self->{cur_board}); 458 $self->{board}->set_board ($self->{cur_board});
442 459
443 $self->update_cursor; 460 $self->update_cursor;
651 668
652sub event_out_of_time { 669sub event_out_of_time {
653 my ($self, $player) = @_; 670 my ($self, $player) = @_;
654 671
655 sound::play 3, "timewin"; 672 sound::play 3, "timewin";
656 $self->{chat}->append_text ("\n<infoblock><header>Time Over</header>" 673 $self->{chat}->append_text ("\n<infoblock><header>Out of Time</header>"
657 . "\n<user>" 674 . "\n<user>"
658 . (util::toxml $self->{user}[$msg->{player}]->as_string) 675 . (util::toxml $self->{user}[$msg->{player}]->as_string)
659 . "</user> ran out of time.</infoblock>"); 676 . "</user> ran out of time and lost.</infoblock>");
660} 677}
661 678
662sub event_done { 679sub event_done {
663 my ($self) = @_; 680 my ($self) = @_;
664 681
679} 696}
680 697
681sub inject_set_gametime { 698sub inject_set_gametime {
682 my ($self, $msg) = @_; 699 my ($self, $msg) = @_;
683 700
684 $self->{gametime} = $msg; 701 $self->{timers} = [
685
686 my $move = int $self->{moveadj}->get_value;
687
688 my $running = $move == @{$self->{path}} && !$self->{teacher};
689
690 $self->{userpanel}[COLOUR_BLACK]->set_timer (
691 $running && $self->{lastmove_colour} == COLOUR_WHITE && $msg->{NOW},
692 $msg->{black_time}, $msg->{black_moves}); 702 [$msg->{NOW}, $msg->{black_time}, $msg->{black_moves}],
693 $self->{userpanel}[COLOUR_WHITE]->set_timer (
694 $running && $self->{lastmove_colour} == COLOUR_BLACK && $msg->{NOW},
695 $msg->{white_time}, $msg->{white_moves}); 703 [$msg->{NOW}, $msg->{white_time}, $msg->{white_moves}],
704 ];
705
706 print "SGT\n";#d#
707 $self->update_timers ($self->{timers})
708 if $self->{showmove} == @{$self->{path}};
696} 709}
697 710
698sub inject_req_undo { 711sub inject_req_undo {
699 my ($self, $msg) = @_; 712 my ($self, $msg) = @_;
700 713

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines