PangZero/RecordGame.pm untested

filter: Statementstmt 0.0% 0 / 53 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 78 CC 7 SCAR 32.0
CC
7
Cov
0%
PreAdvanceAction
42.0
Rewind
6.0
Rand
2.0
CRAP 24.5
1 ##########################################################################
2 package Games::PangZero::RecordGame;
3 ##########################################################################
4  
5 @ISA = qw(Games::PangZero::PanicGame);
6 use strict;
7 use warnings;
8  
9 sub Rand {
10 my $self = shift;
11 my $result = int(rand($_[0]) * 100) / 100;
12 push @{$self->{rand}}, ($result);
13 return $result;
14 }
15  
16 sub Rewind {
17 my $self = shift;
18 my ($recordEnd, $playback);
19
20 $recordEnd = length($self->{record}) - $Games::PangZero::NumGuys * 1000;
21 return if $recordEnd <= 0;
22 $self->{record} = substr($self->{record}, 0, $recordEnd);
23 $Games::PangZero::Game = $playback
24 = DemoPlaybackGame->new($Games::PangZero::NumGuys, $Games::PangZero::DifficultyLevel, $self->{record}, $self->{rand}, {});
25 $playback->{skip} = 1;
26 SDL::Video::blit_surface($Games::PangZero::Background, SDL::Rect->new(0, 0, $Games::PangZero::App->w, $Games::PangZero::App->h), $Games::PangZero::App, SDL::Rect->new(0, 0, $Games::PangZero::App->w, $Games::PangZero::App->h));
27 $playback->Run();
28
29 $playback->RestoreGameSettings();
30 %{$self} = %{$playback};
31 $Games::PangZero::Game = $self;
32 $self->{abortgame} = 0;
33 print "Splicing {rand}: original length is ", scalar(@{$self->{rand}}), "; playback randpointer is $playback->{randpointer}.\n";
34 splice @{$self->{rand}}, $playback->{randpointer};
35 SDL::Video::blit_surface($Games::PangZero::Background, SDL::Rect->new(0, 0, $Games::PangZero::App->w, $Games::PangZero::App->h), $Games::PangZero::App, SDL::Rect->new(0, 0, $Games::PangZero::App->w, $Games::PangZero::App->h));
36 $self->DrawGame();
37 %Games::PangZero::Events = %Games::PangZero::Keys = ();
38
39 while( not %Games::PangZero::Events ) {
40 Games::PangZero::HandleEvents();
41 $Games::PangZero::App->delay(100);
42 }
43 GameTimer::ResetTimer();
44 }
45  
46 sub PreAdvanceAction {
47 my $self = shift;
48 $self->Rewind() if $Games::PangZero::Events{::SDLK_F3()};
49
50 for (my $i = 0; $i < $Games::PangZero::NumGuys; ++$i) {
51 my $keys = $Games::PangZero::Players[$i]->{keys};
52 my $record = 0;
53 $record += 1 if $Games::PangZero::Keys{$keys->[0]};
54 $record += 2 if $Games::PangZero::Keys{$keys->[1]};
55 $record += 4 if $Games::PangZero::Events{$keys->[2]};
56 if ($Games::PangZero::Events{SDLK_F2()} and $Games::PangZero::NumGuys == 1) {
57 $record += 8;
58 $Games::PangZero::GameEvents{superkill} = 1;
59 }
60 $self->{record} .= $record;
61 }
62 }
63  
64 1;