line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Games::2048::Game::Input; |
2
|
4
|
|
|
4
|
|
97
|
use 5.012; |
|
4
|
|
|
|
|
13
|
|
|
4
|
|
|
|
|
152
|
|
3
|
4
|
|
|
4
|
|
19
|
use Moo; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
23
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
extends 'Games::2048::Game'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub handle_input { |
8
|
0
|
|
|
0
|
0
|
|
my ($self, $app) = @_; |
9
|
|
|
|
|
|
|
|
10
|
0
|
|
|
|
|
|
while (defined(my $key = Games::2048::Util::read_key)) { |
11
|
0
|
0
|
0
|
|
|
|
$self->handle_input_key_vector($app, $key) |
|
|
|
0
|
|
|
|
|
12
|
|
|
|
|
|
|
or $self->handle_input_key_quit_restart($app, $key) |
13
|
|
|
|
|
|
|
or $self->handle_input_key_option($app, $key) |
14
|
|
|
|
|
|
|
or $self->handle_input_key($app, $key); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub handle_input_key_vector { |
19
|
0
|
|
|
0
|
0
|
|
my ($self, $app, $key) = @_; |
20
|
0
|
|
|
|
|
|
my $vec = Games::2048::Util::key_vector($key); |
21
|
0
|
0
|
|
|
|
|
if ($vec) { |
22
|
0
|
|
|
|
|
|
$self->move($vec); |
23
|
0
|
|
|
|
|
|
1; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
sub handle_input_key_quit_restart { |
27
|
0
|
|
|
0
|
0
|
|
my ($self, $app, $key) = @_; |
28
|
0
|
0
|
|
|
|
|
if ($key =~ /^[q]$/i) { |
|
|
0
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
$app->quit(1); |
30
|
0
|
|
|
|
|
|
1; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
elsif ($key =~ /^[r]$/i) { |
33
|
0
|
|
|
|
|
|
$app->restart(1); |
34
|
0
|
|
|
|
|
|
1; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
sub handle_input_key_option { |
38
|
0
|
|
|
0
|
0
|
|
my ($self, $app, $key) = @_; |
39
|
0
|
0
|
|
|
|
|
if ($key =~ /^[a]$/i) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
$self->no_animations(!$self->no_animations); |
41
|
0
|
|
|
|
|
|
1; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
elsif ($key =~ /^[-_]$/) { |
44
|
0
|
|
|
|
|
|
$self->zoom($self->zoom - 1); |
45
|
0
|
|
|
|
|
|
1; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
elsif ($key =~ /^[=+]$/) { |
48
|
0
|
|
|
|
|
|
$self->zoom($self->zoom + 1); |
49
|
0
|
|
|
|
|
|
1; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
elsif ($key =~ /^[c]$/i) { |
52
|
0
|
|
|
|
|
|
$self->colors($self->colors + 1); |
53
|
0
|
|
|
|
|
|
1; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
0
|
|
|
0
|
0
|
|
sub handle_input_key {} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub handle_finish { |
59
|
0
|
|
|
0
|
0
|
|
my ($self, $app) = @_; |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
while (1) { |
62
|
0
|
|
|
|
|
|
my $key = Games::2048::Util::poll_key; |
63
|
0
|
0
|
|
|
|
|
$self->handle_finish_key($app, $key) and return; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub handle_finish_key { |
68
|
0
|
|
|
0
|
0
|
|
my ($self, $app, $key) = @_; |
69
|
0
|
0
|
|
|
|
|
if ($key =~ /^[nq]$/i) { |
|
|
0
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
$app->quit(1); |
71
|
0
|
|
|
|
|
|
1; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
elsif ($key =~ /^[yr\n]$/i) { |
74
|
0
|
|
|
|
|
|
1; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |