| 1 | package Games::Cellulo::Game::Screen; | ||||||||||||||
| 2 | 3 | $Games::Cellulo::Game::Screen::VERSION = '0.2_01'; | |||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 3 | ▶ | use warnings FATAL => 'all'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | |||||||||||||||
| 6 | 3 | ▶ | use Moo; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 3 | require Term::Screen; | |||||||||||||
| 8 | |||||||||||||||
| 9 | 3 | has _screen => ( | |||||||||||||
| 10 | is => 'lazy', | ||||||||||||||
| 11 | handles => { | ||||||||||||||
| 12 | 'at' => 'at', | ||||||||||||||
| 13 | key_pressed => 'key_pressed', | ||||||||||||||
| 14 | clrscr => 'clrscr', | ||||||||||||||
| 15 | } ); | ||||||||||||||
| 16 | |||||||||||||||
| 17 | 3 | has grid => ( | |||||||||||||
| 18 | is => 'lazy', | ||||||||||||||
| 19 | ); | ||||||||||||||
| 20 | |||||||||||||||
| 21 | 0 | ▶ | sub _build_rows { shift->_screen->rows } | ||||||||||||
|
Subroutine
_build_rows: not called CC=1 SCAR=6.9
| |||||||||||||||
| 22 | 0 | ▶ | sub _build_cols { shift->_screen->cols } | ||||||||||||
|
Subroutine
_build_cols: not called CC=1 SCAR=6.9
| |||||||||||||||
| 23 | 3 | has rows => ( is => 'lazy' ); | |||||||||||||
| 24 | 3 | has cols => ( is => 'lazy' ); | |||||||||||||
| 25 | |||||||||||||||
| 26 | |||||||||||||||
| 27 | sub reset_grid { | ||||||||||||||
| 28 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
reset_grid: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 29 | 0 | my $grid = $self->grid; | |||||||||||||
| 30 | 0 | @$grid = @{ $self->_build_grid }; | |||||||||||||
| 31 | 0 | return $grid; | |||||||||||||
| 32 | } | ||||||||||||||
| 33 | sub _build_grid { | ||||||||||||||
| 34 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
_build_grid: not called CC=1 SCAR=6.9
| |||||||||||||||
| 35 | 0 | my $ret = [ map { [ (undef) x $self->cols ] } ( 1 .. $self->rows ) ]; | |||||||||||||
| 36 | 0 | return $ret; | |||||||||||||
| 37 | } | ||||||||||||||
| 38 | |||||||||||||||
| 39 | sub _build__screen { | ||||||||||||||
| 40 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
_build__screen: not called CC=1 SCAR=6.9
| |||||||||||||||
| 41 | 0 | Term::Screen->new; | |||||||||||||
| 42 | } | ||||||||||||||
| 43 | |||||||||||||||
| 44 | sub xpos { | ||||||||||||||
| 45 | 0 | ▶ | my( $self, $xx ) = @_; | ||||||||||||
|
Subroutine
xpos: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||
| 46 | 0 | ▶ | if( $xx >= $self->cols ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 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 | ▶ | my( $self, $yy ) = @_; | ||||||||||||
|
Subroutine
ypos: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||
| 56 | 0 | ▶ | if( $yy >= $self->rows ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 57 | 0 | $yy -= $self->rows; | |||||||||||||
| 58 | } elsif ( $yy < 0 ) { | ||||||||||||||
| 59 | 0 | $yy += $self->rows; | |||||||||||||
| 60 | } | ||||||||||||||
| 61 | 0 | return $yy; | |||||||||||||
| 62 | } | ||||||||||||||
| 63 | |||||||||||||||
| 64 | 3 | 1; | |||||||||||||