line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Wx::App::Mastermind::Player; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1854
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
5
|
1
|
|
|
1
|
|
5
|
use base qw(Class::Accessor::Fast Class::Publisher); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1043
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
8416
|
use Games::Mastermind; |
|
1
|
|
|
|
|
767
|
|
|
1
|
|
|
|
|
512
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors( qw(board won) ); |
10
|
|
|
|
|
|
|
__PACKAGE__->mk_ro_accessors( qw(listener pegs holes tries) ); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
0
|
|
|
0
|
1
|
|
my( $class, @args ) = @_; |
14
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new; |
15
|
|
|
|
|
|
|
|
16
|
0
|
|
|
|
|
|
$self->init( @args ); |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
|
return $self; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub init { |
22
|
0
|
|
|
0
|
0
|
|
my( $self, %args ) = @_; |
23
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
my $game = Games::Mastermind->new( %args ); |
25
|
0
|
|
|
|
|
|
$self->{listener} = $self->create_listener( $game ); |
26
|
0
|
|
|
|
|
|
$self->{pegs} = $game->pegs; |
27
|
0
|
|
|
|
|
|
$self->{holes} = $game->holes; |
28
|
0
|
|
|
|
|
|
$self->{tries} = $args{tries}; |
29
|
0
|
|
|
|
|
|
$self->add_subscriber( 'move', $self->listener, 'on_move' ); |
30
|
0
|
|
|
|
|
|
$self->add_subscriber( 'answer', $self->listener, 'on_answer' ); |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
return $self; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub add_move { |
36
|
0
|
|
|
0
|
0
|
|
my( $self, $move ) = @_; |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
$self->board->add_move( $move ); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub add_answer { |
42
|
0
|
|
|
0
|
0
|
|
my( $self, $answer ) = @_; |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
$self->won( $answer->[0] == $self->holes ); |
45
|
0
|
|
|
|
|
|
$self->board->add_answer( $answer ); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub turn_finished { |
49
|
0
|
|
|
0
|
0
|
|
my( $self ) = @_; |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
$self->board->turn_finished; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub stop { |
55
|
0
|
|
|
0
|
0
|
|
my( $self ) = @_; |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
$self->board->stop; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub start { |
61
|
0
|
|
|
0
|
0
|
|
my( $self ) = @_; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
$self->board->start; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
0
|
0
|
|
sub terminate {} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub reset { |
69
|
0
|
|
|
0
|
0
|
|
my( $self ) = @_; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
$self->board->reset; |
72
|
0
|
|
|
|
|
|
$self->listener->reset; |
73
|
0
|
|
|
|
|
|
$self->won( 0 ); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |