| 1 | package Game::Floppy; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 15 | ▶ | use 5.014; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 15 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 15 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | 15 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | 15 | ▶ | use Digest::SHA (); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | 15 | ▶ | use Object::Proto::Sugar -types; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | 15 | ▶ | use Game::Floppy::Error; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | 15 | ▶ | use Game::Floppy::Result; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | 15 | our $VERSION = '0.09'; | |||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | has width => ( | ||||||||||||||||||||||||||||||||
| 17 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 18 | isa => Int, | ||||||||||||||||||||||||||||||||
| 19 | default => 516 | ||||||||||||||||||||||||||||||||
| 20 | 15 | ); | |||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | has height => ( | ||||||||||||||||||||||||||||||||
| 23 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 24 | isa => Int, | ||||||||||||||||||||||||||||||||
| 25 | default => 400 | ||||||||||||||||||||||||||||||||
| 26 | 15 | ); | |||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | has seed => ( | ||||||||||||||||||||||||||||||||
| 29 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 30 | isa => Str, | ||||||||||||||||||||||||||||||||
| 31 | default => 'Game::Floppy' | ||||||||||||||||||||||||||||||||
| 32 | 15 | ); | |||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||
| 34 | has bird_x => ( | ||||||||||||||||||||||||||||||||
| 35 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 36 | isa => Int, | ||||||||||||||||||||||||||||||||
| 37 | default => 80 | ||||||||||||||||||||||||||||||||
| 38 | 15 | ); | |||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||
| 40 | has bird_radius => ( | ||||||||||||||||||||||||||||||||
| 41 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 42 | isa => Int, | ||||||||||||||||||||||||||||||||
| 43 | default => 24 | ||||||||||||||||||||||||||||||||
| 44 | 15 | ); | |||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||
| 46 | has gravity => ( | ||||||||||||||||||||||||||||||||
| 47 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 48 | isa => Int, | ||||||||||||||||||||||||||||||||
| 49 | default => 3 | ||||||||||||||||||||||||||||||||
| 50 | 15 | ); | |||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||
| 52 | has lift => ( | ||||||||||||||||||||||||||||||||
| 53 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 54 | isa => Int, | ||||||||||||||||||||||||||||||||
| 55 | default => 30 | ||||||||||||||||||||||||||||||||
| 56 | 15 | ); | |||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||
| 58 | has tube_every => ( | ||||||||||||||||||||||||||||||||
| 59 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 60 | isa => Int, | ||||||||||||||||||||||||||||||||
| 61 | default => 100 | ||||||||||||||||||||||||||||||||
| 62 | 15 | ); | |||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||
| 64 | has tube_speed => ( | ||||||||||||||||||||||||||||||||
| 65 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 66 | isa => Int, | ||||||||||||||||||||||||||||||||
| 67 | default => 3 | ||||||||||||||||||||||||||||||||
| 68 | 15 | ); | |||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||
| 70 | has tube_width => ( | ||||||||||||||||||||||||||||||||
| 71 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 72 | isa => Int, | ||||||||||||||||||||||||||||||||
| 73 | default => 52 | ||||||||||||||||||||||||||||||||
| 74 | 15 | ); | |||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||
| 76 | has gap => ( | ||||||||||||||||||||||||||||||||
| 77 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 78 | isa => Int, | ||||||||||||||||||||||||||||||||
| 79 | default => 140 | ||||||||||||||||||||||||||||||||
| 80 | 15 | ); | |||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||
| 82 | has tube_score => ( | ||||||||||||||||||||||||||||||||
| 83 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 84 | isa => Int, | ||||||||||||||||||||||||||||||||
| 85 | default => 100 | ||||||||||||||||||||||||||||||||
| 86 | 15 | ); | |||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | has _tubes => ( | ||||||||||||||||||||||||||||||||
| 89 | is => 'rw', | ||||||||||||||||||||||||||||||||
| 90 | isa => ArrayRef, | ||||||||||||||||||||||||||||||||
| 91 | 239 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 92 | private => 1 | ||||||||||||||||||||||||||||||||
| 93 | 15 | ); | |||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||
| 95 | 15 | has _y => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||
| 96 | 15 | has _cause => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||
| 97 | 15 | has _error => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||
| 99 | has _flap => ( | ||||||||||||||||||||||||||||||||
| 100 | is => 'rw', | ||||||||||||||||||||||||||||||||
| 101 | isa => Int, | ||||||||||||||||||||||||||||||||
| 102 | default => 0, | ||||||||||||||||||||||||||||||||
| 103 | private => 1 | ||||||||||||||||||||||||||||||||
| 104 | 15 | ); | |||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||
| 106 | has _tilt => ( | ||||||||||||||||||||||||||||||||
| 107 | is => 'rw', | ||||||||||||||||||||||||||||||||
| 108 | isa => Int, | ||||||||||||||||||||||||||||||||
| 109 | default => 0, | ||||||||||||||||||||||||||||||||
| 110 | private => 1 | ||||||||||||||||||||||||||||||||
| 111 | 15 | ); | |||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||
| 113 | has _spawned => ( | ||||||||||||||||||||||||||||||||
| 114 | is => 'rw', | ||||||||||||||||||||||||||||||||
| 115 | isa => Int, | ||||||||||||||||||||||||||||||||
| 116 | default => 0, | ||||||||||||||||||||||||||||||||
| 117 | private => 1 | ||||||||||||||||||||||||||||||||
| 118 | 15 | ); | |||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||
| 120 | has _score => ( | ||||||||||||||||||||||||||||||||
| 121 | is => 'rw', | ||||||||||||||||||||||||||||||||
| 122 | isa => Int, | ||||||||||||||||||||||||||||||||
| 123 | default => 0, | ||||||||||||||||||||||||||||||||
| 124 | private => 1 | ||||||||||||||||||||||||||||||||
| 125 | 15 | ); | |||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||
| 127 | has _ticks => ( | ||||||||||||||||||||||||||||||||
| 128 | is => 'rw', | ||||||||||||||||||||||||||||||||
| 129 | isa => Int, | ||||||||||||||||||||||||||||||||
| 130 | default => 0, | ||||||||||||||||||||||||||||||||
| 131 | private => 1 | ||||||||||||||||||||||||||||||||
| 132 | 15 | ); | |||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||
| 134 | has _status => ( | ||||||||||||||||||||||||||||||||
| 135 | is => 'rw', | ||||||||||||||||||||||||||||||||
| 136 | isa => Str, | ||||||||||||||||||||||||||||||||
| 137 | default => 'ready', | ||||||||||||||||||||||||||||||||
| 138 | private => 1 | ||||||||||||||||||||||||||||||||
| 139 | 15 | ); | |||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||
| 141 | 2462 | ▶ | my $spawn = sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 142 | 2462 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 143 | 2462 | my $k = $self->_spawned; | |||||||||||||||||||||||||||||||
| 144 | 2462 | my $hash = Digest::SHA::sha256($self->seed . "floppy:tube:$k"); | |||||||||||||||||||||||||||||||
| 145 | 2462 | my $range = $self->height - 100; | |||||||||||||||||||||||||||||||
| 146 | 2462 | my $h = unpack('N', substr($hash, 0, 4)) % $range; | |||||||||||||||||||||||||||||||
| 147 | 2462 | my $top = $range - $h; | |||||||||||||||||||||||||||||||
| 148 | 2462 | push @{ $self->_tubes }, { | |||||||||||||||||||||||||||||||
| 149 | x => $self->width, | ||||||||||||||||||||||||||||||||
| 150 | gap_top => $top, | ||||||||||||||||||||||||||||||||
| 151 | gap_bottom => $top + $self->gap, | ||||||||||||||||||||||||||||||||
| 152 | k => $k, | ||||||||||||||||||||||||||||||||
| 153 | }; | ||||||||||||||||||||||||||||||||
| 154 | 2462 | $self->_spawned($k + 1); | |||||||||||||||||||||||||||||||
| 155 | 2462 | return; | |||||||||||||||||||||||||||||||
| 156 | 15 | }; | |||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||
| 158 | 237 | ▶ | my $lay = sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 159 | 237 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 160 | 237 | $self->_y(int($self->height / 2) - $self->bird_radius); | |||||||||||||||||||||||||||||||
| 161 | 237 | $self->_tubes([]); | |||||||||||||||||||||||||||||||
| 162 | 237 | $self->_flap(0); | |||||||||||||||||||||||||||||||
| 163 | 237 | $self->_tilt(0); | |||||||||||||||||||||||||||||||
| 164 | 237 | $self->_spawned(0); | |||||||||||||||||||||||||||||||
| 165 | 237 | $self->_score(0); | |||||||||||||||||||||||||||||||
| 166 | 237 | $self->_ticks(0); | |||||||||||||||||||||||||||||||
| 167 | 237 | $self->_status('ready'); | |||||||||||||||||||||||||||||||
| 168 | 237 | $self->_cause(undef); | |||||||||||||||||||||||||||||||
| 169 | 237 | $self->_error(undef); | |||||||||||||||||||||||||||||||
| 170 | 237 | return $self; | |||||||||||||||||||||||||||||||
| 171 | 15 | }; | |||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||
| 173 | 4 | ▶ | my $refuse = sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 174 | 4 | my ($self, $code) = @_; | |||||||||||||||||||||||||||||||
| 175 | 4 | $self->_error(Game::Floppy::Error->of($code)); | |||||||||||||||||||||||||||||||
| 176 | 4 | return 0; | |||||||||||||||||||||||||||||||
| 177 | 15 | }; | |||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||
| 179 | 79 | ▶ | my $finish = sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 180 | 79 | my ($self, $cause, $flapped) = @_; | |||||||||||||||||||||||||||||||
| 181 | 79 | $self->_status('finished'); | |||||||||||||||||||||||||||||||
| 182 | 79 | $self->_cause($cause); | |||||||||||||||||||||||||||||||
| 183 | 79 | $self->_flap(0); | |||||||||||||||||||||||||||||||
| 184 | 79 | return { moved => 1, flapped => $flapped, passed => 0, died => $cause }; | |||||||||||||||||||||||||||||||
| 185 | 15 | }; | |||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||
| 187 | 239 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=11 SCAR=24.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 188 | 239 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||
| 190 | 239 | for my $name (qw/ width height bird_x bird_radius gravity lift tube_every tube_speed tube_width gap tube_score /) { | |||||||||||||||||||||||||||||||
| 191 | 2619 | my $value = $self->$name; | |||||||||||||||||||||||||||||||
| 192 | 2619 | ▶ | Carp::croak("Game::Floppy: $name must be a whole number, not " | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
defined $value and $value =~ /\A[0-9]+\z/u
MC/DC50%1/2
defined $value and $value =~ /\A[0-9]+\z/u
defined $value
$value =~ /\A[0-9]+\z/u
Truth table66%2/3
A and B
A= defined $valueB= $value =~ /\A[0-9]+\z/u
| |||||||||||||||||||||||||||||||||
| 193 | . (defined $value ? "'$value'" : 'undef')) | ||||||||||||||||||||||||||||||||
| 194 | unless defined $value && $value =~ /\A[0-9]+\z/; | ||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||
| 197 | 238 | ▶ | Carp::croak('Game::Floppy: a field is at least 200 high') if $self->height < 200; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 198 | 237 | ▶ | Carp::croak('Game::Floppy: a field ' . $self->width . ' wide has no room for a tube') | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 199 | if $self->width < $self->bird_x + $self->tube_width + 1; | ||||||||||||||||||||||||||||||||
| 200 | 236 | for my $name (qw/ bird_radius gravity lift tube_every tube_speed tube_width gap tube_score /) { | |||||||||||||||||||||||||||||||
| 201 | 1881 | ▶ | Carp::croak("Game::Floppy: $name is 1 or more") if $self->$name < 1; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||
| 203 | 234 | ▶ | Carp::croak('Game::Floppy: a seed is a string with something in it') | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->seed and length $self->seed
MC/DC50%1/2
defined $self->seed and length $self->seed
defined $self->seed
length $self->seed
Truth table66%2/3
A and B
A= defined $self->seedB= length $self->seed
| |||||||||||||||||||||||||||||||||
| 204 | unless defined $self->seed && length $self->seed; | ||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||
| 206 | 233 | $self->$lay; | |||||||||||||||||||||||||||||||
| 207 | 233 | return; | |||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||
| 210 | 736976 | ▶ | sub circle_hits_rectangle { | ||||||||||||||||||||||||||||||
|
Subroutine
circle_hits_rectangle: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 211 | 736976 | my ($class, $cx, $cy, $r, $x, $y, $w, $h) = @_; | |||||||||||||||||||||||||||||||
| 212 | 736976 | my ($hw, $hh) = ($w / 2, $h / 2); | |||||||||||||||||||||||||||||||
| 213 | 736976 | my $dx = abs($cx - ($x + $hw)); | |||||||||||||||||||||||||||||||
| 214 | 736976 | my $dy = abs($cy - ($y + $hh)); | |||||||||||||||||||||||||||||||
| 215 | 736976 | ▶ | return 0 if $dx > $hw + $r || $dy > $hh + $r; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$dx > $hw + $r or $dy > $hh + $r
MC/DC100%2/2
$dx > $hw + $r or $dy > $hh + $r
$dx > $hw + $r
$dy > $hh + $r
Truth table100%3/3
A or B
A= $dx > $hw + $rB= $dy > $hh + $r
| |||||||||||||||||||||||||||||||||
| 216 | 119 | ▶ | return 1 if $dx <= $hw || $dy <= $hh; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$dx <= $hw or $dy <= $hh
MC/DC100%2/2
$dx <= $hw or $dy <= $hh
$dx <= $hw
$dy <= $hh
Truth table100%3/3
A or B
A= $dx <= $hwB= $dy <= $hh
| |||||||||||||||||||||||||||||||||
| 217 | 93 | my ($ex, $ey) = ($dx - $hw, $dy - $hh); | |||||||||||||||||||||||||||||||
| 218 | 93 | ▶ | return $ex * $ex + $ey * $ey <= $r * $r ? 1 : 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||
| 221 | 24606 | ▶ | sub flap { | ||||||||||||||||||||||||||||||
|
Subroutine
flap: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 222 | 24606 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 223 | 24606 | ▶ | return $self->$refuse('not_active') if $self->_status eq 'finished'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 224 | 24605 | ▶ | return $self->$refuse('already_flapped') if $self->_flap; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 225 | 24602 | $self->_flap(1); | |||||||||||||||||||||||||||||||
| 226 | 24602 | $self->_error(undef); | |||||||||||||||||||||||||||||||
| 227 | 24602 | return 1; | |||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||
| 230 | 248807 | ▶ | sub tick { | ||||||||||||||||||||||||||||||
|
Subroutine
tick: called CC=12 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 231 | 248807 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||
| 233 | 248807 | ▶ | return { moved => 0 } if $self->_status eq 'finished'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||
| 235 | 248805 | $self->_status('active'); | |||||||||||||||||||||||||||||||
| 236 | 248805 | $self->_ticks($self->_ticks + 1); | |||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||
| 238 | 248805 | my $y = $self->_y + $self->gravity; | |||||||||||||||||||||||||||||||
| 239 | 248805 | my $flapped = 0; | |||||||||||||||||||||||||||||||
| 240 | 248805 | ▶ | if ($self->_flap) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 241 | 24597 | $y -= $self->lift; | |||||||||||||||||||||||||||||||
| 242 | 24597 | $self->_flap(0); | |||||||||||||||||||||||||||||||
| 243 | 24597 | $self->_tilt(-45); | |||||||||||||||||||||||||||||||
| 244 | 24597 | $flapped = 1; | |||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||
| 246 | 248805 | ▶ | $self->_tilt($self->_tilt + 1) if $self->_tilt < 45; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 247 | 248805 | $self->_y($y); | |||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||
| 249 | 248805 | ▶ | return $self->$finish('sky', $flapped) if $y < 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 250 | 248802 | ▶ | return $self->$finish('ground', $flapped) if $y > $self->height; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||
| 252 | 248796 | my $tubes = $self->_tubes; | |||||||||||||||||||||||||||||||
| 253 | 248796 | my ($cx, $r, $w) = ($self->bird_x, $self->bird_radius, $self->tube_width); | |||||||||||||||||||||||||||||||
| 254 | 248796 | my $passed = 0; | |||||||||||||||||||||||||||||||
| 255 | 248796 | my @kept; | |||||||||||||||||||||||||||||||
| 256 | 248796 | for my $tube (@$tubes) { | |||||||||||||||||||||||||||||||
| 257 | 368505 | $tube->{x} -= $self->tube_speed; | |||||||||||||||||||||||||||||||
| 258 | return $self->$finish('tube', $flapped) | ||||||||||||||||||||||||||||||||
| 259 | if $self->circle_hits_rectangle($cx, $y, $r, $tube->{x}, 0, $w, $tube->{gap_top}) | ||||||||||||||||||||||||||||||||
| 260 | 368505 | ▶ | || $self->circle_hits_rectangle($cx, $y, $r, $tube->{x}, $tube->{gap_bottom}, $w, $self->height); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->circle_hits_rectangle($cx, $y, $r, $tube->{"x"}, 0, $w, $tube->{"gap_top"}) or $self->circle_hits_rectangle($cx, $y, $r, $tube->{"x"}, $tube->{"gap_bottom"}, $w, $self->height)
MC/DC100%2/2
$self->circle_hits_rectangle($cx, $y, $r, $tube->{"x"}, 0, $w, $tube->{"gap_top"}) or $self->circle_hits_rectangle($cx, $y, $r, $tube->{"x"}, $tube->{"gap_bottom"}, $w, $self->height)
$self->circle_hits_rectangle($cx, $y, $r, $tube->{"x"}, 0, $w, $tube->{"gap_top"})
$self->circle_hits_rectangle($cx, $y, $r, $tube->{"x"}, $tube->{"gap_bottom"}, $w, $self->height)
Truth table100%3/3
A or B
A= $self->circle_hits_rectangle($cx, $y, $r, $tube->{"x"}, 0, $w, $tube->{"gap_top"})B= $self->circle_hits_rectangle($cx, $y, $r, $tube->{"x"}, $tube->{"gap_bottom"}, $w, $self->height)
| |||||||||||||||||||||||||||||||||
| 261 | 368461 | ▶ | if ($tube->{x} + $w < $cx) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 262 | 2168 | $self->_score($self->_score + $self->tube_score); | |||||||||||||||||||||||||||||||
| 263 | 2168 | $passed = 1; | |||||||||||||||||||||||||||||||
| 264 | 2168 | next; | |||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||
| 266 | 366293 | push @kept, $tube; | |||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||
| 268 | 248752 | ▶ | $self->_tubes(\@kept) if $passed; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||
| 270 | 248752 | ▶ | $self->$spawn if $self->_ticks % $self->tube_every == 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||
| 272 | 248752 | return { moved => 1, flapped => $flapped, passed => $passed, died => undef }; | |||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||
| 275 | 27 | ▶ | sub quit { | ||||||||||||||||||||||||||||||
|
Subroutine
quit: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 276 | 27 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 277 | 27 | ▶ | return 0 if $self->_status eq 'finished'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 278 | 26 | $self->$finish('quit', 0); | |||||||||||||||||||||||||||||||
| 279 | 26 | return 1; | |||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||
| 282 | 4 | ▶ | sub reset { | ||||||||||||||||||||||||||||||
|
Subroutine
reset: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 283 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 284 | 4 | return $self->$lay; | |||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||
| 287 | 248834 | ▶ | sub bird { | ||||||||||||||||||||||||||||||
|
Subroutine
bird: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 288 | 248834 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 289 | 248834 | return { x => $self->bird_x, y => $self->_y, radius => $self->bird_radius, tilt => $self->_tilt }; | |||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||
| 292 | 243616 | ▶ | sub tubes { | ||||||||||||||||||||||||||||||
|
Subroutine
tubes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 293 | 243616 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 294 | 243616 | return [ map { +{ %$_ } } @{ $self->_tubes } ]; | |||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||
| 297 | 55 | ▶ | sub passed { my ($self) = @_; return int($self->_score / $self->tube_score) } | ||||||||||||||||||||||||||||||
|
Subroutine
passed: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 298 | 7504 | ▶ | sub score { return $_[0]->_score } | ||||||||||||||||||||||||||||||
|
Subroutine
score: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 299 | 244284 | ▶ | sub ticks { return $_[0]->_ticks } | ||||||||||||||||||||||||||||||
|
Subroutine
ticks: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 300 | 478730 | ▶ | sub status { return $_[0]->_status } | ||||||||||||||||||||||||||||||
|
Subroutine
status: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 301 | 6 | ▶ | sub error { return $_[0]->_error } | ||||||||||||||||||||||||||||||
|
Subroutine
error: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||
| 303 | 54 | ▶ | sub result { | ||||||||||||||||||||||||||||||
|
Subroutine
result: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 304 | 54 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 305 | 54 | ▶ | return undef unless $self->_status eq 'finished'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 306 | 51 | return Game::Floppy::Result->new( | |||||||||||||||||||||||||||||||
| 307 | cause => $self->_cause, | ||||||||||||||||||||||||||||||||
| 308 | score => $self->_score, | ||||||||||||||||||||||||||||||||
| 309 | tubes => $self->passed, | ||||||||||||||||||||||||||||||||
| 310 | ticks => $self->_ticks, | ||||||||||||||||||||||||||||||||
| 311 | ); | ||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||
| 314 | 15 | 1; | |||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||
| 316 | __END__ | ||||||||||||||||||||||||||||||||