line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Wx::App::Mastermind::Board::Editor; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1756
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
28
|
|
5
|
1
|
|
|
1
|
|
5
|
use base qw(Class::Accessor::Fast); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
87
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
43
|
use Wx::App::Mastermind::Board::PegStrip; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors( qw(selected_peg enabled) ); |
10
|
|
|
|
|
|
|
__PACKAGE__->mk_ro_accessors( qw(position board) ); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub draw { |
13
|
|
|
|
|
|
|
my( $self, $dc ) = @_; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $strip = $self->board->_create_strip; |
16
|
|
|
|
|
|
|
$strip->draw( $dc, $self->position->[0], |
17
|
|
|
|
|
|
|
$self->position->[1], $self->pegs, $self->selected_peg ); |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub on_click { |
21
|
|
|
|
|
|
|
my( $self, $event ) = @_; |
22
|
|
|
|
|
|
|
return unless $self->enabled; |
23
|
|
|
|
|
|
|
my $hit = $self->board->hit_test( $event->GetPositionXY ); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
return unless $hit; |
26
|
|
|
|
|
|
|
if( $hit->[0] eq 'editor' ) { |
27
|
|
|
|
|
|
|
$self->selected_peg( $self->pegs->[$hit->[1]] ); |
28
|
|
|
|
|
|
|
$self->board->Refresh; |
29
|
|
|
|
|
|
|
} elsif( $hit->[0] eq 'move' ) { |
30
|
|
|
|
|
|
|
return unless $self->selected_peg; |
31
|
|
|
|
|
|
|
return if $hit->[1] > $self->board->position; |
32
|
|
|
|
|
|
|
$self->board->set_peg( $hit->[1], $hit->[2], $self->selected_peg ); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub on_move { |
37
|
|
|
|
|
|
|
my( $self ) = @_; |
38
|
|
|
|
|
|
|
return unless $self->enabled; |
39
|
|
|
|
|
|
|
my $move = $self->board->moves( $self->board->position ); |
40
|
|
|
|
|
|
|
return if grep / /, @$move; |
41
|
|
|
|
|
|
|
$self->board->add_move( $move ); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub get_size { |
45
|
|
|
|
|
|
|
my( $self ) = @_; |
46
|
|
|
|
|
|
|
my $strip = $self->board->_create_strip; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
return $strip->get_size( $self->peg_count ); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub hit_test { |
52
|
|
|
|
|
|
|
my( $self, $mx, $my ) = @_; |
53
|
|
|
|
|
|
|
my $strip = $self->board->_create_strip; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
return $strip->hit_test( $self->position->[0], $self->position->[1], |
56
|
|
|
|
|
|
|
$self->peg_count, $mx, $my ); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub pegs { $_[0]->board->pegs } |
60
|
|
|
|
|
|
|
sub peg_count { scalar @{$_[0]->pegs} } |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |