line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Games::Sudoku::Component::TkPlayer::View;
|
2
|
|
|
|
|
|
|
{
|
3
|
1
|
|
|
1
|
|
78016
|
use strict;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
5
|
1
|
|
|
1
|
|
5
|
use Carp;
|
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
81
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
661
|
use Tk::JPEG;
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Games::Sudoku::Component::TkPlayer::Splashscreen;
|
10
|
|
|
|
|
|
|
use Games::Sudoku::Component::TkPlayer::Selector;
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new {
|
13
|
|
|
|
|
|
|
my $class = shift;
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my %options = ref $_[0] ? %{ $_[0] } : @_;
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $this = bless {
|
18
|
|
|
|
|
|
|
mw => $options{mw},
|
19
|
|
|
|
|
|
|
sdk => $options{sdk},
|
20
|
|
|
|
|
|
|
cmd => $options{cmd},
|
21
|
|
|
|
|
|
|
ver => $options{ver},
|
22
|
|
|
|
|
|
|
wgt => {},
|
23
|
|
|
|
|
|
|
}, (ref $class || $class);
|
24
|
|
|
|
|
|
|
}
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub create {
|
27
|
|
|
|
|
|
|
my $this = shift;
|
28
|
|
|
|
|
|
|
my $mw = $this->{mw};
|
29
|
|
|
|
|
|
|
my $cmd = $this->{cmd};
|
30
|
|
|
|
|
|
|
my $ver = $this->{ver};
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
$mw->title("Sudoku Player $ver");
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
$this->create_menu;
|
35
|
|
|
|
|
|
|
$this->create_progressbar;
|
36
|
|
|
|
|
|
|
$this->create_board;
|
37
|
|
|
|
|
|
|
$this->create_sideboard;
|
38
|
|
|
|
|
|
|
$this->create_selector;
|
39
|
|
|
|
|
|
|
$mw->focus;
|
40
|
|
|
|
|
|
|
}
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub create_menu {
|
43
|
|
|
|
|
|
|
my $this = shift;
|
44
|
|
|
|
|
|
|
my $mw = $this->{mw};
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
$mw->configure(-menu => my $menu = $mw->Menu);
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
$menu->cascade(
|
49
|
|
|
|
|
|
|
-label => '~Game',
|
50
|
|
|
|
|
|
|
-menuitems => $this->create_menu_file,
|
51
|
|
|
|
|
|
|
-tearoff => 0,
|
52
|
|
|
|
|
|
|
);
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
$menu->cascade(
|
55
|
|
|
|
|
|
|
-label => '~Hint',
|
56
|
|
|
|
|
|
|
-menuitems => $this->create_menu_hint,
|
57
|
|
|
|
|
|
|
-tearoff => 0,
|
58
|
|
|
|
|
|
|
);
|
59
|
|
|
|
|
|
|
}
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub create_menu_file {
|
62
|
|
|
|
|
|
|
my $this = shift;
|
63
|
|
|
|
|
|
|
my $mw = $this->{mw};
|
64
|
|
|
|
|
|
|
my $cmd = $this->{cmd};
|
65
|
|
|
|
|
|
|
my $sdk = $this->{sdk};
|
66
|
|
|
|
|
|
|
my $wgt = $this->{wgt};
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
[
|
69
|
|
|
|
|
|
|
[
|
70
|
|
|
|
|
|
|
'command', '~New',
|
71
|
|
|
|
|
|
|
-command => [ 'new_game', $cmd, $mw, $sdk, $wgt ],
|
72
|
|
|
|
|
|
|
],
|
73
|
|
|
|
|
|
|
[
|
74
|
|
|
|
|
|
|
'command', '~Load',
|
75
|
|
|
|
|
|
|
-command => [ 'load_game', $cmd, $mw, $sdk, $wgt ],
|
76
|
|
|
|
|
|
|
],
|
77
|
|
|
|
|
|
|
[
|
78
|
|
|
|
|
|
|
'command', '~Save',
|
79
|
|
|
|
|
|
|
-command => [ 'save_game', $cmd, $mw, $sdk, $wgt ],
|
80
|
|
|
|
|
|
|
],
|
81
|
|
|
|
|
|
|
'',
|
82
|
|
|
|
|
|
|
[
|
83
|
|
|
|
|
|
|
'command', 'Loc~k',
|
84
|
|
|
|
|
|
|
-command => [ 'lock', $cmd, $mw, $sdk, $wgt ],
|
85
|
|
|
|
|
|
|
],
|
86
|
|
|
|
|
|
|
[
|
87
|
|
|
|
|
|
|
'command', '~Unlock',
|
88
|
|
|
|
|
|
|
-command => [ 'unlock', $cmd, $mw, $sdk, $wgt ],
|
89
|
|
|
|
|
|
|
],
|
90
|
|
|
|
|
|
|
'',
|
91
|
|
|
|
|
|
|
[
|
92
|
|
|
|
|
|
|
'command', '~Rewind all',
|
93
|
|
|
|
|
|
|
-command => [ 'rewind_all', $cmd, $mw, $sdk, $wgt ],
|
94
|
|
|
|
|
|
|
],
|
95
|
|
|
|
|
|
|
[
|
96
|
|
|
|
|
|
|
'command', '~Clear',
|
97
|
|
|
|
|
|
|
-command => [ 'clear', $cmd, $mw, $sdk, $wgt ],
|
98
|
|
|
|
|
|
|
],
|
99
|
|
|
|
|
|
|
'',
|
100
|
|
|
|
|
|
|
[
|
101
|
|
|
|
|
|
|
'command', '~Quit',
|
102
|
|
|
|
|
|
|
-command => [ 'quit', $cmd, $mw ],
|
103
|
|
|
|
|
|
|
],
|
104
|
|
|
|
|
|
|
];
|
105
|
|
|
|
|
|
|
}
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub create_menu_hint {
|
108
|
|
|
|
|
|
|
my $this = shift;
|
109
|
|
|
|
|
|
|
my $mw = $this->{mw};
|
110
|
|
|
|
|
|
|
my $cmd = $this->{cmd};
|
111
|
|
|
|
|
|
|
my $sdk = $this->{sdk};
|
112
|
|
|
|
|
|
|
my $wgt = $this->{wgt};
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
my ($check_tmp, $allowed_only);
|
115
|
|
|
|
|
|
|
$cmd->{check_tmp} = sub { @_ ? $check_tmp = shift : $check_tmp };
|
116
|
|
|
|
|
|
|
$cmd->{allowed_only} = sub { @_ ? $allowed_only = shift : $allowed_only };
|
117
|
|
|
|
|
|
|
[
|
118
|
|
|
|
|
|
|
[
|
119
|
|
|
|
|
|
|
'checkbutton', q{Tell me if I'm ~wrong},
|
120
|
|
|
|
|
|
|
-onvalue => 1,
|
121
|
|
|
|
|
|
|
-offvalue => 0,
|
122
|
|
|
|
|
|
|
-variable => \$check_tmp,
|
123
|
|
|
|
|
|
|
-command => [ 'find_tmpvalue', $cmd, $sdk, $wgt ],
|
124
|
|
|
|
|
|
|
],
|
125
|
|
|
|
|
|
|
[
|
126
|
|
|
|
|
|
|
'checkbutton', q{~Allowed value only},
|
127
|
|
|
|
|
|
|
-onvalue => 1,
|
128
|
|
|
|
|
|
|
-offvalue => 0,
|
129
|
|
|
|
|
|
|
-variable => \$allowed_only,
|
130
|
|
|
|
|
|
|
# -command => [ 'allowed_only', $cmd, $sdk, $wgt ],
|
131
|
|
|
|
|
|
|
],
|
132
|
|
|
|
|
|
|
'',
|
133
|
|
|
|
|
|
|
[
|
134
|
|
|
|
|
|
|
'command', q{What should I do ~next},
|
135
|
|
|
|
|
|
|
-command => [ 'find_next', $cmd, $mw, $sdk, $wgt ],
|
136
|
|
|
|
|
|
|
],
|
137
|
|
|
|
|
|
|
[
|
138
|
|
|
|
|
|
|
'command', q{~Help me a step},
|
139
|
|
|
|
|
|
|
-command => [ 'do_next', $cmd, $mw, $sdk, $wgt ],
|
140
|
|
|
|
|
|
|
],
|
141
|
|
|
|
|
|
|
[
|
142
|
|
|
|
|
|
|
'command', q{~Solve all},
|
143
|
|
|
|
|
|
|
-command => [ 'solve', $cmd, $mw, $sdk, $wgt ],
|
144
|
|
|
|
|
|
|
],
|
145
|
|
|
|
|
|
|
];
|
146
|
|
|
|
|
|
|
}
|
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub create_progressbar {
|
149
|
|
|
|
|
|
|
my $this = shift;
|
150
|
|
|
|
|
|
|
my $mw = $this->{mw};
|
151
|
|
|
|
|
|
|
my $wgt = $this->{wgt};
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
$wgt->{splash} = $mw->Splashscreen;
|
154
|
|
|
|
|
|
|
}
|
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub create_selector {
|
157
|
|
|
|
|
|
|
my $this = shift;
|
158
|
|
|
|
|
|
|
my $mw = $this->{mw};
|
159
|
|
|
|
|
|
|
my $wgt = $this->{wgt};
|
160
|
|
|
|
|
|
|
my $sdk = $this->{sdk};
|
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
$wgt->{selector} = $mw->Selector;
|
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
$wgt->{selector}->setsize($sdk->table->size);
|
165
|
|
|
|
|
|
|
}
|
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub create_board {
|
168
|
|
|
|
|
|
|
my $this = shift;
|
169
|
|
|
|
|
|
|
my $mw = $this->{mw};
|
170
|
|
|
|
|
|
|
my $cmd = $this->{cmd};
|
171
|
|
|
|
|
|
|
my $sdk = $this->{sdk};
|
172
|
|
|
|
|
|
|
my $wgt = $this->{wgt};
|
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
my $frame = $mw->Frame;
|
175
|
|
|
|
|
|
|
my $size = $sdk->table->size;
|
176
|
|
|
|
|
|
|
foreach my $row (1..$size) {
|
177
|
|
|
|
|
|
|
foreach my $col (1..$size) {
|
178
|
|
|
|
|
|
|
my $value = $sdk->table->cell($row,$col)->value;
|
179
|
|
|
|
|
|
|
my $id = ($row - 1) * $size + ($col - 1);
|
180
|
|
|
|
|
|
|
$wgt->{buttons}->[$id] = $mw->Button(
|
181
|
|
|
|
|
|
|
-text => ' ',
|
182
|
|
|
|
|
|
|
-command => [
|
183
|
|
|
|
|
|
|
'push_button', $cmd, $sdk, $wgt, $row, $col
|
184
|
|
|
|
|
|
|
],
|
185
|
|
|
|
|
|
|
)->grid(
|
186
|
|
|
|
|
|
|
-in => $frame,
|
187
|
|
|
|
|
|
|
-row => $row - 1,
|
188
|
|
|
|
|
|
|
-column => $col - 1,
|
189
|
|
|
|
|
|
|
);
|
190
|
|
|
|
|
|
|
$cmd->configure_button_color($wgt, $id, 'gray');
|
191
|
|
|
|
|
|
|
$cmd->configure_button($wgt, $id);
|
192
|
|
|
|
|
|
|
}
|
193
|
|
|
|
|
|
|
}
|
194
|
|
|
|
|
|
|
$frame->pack(-side => 'left');
|
195
|
|
|
|
|
|
|
}
|
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
sub create_sideboard {
|
198
|
|
|
|
|
|
|
my $this = shift;
|
199
|
|
|
|
|
|
|
my $mw = $this->{mw};
|
200
|
|
|
|
|
|
|
my $cmd = $this->{cmd};
|
201
|
|
|
|
|
|
|
my $sdk = $this->{sdk};
|
202
|
|
|
|
|
|
|
my $wgt = $this->{wgt};
|
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
# my $image = $mw->Photo(-file => 'resources/charsbar.jpg');
|
205
|
|
|
|
|
|
|
my $image = $mw->Photo;
|
206
|
|
|
|
|
|
|
my $frame = $mw->Frame;
|
207
|
|
|
|
|
|
|
$wgt->{image} = $frame->Label(-image => $image)->pack(-side => 'right');
|
208
|
|
|
|
|
|
|
my $message;
|
209
|
|
|
|
|
|
|
$wgt->{mbox} = $frame->Label(
|
210
|
|
|
|
|
|
|
-textvariable => \$message,
|
211
|
|
|
|
|
|
|
-font => [
|
212
|
|
|
|
|
|
|
-family => 'helvetica',
|
213
|
|
|
|
|
|
|
-size => 12,
|
214
|
|
|
|
|
|
|
-weight => 'bold',
|
215
|
|
|
|
|
|
|
],
|
216
|
|
|
|
|
|
|
-background => '#ffffff',
|
217
|
|
|
|
|
|
|
-height => 10,
|
218
|
|
|
|
|
|
|
-width => 18,
|
219
|
|
|
|
|
|
|
-justify => 'left',
|
220
|
|
|
|
|
|
|
-anchor => 'nw',
|
221
|
|
|
|
|
|
|
)->pack(
|
222
|
|
|
|
|
|
|
-side => 'left'
|
223
|
|
|
|
|
|
|
);
|
224
|
|
|
|
|
|
|
$frame->pack(-side => 'right');
|
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
$cmd->{message} = sub { $message = shift };
|
227
|
|
|
|
|
|
|
}
|
228
|
|
|
|
|
|
|
}
|
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
1;
|
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
__END__
|