| 1 | package Game::Floppy::Terminal; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use 5.014; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 7 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 7 | ▶ | use Digest::SHA (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 7 | ▶ | use Getopt::Long (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 7 | ▶ | use Object::Proto::Sugar -types; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 7 | ▶ | use Game::Floppy; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 7 | ▶ | use Game::Floppy::Bot; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 7 | ▶ | use Game::Terminal::Kit::Keys; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 7 | ▶ | use Game::Terminal::Kit::Run; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 7 | ▶ | use Game::Terminal::Kit::Screen; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 7 | ▶ | use Game::Terminal::Kit::Ticker; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 7 | our $VERSION = '0.10'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 7 | my %GLYPH = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | wide => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | pipe => "\xE2\x96\x88", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | top => "\xE2\x96\x80", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | bottom => "\xE2\x96\x84", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | bird => "\xE2\x97\x8F", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | centre => "\xE2\x97\x89", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | sky => ' ', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | h => "\xE2\x94\x80", v => "\xE2\x94\x82", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | tl => "\xE2\x95\xAD", tr => "\xE2\x95\xAE", bl => "\xE2\x95\xB0", br => "\xE2\x95\xAF", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | ascii => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | pipe => '#', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | top => '=', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | bottom => '=', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | bird => 'o', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | centre => '@', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | sky => ' ', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | h => '-', v => '|', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | tl => '+', tr => '+', bl => '+', br => '+', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 7 | my %SGR = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | pipe => '32', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | top => '32', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | bottom => '32', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | bird => '1;36', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | centre => '1;36', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | frame => '2', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | status => '1', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | paused => '1;33', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | over => '1;31', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | legend => '2', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 7 | my %FLAP = map { $_ => 1 } ' ', 'up', 'enter', 'w', 'k'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 7 | my ($MIN_ROWS, $MAX_ROWS) = (10, 25); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | has in => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | isa => Any, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 7 | ▶ | default => sub { \*STDIN } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 7 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | has out => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | isa => Any, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 7 | ▶ | default => sub { \*STDOUT } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 7 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 7 | has cols => (is => 'ro'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 7 | has rows => (is => 'ro'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | has seed => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | isa => Str, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | default => '' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 7 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | has level => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | isa => Int, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | default => 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 7 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | has watch => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | isa => Int, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | default => 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 7 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | has quiet => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | isa => Int, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | default => 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 7 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | has ascii => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | isa => Int, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | default => 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 7 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | has max_ticks => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | isa => Int, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | default => 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 7 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | has game => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | isa => Object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 7 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | has [qw/keyboard screen/] => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | is => 'rw' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 7 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 7 | has keysource => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | has pending => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | isa => ArrayRef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 42 | ▶ | default => sub { [] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 7 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | has clock => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | isa => Any, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 7 | ▶ | default => sub { \&Time::HiRes::time } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 7 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | has sleeper => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | isa => Any, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 7 | ▶ | default => sub { sub { select undef, undef, undef, $_[0] } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 7 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | has ticker => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | isa => Object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 7 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 7 | has columns => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 7 | has lines => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | has frames => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | isa => Int, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | default => 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 7 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | has refused => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | isa => Int, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | default => 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 7 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | has games => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | isa => Int, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | default => 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 7 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | has best => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | isa => Int, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | default => 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 7 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | has stopped => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | isa => Str, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | default => '' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 7 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | has refusal => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | isa => Str, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | default => '' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 7 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | has _wants_ansi => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | init_arg => 'ansi', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | private => 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 7 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | has _wants_interactive => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | init_arg => 'interactive', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | private => 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 7 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 7 | has _view_cols => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 7 | has _view_rows => (is => 'rw', private => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 6 | ▶ | my $clamp = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 6 | my ($value, $low, $high) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 6 | ▶ | return $low if $value < $low; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 4 | ▶ | return $high if $value > $high; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 3 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 7 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 11 | ▶ | my $cols_for = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 11 | my ($game, $rows) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 11 | return int($rows * $game->width / $game->height * 2 + 0.5); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 7 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 42 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=24 SCAR=32.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 42 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 42 | Game::Floppy::Bot->describe($self->level); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 40 | for my $name (qw/ cols rows columns lines max_ticks /) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 196 | my $value = $self->$name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 196 | ▶ | next unless defined $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 111 | ▶ | Carp::croak("Game::Floppy::Terminal: $name must be a whole number, not '$value'") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | unless $value =~ /\A[0-9]+\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 39 | ▶ | $self->stopped('') unless defined $self->stopped; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 39 | ▶ | $self->refusal('') unless defined $self->refusal; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 39 | ▶ | Carp::croak('Game::Floppy::Terminal: the clock is a code reference') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | unless ref $self->clock eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 38 | ▶ | Carp::croak('Game::Floppy::Terminal: the sleeper is a code reference') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | unless ref $self->sleeper eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 38 | ▶ | $self->keyboard(Game::Terminal::Kit::Keys->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | in => $self->in, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | pending => $self->pending, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | sleeper => $self->sleeper, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | ($self->keysource ? (keysource => $self->keysource) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | )) unless $self->keyboard; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 38 | ▶ | $self->screen(Game::Terminal::Kit::Screen->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | out => $self->out, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | interactive => $self->interactive, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | colour => $self->ansi, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | ascii => $self->ascii ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | )) unless $self->screen; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 38 | ▶ | unless ($self->game) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 38 | my $seed = $self->seed; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 38 | ▶ | $seed = Digest::SHA::sha256_hex(join ':', $self->clock->(), $$) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | unless CORE::length $seed; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 38 | $self->game(Game::Floppy->new(seed => $seed)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 38 | my ($w, $h) = $self->_measure; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 38 | ▶ | my $rows = defined $self->rows ? $self->rows | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | : $h ? $clamp->($h - 5, $MIN_ROWS, $MAX_ROWS) : 20; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 38 | ▶ | my $cols = defined $self->cols ? $self->cols : $cols_for->($self->game, $rows); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 38 | ▶ | if (!defined $self->cols && !defined $self->rows && $w && $cols + 2 > $w) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
not defined $self->cols || defined $self->rows and $w and $cols + 2 > $w
not defined $self->cols || defined $self->rows and $w
defined $self->cols || defined $self->rows
MC/DC100%4/4
not defined $self->cols || defined $self->rows and $w and $cols + 2 > $w
defined $self->cols
defined $self->rows
$w
$cols + 2 > $w
Truth table100%5/5
not(A || B) and C and D
A= defined $self->colsB= defined $self->rowsC= $wD= $cols + 2 > $w
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 2 | $rows = $clamp->(int(($w - 2) / ($self->game->width / $self->game->height * 2)), $MIN_ROWS, $MAX_ROWS); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 2 | $cols = $cols_for->($self->game, $rows); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 38 | ▶ | Carp::croak('Game::Floppy::Terminal: a view is at least 10 by 10') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$cols < 10 or $rows < 10
MC/DC50%1/2
$cols < 10 or $rows < 10
$cols < 10
$rows < 10
Truth table66%2/3
A or B
A= $cols < 10B= $rows < 10
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | if $cols < 10 || $rows < 10; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 36 | $self->_view_cols($cols); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 36 | $self->_view_rows($rows); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 36 | ▶ | $self->ticker(Game::Terminal::Kit::Ticker->new(clock => $self->clock)) unless $self->ticker; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 36 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 3696 | ▶ | sub view { my ($self) = @_; return ($self->_view_cols, $self->_view_rows) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
view: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 149122 | ▶ | sub ansi { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ansi: called CC=6 SCAR=18.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 149122 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 149122 | ▶ | return 0 if defined $ENV{NO_COLOR} && CORE::length $ENV{NO_COLOR}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $ENV{"NO_COLOR"} and length $ENV{"NO_COLOR"}
MC/DC50%1/2
defined $ENV{"NO_COLOR"} and length $ENV{"NO_COLOR"}
defined $ENV{"NO_COLOR"}
length $ENV{"NO_COLOR"}
Truth table66%2/3
A and B
A= defined $ENV{"NO_COLOR"}B= length $ENV{"NO_COLOR"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 149111 | ▶ | return $self->_wants_ansi ? 1 : 0 if defined $self->_wants_ansi; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 7 | ▶ | return -t $self->out ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 152854 | ▶ | sub interactive { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
interactive: called CC=4 SCAR=14.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 152854 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 152854 | ▶ | return $self->_wants_interactive ? 1 : 0 if defined $self->_wants_interactive; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 59 | ▶ | return -t $self->out ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 149084 | ▶ | sub _synced { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_synced: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 149084 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 149084 | my $screen = $self->screen; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 149084 | $screen->out($self->out); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 149084 | $screen->interactive($self->interactive); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 149084 | $screen->colour($self->ansi); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 149084 | return $screen; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 1 | ▶ | sub raw { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
raw: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 1 | return $self->keyboard->raw; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 2 | ▶ | sub keys_available { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
keys_available: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 2 | return $self->keyboard->keys_available; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 29 | ▶ | sub enter_raw { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
enter_raw: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 29 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 29 | ▶ | return $self->keyboard->enter_raw ? $self : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 31 | ▶ | sub leave_raw { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
leave_raw: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 31 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 31 | $self->screen->restore; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 31 | $self->keyboard->leave_raw; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 31 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 3755 | ▶ | sub read_key { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_key: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 3755 | my ($self, $wait) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 3755 | return $self->keyboard->read_key($wait); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 4 | ▶ | sub cannot_play { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cannot_play: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 4 | return 'A real-time game needs a terminal and Term::ReadKey to read the keys.' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | . ' Install Term::ReadKey, or run floppy --watch to watch the bot play.'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 70 | ▶ | sub _measure { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_measure: called CC=5 SCAR=19.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 70 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 70 | ▶ | return ($self->columns, $self->lines) if defined $self->columns; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 62 | ▶ | return () if $self->keysource || !$self->interactive; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->keysource or not $self->interactive
MC/DC0%0/2
$self->keysource or not $self->interactive
$self->keysource
not $self->interactive
Truth table66%2/3
A or not(B)
A= $self->keysourceB= not $self->interactive
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | my ($w, $h) = $self->_synced->measured; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | ▶ | return $w ? ($w, $h) : (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 32 | ▶ | sub too_narrow { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
too_narrow: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 32 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 32 | my ($w, $h) = $self->_measure; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 32 | ▶ | return undef unless $w; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 3 | my ($cols, $rows) = $self->view; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 3 | my ($need_w, $need_h) = ($cols + 2, $rows + 5); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 3 | ▶ | return undef if $w >= $need_w && (!$h || $h >= $need_h); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$w >= $need_w and !$h || $h >= $need_h
not $h or $h >= $need_h
MC/DC66%2/3
$w >= $need_w and !$h || $h >= $need_h
$w >= $need_w
not $h
$h >= $need_h
Truth table75%3/4
A and not(B) or C
A= $w >= $need_wB= not $hC= $h >= $need_h
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 2 | ▶ | return sprintf 'This window is %d columns by %d lines, and a view %d by %d needs %d by %d.' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$h || 0
MC/DC0%0/1
$h || 0
$h
Truth table50%1/2
A
A= $h
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | . ' Widen it, or ask for a smaller view with --cols and --rows.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | $w, ($h || 0), $cols, $rows, $need_w, $need_h; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 3688 | ▶ | sub _glyphs { return $GLYPH{ $_[0]->ascii ? 'ascii' : 'wide' } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_glyphs: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 1166100 | ▶ | sub _paint { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_paint: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 1166100 | my ($self, $text, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 1166100 | ▶ | return $text unless defined $key && defined $SGR{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $key and defined $SGR{$key}
MC/DC50%1/2
defined $key and defined $SGR{$key}
defined $key
defined $SGR{$key}
Truth table66%2/3
A and B
A= defined $keyB= defined $SGR{$key}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 145371 | return $self->_synced->paint($text, $SGR{$key}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 26 | ▶ | sub _say { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_say: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 26 | my ($self, @lines) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 26 | ▶ | $self->_synced->say(@lines) if @lines; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 26 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 3687 | ▶ | sub status_line { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
status_line: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 3687 | my ($self, $note) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 3687 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 3687 | my $line = sprintf ' Floppy score %d best %d', $game->score, $self->best; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 3687 | $line = $self->_paint($line, 'status'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 3687 | ▶ | if (defined $note && CORE::length $note) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $note and length $note
MC/DC50%1/2
defined $note and length $note
defined $note
length $note
Truth table66%2/3
A and B
A= defined $noteB= length $note
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 22 | ▶ | my $key = $note eq 'paused' ? 'paused' : $note =~ /\AGame over/ ? 'over' : 'legend'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 22 | $line .= ' ' . $self->_paint($note, $key); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 3687 | return $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 3687 | ▶ | sub legend { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
legend: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 3687 | my ($self, $mode) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 3687 | ▶ | $mode = '' unless defined $mode; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 3687 | ▶ | my $text = $self->watch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | ? ' watching level ' . $self->level . ': q quits, p pauses' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | : $mode eq 'again' ? ' space plays again; q quits' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | : ' space, up, enter, w or k flap; p pauses; q quits'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 3687 | return $self->_paint($text, 'legend'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 3688 | ▶ | sub board_lines { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
board_lines: called CC=21 SCAR=30.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 3688 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 3688 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 3688 | my $g = $self->_glyphs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 3688 | my ($cols, $rows) = $self->view; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 3688 | my ($width, $height) = ($game->width, $game->height); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 3688 | my $ppc = $width / $cols; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 3688 | my $ppr = $height / $rows; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 3688 | my @cell = map { [ ('sky') x $cols ] } 1 .. $rows; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 3688 | for my $tube (@{ $game->tubes }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 4941 | my $from = int($tube->{x} / $ppc); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 4941 | my $to = int(($tube->{x} + $game->tube_width - 1) / $ppc); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 4941 | for my $c ($from .. $to) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 18142 | ▶ | next if $c < 0 || $c >= $cols; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$c < 0 or $c >= $cols
MC/DC50%1/2
$c < 0 or $c >= $cols
$c < 0
$c >= $cols
Truth table66%2/3
A or B
A= $c < 0B= $c >= $cols
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 17007 | for my $r (0 .. $rows - 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 180260 | my ($y0, $y1) = ($r * $ppr, ($r + 1) * $ppr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 180260 | ▶ | if ($y1 <= $tube->{gap_top}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 60449 | $cell[$r][$c] = 'pipe'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | ▶ | elsif ($y0 < $tube->{gap_top} && $tube->{gap_top} - $y0 >= $ppr / 2) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$y0 < $tube->{"gap_top"} and $tube->{"gap_top"} - $y0 >= $ppr / 2
MC/DC100%2/2
$y0 < $tube->{"gap_top"} and $tube->{"gap_top"} - $y0 >= $ppr / 2
$y0 < $tube->{"gap_top"}
$tube->{"gap_top"} - $y0 >= $ppr / 2
Truth table100%3/3
A and B
A= $y0 < $tube->{"gap_top"}B= $tube->{"gap_top"} - $y0 >= $ppr / 2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 6972 | $cell[$r][$c] = 'top'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | elsif ($y0 >= $tube->{gap_bottom}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 43577 | $cell[$r][$c] = 'pipe'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | ▶ | elsif ($y1 > $tube->{gap_bottom} && $y1 - $tube->{gap_bottom} >= $ppr / 2) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$y1 > $tube->{"gap_bottom"} and $y1 - $tube->{"gap_bottom"} >= $ppr / 2
MC/DC100%2/2
$y1 > $tube->{"gap_bottom"} and $y1 - $tube->{"gap_bottom"} >= $ppr / 2
$y1 > $tube->{"gap_bottom"}
$y1 - $tube->{"gap_bottom"} >= $ppr / 2
Truth table100%3/3
A and B
A= $y1 > $tube->{"gap_bottom"}B= $y1 - $tube->{"gap_bottom"} >= $ppr / 2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 6359 | $cell[$r][$c] = 'bottom'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 3688 | my $bird = $game->bird; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 3688 | my $r2 = $bird->{radius} ** 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 3688 | for my $r (0 .. $rows - 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 39300 | for my $c (0 .. $cols - 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 1147640 | my $dx = ($c + 0.5) * $ppc - $bird->{x}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 1147640 | my $dy = ($r + 0.5) * $ppr - $bird->{y}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 1147640 | ▶ | $cell[$r][$c] = 'bird' if $dx * $dx + $dy * $dy <= $r2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 3688 | my ($bc, $br) = (int($bird->{x} / $ppc), int($bird->{y} / $ppr)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 3688 | ▶ | $cell[$br][$bc] = 'centre' if $br >= 0 && $br < $rows && $bc >= 0 && $bc < $cols; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%6/9
$br >= 0 and $br < $rows and $bc >= 0 and $bc < $cols
$br >= 0 and $br < $rows and $bc >= 0
$br >= 0 and $br < $rows
MC/DC25%1/4
$br >= 0 and $br < $rows and $bc >= 0 and $bc < $cols
$br >= 0
$br < $rows
$bc >= 0
$bc < $cols
Truth table40%2/5
A and B and C and D
A= $br >= 0B= $br < $rowsC= $bc >= 0D= $bc < $cols
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 3688 | my $v = $self->_paint($g->{v}, 'frame'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 3688 | my @lines = ($self->_paint($g->{tl} . ($g->{h} x $cols) . $g->{tr}, 'frame')); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 3688 | for my $r (0 .. $rows - 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 39300 | ▶ | push @lines, $v . join('', map { my $k = $cell[$r][$_]; $self->_paint($g->{$k}, $k eq 'sky' ? undef : $k) } 0 .. $cols - 1) . $v; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 3688 | push @lines, $self->_paint($g->{bl} . ($g->{h} x $cols) . $g->{br}, 'frame'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 3688 | return @lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 3687 | ▶ | sub frame_lines { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
frame_lines: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 3687 | my ($self, $note, $mode) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 3687 | return ($self->status_line($note), $self->board_lines, $self->legend($mode)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 3725 | ▶ | sub _frame { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_frame: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 3725 | my ($self, $note, $mode) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 3725 | ▶ | return if $self->quiet; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 3687 | $self->frames($self->frames + 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 3687 | my @lines = $self->frame_lines($note, $mode); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 3687 | my $screen = $self->_synced->flush_on; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 3687 | $screen->show(\@lines); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 3687 | ▶ | $screen->say('') unless $self->interactive; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 3687 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 26 | ▶ | sub _intro { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_intro: called CC=3 SCAR=15.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 26 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 26 | ▶ | return unless $self->interactive && !$self->quiet; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->interactive and not $self->quiet
MC/DC0%0/2
$self->interactive and not $self->quiet
$self->interactive
not $self->quiet
Truth table33%1/3
A and not(B)
A= $self->interactiveB= not $self->quiet
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | $self->_synced->flush_on->clear->hide_cursor; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 3511 | ▶ | sub _bot_turn { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_bot_turn: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 3511 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 3511 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 3511 | ▶ | $game->flap if Game::Floppy::Bot->choose($game, level => $self->level); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 3511 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 39 | ▶ | sub _on_key { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_on_key: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 39 | my ($self, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 39 | ▶ | return 0 if !defined $key || $key eq 'q' || $key eq 'eof' || $key eq 'interrupt'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
not defined $key or $key eq "q" or $key eq "eof" or $key eq "interrupt"
not defined $key or $key eq "q" or $key eq "eof"
not defined $key or $key eq "q"
MC/DC50%2/4
not defined $key or $key eq "q" or $key eq "eof" or $key eq "interrupt"
not defined $key
$key eq "q"
$key eq "eof"
$key eq "interrupt"
Truth table60%3/5
not(A) or B or C or D
A= not defined $keyB= $key eq "q"C= $key eq "eof"D= $key eq "interrupt"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 23 | ▶ | if ($FLAP{$key}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 17 | ▶ | return 1 if $self->watch; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 15 | ▶ | $self->refused($self->refused + 1) unless $self->game->flap; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 15 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 6 | ▶ | return $self->_pause if $key eq 'p'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 3 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 3 | ▶ | sub _pause { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_pause: called CC=7 SCAR=19.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 3 | $self->_frame('paused'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 3 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 3 | my $key = $self->read_key(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 3 | ▶ | return 0 if !defined $key || $key eq 'q' || $key eq 'eof' || $key eq 'interrupt'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%6/9
not defined $key or $key eq "q" or $key eq "eof" or $key eq "interrupt"
not defined $key or $key eq "q" or $key eq "eof"
not defined $key or $key eq "q"
MC/DC25%1/4
not defined $key or $key eq "q" or $key eq "eof" or $key eq "interrupt"
not defined $key
$key eq "q"
$key eq "eof"
$key eq "interrupt"
Truth table40%2/5
not(A) or B or C or D
A= not defined $keyB= $key eq "q"C= $key eq "eof"D= $key eq "interrupt"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 2 | ▶ | last if $key eq 'p'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 1 | ▶ | if ($FLAP{$key}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 1 | $self->_on_key($key); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 1 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 2 | $self->ticker->start(1 / 20); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 7 | my $PERIOD = 1 / 20; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 27 | ▶ | my $one_game = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=15 SCAR=27.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 27 | my ($self, $queued) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 27 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 27 | my $ticker = $self->ticker; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 27 | $self->games($self->games + 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 27 | ▶ | $self->_frame($self->watch || $queued ? undef : 'space to start'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->watch or $queued
MC/DC100%2/2
$self->watch or $queued
$self->watch
$queued
Truth table100%3/3
A or B
A= $self->watchB= $queued
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 27 | ▶ | unless ($self->watch || $queued) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->watch or $queued
MC/DC100%2/2
$self->watch or $queued
$self->watch
$queued
Truth table100%3/3
A or B
A= $self->watchB= $queued
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 16 | my $key = $self->read_key(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 16 | ▶ | return 'quit' unless $self->_on_key($key); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 26 | $ticker->start($PERIOD); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 26 | ▶ | while ($game->status ne 'finished') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 3723 | ▶ | return 'capped' if $self->max_ticks && $ticker->ticks >= $self->max_ticks; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->max_ticks and $ticker->ticks >= $self->max_ticks
MC/DC100%2/2
$self->max_ticks and $ticker->ticks >= $self->max_ticks
$self->max_ticks
$ticker->ticks >= $self->max_ticks
Truth table100%3/3
A and B
A= $self->max_ticksB= $ticker->ticks >= $self->max_ticks
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 3717 | ▶ | unless ($ticker->due) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 3717 | my $key = $self->read_key($ticker->remaining); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 3717 | ▶ | if (defined $key) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 22 | ▶ | return 'quit' unless $self->_on_key($key); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 6 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 3695 | ▶ | $self->_bot_turn if $self->watch; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 3695 | my $step = $game->tick; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 3695 | $ticker->tick($PERIOD); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 3695 | ▶ | $self->best($game->score) if $game->score > $self->best; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 3695 | ▶ | $self->_frame($step->{died} ? ($game->result->stringify, 'again') : ()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 4 | return 'died'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 7 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 26 | ▶ | my $finish = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 26 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 26 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 26 | ▶ | $game->quit unless $game->status eq 'finished'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 26 | $self->leave_raw; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 26 | my $result = $game->result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 26 | $self->_say($result->stringify); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 26 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 7 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 30 | ▶ | sub start { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start: called CC=12 SCAR=24.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 30 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 30 | my $game = $self->game; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 30 | ▶ | if (my $why = $self->too_narrow) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 1 | $self->refusal($why); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 1 | $self->stopped('narrow'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 1 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 29 | ▶ | if ($self->watch) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 10 | $self->enter_raw; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | elsif (!$self->enter_raw) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 3 | $self->refusal($self->cannot_play); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 3 | $self->stopped('keys'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 3 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 26 | $self->_intro; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 26 | my $queued = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 26 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 27 | my $how = $self->$one_game($queued); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 27 | ▶ | if ($how ne 'died') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 23 | $self->stopped($how); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 23 | return $self->$finish; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 4 | ▶ | return $self->$finish if $self->watch || $self->max_ticks; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->watch or $self->max_ticks
MC/DC50%1/2
$self->watch or $self->max_ticks
$self->watch
$self->max_ticks
Truth table66%2/3
A or B
A= $self->watchB= $self->max_ticks
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 2 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 2 | my $key = $self->read_key(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 2 | ▶ | if (!defined $key || $key eq 'q' || $key eq 'eof' || $key eq 'interrupt') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%6/9
not defined $key or $key eq "q" or $key eq "eof" or $key eq "interrupt"
not defined $key or $key eq "q" or $key eq "eof"
not defined $key or $key eq "q"
MC/DC25%1/4
not defined $key or $key eq "q" or $key eq "eof" or $key eq "interrupt"
not defined $key
$key eq "q"
$key eq "eof"
$key eq "interrupt"
Truth table40%2/5
not(A) or B or C or D
A= not defined $keyB= $key eq "q"C= $key eq "eof"D= $key eq "interrupt"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 1 | $self->stopped('quit'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 1 | return $self->$finish; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 1 | ▶ | last if $FLAP{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 1 | $game->reset; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 1 | $game->flap; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 1 | $queued = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 11 | ▶ | sub usage { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
usage: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 11 | return <<'USAGE'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | usage: floppy [options] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | --seed TEXT the game to play: the same seed and the same flaps are the same game | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | --watch watch the bot play | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | --level N the bot's level for --watch, 1 to 3 (default 3) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | --ticks N stop after N ticks (0, the default, plays to the end) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | --rows N, --cols N the view in cells; the default fits the window, at most 25 rows | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | --quiet no frames, only how it ended | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | --ascii plain characters instead of block glyphs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | --colour, --no-colour force colour on or off; NO_COLOR in the environment wins | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | --raylib open a window instead of playing in the terminal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | (needs Raylib::FFI and perl 5.38 or later) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | --version, --help | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | keys: space, up, enter, w or k flap; p pauses; q quits; after a death, space plays again. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | exit status: 0 the game ended or you quit; 2 a bad option, or a game that could not start. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | USAGE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 2 | ▶ | my $sentence = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 2 | my ($why) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 2 | $why =~ s/ at \S+ line \d+\.?\s*\z//s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 2 | $why =~ s/\A(?:Game::Floppy(?:::\w+)*|floppy): //; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 2 | $why =~ s/\s+\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 2 | ▶ | $why .= '.' unless $why =~ /[.!?]\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 2 | return $why; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 7 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 2 | ▶ | sub options { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
options: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | return [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 2 | { name => 'level', type => 'int', min => 1, max => 3, help => "the bot's level, for watch" }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | { name => 'watch', type => 'flag', help => 'watch the bot fly' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | { name => 'rows', type => 'int', min => 10, max => 25, help => 'the view in cells; the default fits the window' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | { name => 'seed', type => 'str', help => 'the same seed and the same flaps are the same game' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 19 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=23 SCAR=34.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 19 | my ($class, @argv) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 19 | my %opt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 19 | my $ok = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 19 | ▶ | local $SIG{__WARN__} = sub { my $w = $_[0]; $w =~ s/\s+\z//; print STDERR "floppy: $w\n" }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 19 | Getopt::Long::GetOptionsFromArray(\@argv, \%opt, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 'seed=s', 'level|l=i', 'watch|w', 'ticks=i', 'rows=i', 'cols=i', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 'quiet|q', 'ascii|a', 'colour|color!', 'raylib', 'version|v', 'help|h'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 19 | ▶ | if (!$ok) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 2 | print STDERR usage(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 2 | return 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 17 | ▶ | if ($opt{help}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 8 | print usage(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 8 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 9 | ▶ | if ($opt{version}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 1 | print "floppy $VERSION\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 8 | ▶ | if (@argv) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 1 | print STDERR "floppy: I do not know '$argv[0]'.\n", usage(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 1 | return 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 7 | my %with; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 7 | ▶ | $with{seed} = $opt{seed} if defined $opt{seed}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 7 | ▶ | $with{level} = $opt{level} if defined $opt{level}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 7 | ▶ | $with{max_ticks} = $opt{ticks} if defined $opt{ticks}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 7 | ▶ | $with{rows} = $opt{rows} if defined $opt{rows}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 7 | ▶ | $with{cols} = $opt{cols} if defined $opt{cols}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 7 | ▶ | $with{watch} = 1 if $opt{watch}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 7 | ▶ | $with{quiet} = 1 if $opt{quiet}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | 7 | ▶ | $with{ascii} = 1 if $opt{ascii}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 7 | ▶ | $with{ansi} = $opt{colour} ? 1 : 0 if defined $opt{colour}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | 7 | ▶ | if ($opt{raylib}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 0 | ▶ | unless (eval { require Game::Floppy::Raylib; 1 }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 0 | print STDERR "floppy: the window is not part of this build; play in the terminal.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 0 | return 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | 0 | ▶ | unless (Game::Floppy::Raylib->available) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 0 | print STDERR 'floppy: ' . Game::Floppy::Raylib->why_not . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 0 | return 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | 0 | delete @with{qw/ quiet ascii ansi rows cols /}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 0 | my $window = eval { Game::Floppy::Raylib->new(%with) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 0 | ▶ | unless ($window) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | 0 | print STDERR 'floppy: ' . $sentence->($@) . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 0 | return 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 0 | ▶ | return $window->start ? 0 : 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 7 | my $terminal = eval { $class->new(%with) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 7 | ▶ | unless ($terminal) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | 2 | print STDERR 'floppy: ' . $sentence->($@) . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 2 | return 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | 5 | ▶ | my $result = Game::Terminal::Kit::Run::guard(sub { $terminal->start }, $terminal); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | 5 | ▶ | return 0 if $result; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 2 | ▶ | print STDERR 'floppy: ' . $terminal->refusal . "\n" if CORE::length $terminal->refusal; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 2 | return 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 7 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||