line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Games::Cellulo::Game::Screen; |
2
|
|
|
|
|
|
|
$Games::Cellulo::Game::Screen::VERSION = '0.2_01'; |
3
|
1
|
|
|
1
|
|
3
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
4
|
1
|
|
|
1
|
|
2
|
use warnings FATAL => 'all'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
22
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
424
|
use Moo; |
|
1
|
|
|
|
|
9640
|
|
|
1
|
|
|
|
|
4
|
|
7
|
|
|
|
|
|
|
require Term::Screen; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has _screen => ( |
10
|
|
|
|
|
|
|
is => 'lazy', |
11
|
|
|
|
|
|
|
handles => { |
12
|
|
|
|
|
|
|
'at' => 'at', |
13
|
|
|
|
|
|
|
key_pressed => 'key_pressed', |
14
|
|
|
|
|
|
|
clrscr => 'clrscr', |
15
|
|
|
|
|
|
|
} ); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has grid => ( |
18
|
|
|
|
|
|
|
is => 'lazy', |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
0
|
|
|
sub _build_rows { shift->_screen->rows } |
22
|
0
|
|
|
0
|
|
|
sub _build_cols { shift->_screen->cols } |
23
|
|
|
|
|
|
|
has rows => ( is => 'lazy' ); |
24
|
|
|
|
|
|
|
has cols => ( is => 'lazy' ); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub reset_grid { |
28
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
29
|
0
|
|
|
|
|
|
my $grid = $self->grid; |
30
|
0
|
|
|
|
|
|
@$grid = @{ $self->_build_grid }; |
|
0
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
return $grid; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
sub _build_grid { |
34
|
0
|
|
|
0
|
|
|
my $self = shift; |
35
|
0
|
|
|
|
|
|
my $ret = [ map { [ (undef) x $self->cols ] } ( 1 .. $self->rows ) ]; |
|
0
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
return $ret; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub _build__screen { |
40
|
0
|
|
|
0
|
|
|
my $self = shift; |
41
|
0
|
|
|
|
|
|
Term::Screen->new; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub xpos { |
45
|
0
|
|
|
0
|
0
|
|
my( $self, $xx ) = @_; |
46
|
0
|
0
|
|
|
|
|
if( $xx >= $self->cols ) { |
|
|
0
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
$xx -= $self->cols; |
48
|
|
|
|
|
|
|
} elsif ( $xx < 0 ) { |
49
|
0
|
|
|
|
|
|
$xx += $self->cols; |
50
|
|
|
|
|
|
|
} |
51
|
0
|
|
|
|
|
|
return $xx; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub ypos { |
55
|
0
|
|
|
0
|
0
|
|
my( $self, $yy ) = @_; |
56
|
0
|
0
|
|
|
|
|
if( $yy >= $self->rows ) { |
|
|
0
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
$yy -= $self->rows; |
58
|
|
|
|
|
|
|
} elsif ( $yy < 0 ) { |
59
|
0
|
|
|
|
|
|
$yy += $self->rows; |
60
|
|
|
|
|
|
|
} |
61
|
0
|
|
|
|
|
|
return $yy; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1; |