| 1 | #* Copyright (C) 2008 Christian Guine | ||
| 2 | # * This program is free software; you can redistribute it and/or modify it | ||
| 3 | # * under the terms of the GNU General Public License as published by the Free | ||
| 4 | # * Software Fondation; either version 2 of the License, or (at your option) | ||
| 5 | # * any later version. | ||
| 6 | # * This program is distributed in the hope that it will be useful, but WITHOUT | ||
| 7 | # * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 8 | # * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
| 9 | # * more details. | ||
| 10 | # * You should have received a copy of the GNU General Public License along with | ||
| 11 | # * this program; if not, write to the Free Software Foundation, Inc., 59 | ||
| 12 | # * Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
| 13 | # */ | ||
| 14 | # affichgrille.pm Posting of a grid | ||
| 15 | # fonction = "S" ==> solution | ||
| 16 | # fonction = "R" ==> resolution | ||
| 17 | # fonction = "C" ==> grid creation | ||
| 18 | # fonction = "T" ==> seizure grid | ||
| 19 | # fonction = "V" ==> seizure solution | ||
| 20 | sub affichgrille { | ||
| 21 | use Tk; | ||
| 22 | use Games::Sudoku::menu; | ||
| 23 | use Games::Sudoku::tr1; | ||
| 24 | use Games::Sudoku::conf; | ||
| 25 | conf(); | ||
| 26 | $timedebut = time; | ||
| 27 | if ($wcanvas == 1) { # cancellation image beginning | ||
| 28 | if ($skin == 1) { | ||
| 29 | $frame1 -> destroy; | ||
| 30 | } else { | ||
| 31 | $canvas -> destroy; | ||
| 32 | $framed1 -> destroy; | ||
| 33 | $framed2 -> destroy; | ||
| 34 | } | ||
| 35 | $wcanvas = 0; | ||
| 36 | } else { | ||
| 37 | $frame1 -> destroy; | ||
| 38 | } | ||
| 39 | ($fonction) = @_; | ||
| 40 | if ($Enfant == 1) { | ||
| 41 | $nbcase = 4; | ||
| 42 | } elsif ($MaxiSudoku == 1) { | ||
| 43 | $nbcase = 16; | ||
| 44 | } elsif ($Simpliste == 1) { | ||
| 45 | $nbcase = 6; | ||
| 46 | } elsif ($Ardu == 1) { | ||
| 47 | $nbcase = 8; | ||
| 48 | } elsif ($Difficile == 1) { | ||
| 49 | $nbcase = 10; | ||
| 50 | } elsif ($Tresdifficile == 1) { | ||
| 51 | $nbcase = 12; | ||
| 52 | } else { | ||
| 53 | $nbcase = 9; # Normal | ||
| 54 | } | ||
| 55 | if ($fonction eq "S") { | ||
| 56 | menu('affichgrilleS'); | ||
| 57 | } else { | ||
| 58 | menu('affichgrille'); | ||
| 59 | } | ||
| 60 | if ($fonction eq "R") { | ||
| 61 | $frame1 = $main->Frame(-width => 850, -height => 600); | ||
| 62 | $frame1->pack(-side=>'left'); | ||
| 63 | my $frame2 = $frame1->Frame; # Posting Question | ||
| 64 | $frame2->pack; | ||
| 65 | $frame2->Label(-text=>tr1('Est ce une nouvelle grille? oui/non'), | ||
| 66 | -font => "Nimbus 15")->pack(-side=>'left'); | ||
| 67 | $listoption = $frame2->Listbox(-width => 5, -height => 2)->pack(-side=>'right'); | ||
| 68 | $listoption->insert('end',tr1('OUI'),tr1('NON')); | ||
| 69 | $listoption->activate(0); | ||
| 70 | $listoption->bind('<Double-1>',\&OK1); | ||
| 71 | $main->bind('<Key-Return>', => [\&OK1]); | ||
| 72 | my $frame3 =$frame1->Frame; | ||
| 73 | $frame3->pack; | ||
| 74 | $frame3 = $frame1->Button ( | ||
| 75 | -command=>[\&OK1], | ||
| 76 | -text=>tr1('OK') | ||
| 77 | )->pack(); | ||
| 78 | } elsif ($fonction eq "C") { | ||
| 79 | $frame1 = $main->Frame(-width => 850, -height => 600); | ||
| 80 | $frame1->pack(-side=>'left'); | ||
| 81 | my $frame2 = $frame1->Frame; # Posting Question | ||
| 82 | $frame2->pack; | ||
| 83 | $frame2->Label(-text=>tr1('Quelle difficulté?'), | ||
| 84 | -font => "Nimbus 15")->pack(-side=>'left'); | ||
| 85 | $listdifficulte = $frame2->Listbox(-width => 10, -height => 3)->pack(-side=>'right'); | ||
| 86 | $listdifficulte->insert('end',tr1('Facile'),tr1('Difficile'),tr1('Très difficile')); | ||
| 87 | $listdifficulte->activate(0); | ||
| 88 | $listdifficulte->bind('<Double-1>',\&OK2); | ||
| 89 | $main->bind('<Key-Return>', => [\&OK2]); | ||
| 90 | my $frame3 = $frame1->Frame; | ||
| 91 | $frame3->pack; | ||
| 92 | $frame3 = $frame1->Button ( | ||
| 93 | -command=>[\&OK2], | ||
| 94 | -text=>tr1('OK') | ||
| 95 | )->pack(); | ||
| 96 | } else { | ||
| 97 | menu('affichgrilleS'); | ||
| 98 | $frame1 = $main->Frame(-width => 850, -height => 600); | ||
| 99 | $frame1->pack(-side=>'left'); | ||
| 100 | init_tableau(); | ||
| 101 | affichage_grille($fonction); | ||
| 102 | } | ||
| 103 | |||
| 104 | } | ||
| 105 | 1; | ||
| 106 | |||
| 107 | sub creation_grille { # Posting grid to build a problem | ||
| 108 | if ($wcanvas == 1) { | ||
| 109 | $frame1->destroy; | ||
| 110 | $wcanvas = 0; | ||
| 111 | } else { | ||
| 112 | $frame1 -> destroy; | ||
| 113 | } | ||
| 114 | if ($Enfant == 1) { | ||
| 115 | $nbcase = 4; | ||
| 116 | } elsif ($Simpliste == 1) { | ||
| 117 | $nbcase = 6; | ||
| 118 | } elsif ($Ardu == 1) { | ||
| 119 | $nbcase = 8; | ||
| 120 | } elsif ($Difficile == 1) { | ||
| 121 | $nbcase = 10; | ||
| 122 | } elsif ($Tresdifficile == 1) { | ||
| 123 | $nbcase = 12; | ||
| 124 | } elsif ($MaxiSudoku == 1) { | ||
| 125 | $nbcase = 16; | ||
| 126 | } else { | ||
| 127 | $nbcase = 9; | ||
| 128 | } | ||
| 129 | menu('affichgrille'); | ||
| 130 | $fonction = "R"; | ||
| 131 | menu('affichgrilleS'); | ||
| 132 | $frame1 = $main->Frame; | ||
| 133 | $frame1->pack(-side=>'left'); | ||
| 134 | @precarre = ' '; | ||
| 135 | @frame = ' '; | ||
| 136 | @frame1 = ' '; | ||
| 137 | @carre = 0; | ||
| 138 | init_tableau(); | ||
| 139 | $timedebut = time; | ||
| 140 | affichage_grille($fonction); | ||
| 141 | } | ||
| 142 | |||
| 143 | sub OK1 { # seizure answer to question new grid yes/no | ||
| 144 | use Games::Sudoku::sudokuprincipal; | ||
| 145 | use Games::Sudoku::tr1; | ||
| 146 | @precarre = ' '; | ||
| 147 | @frame = ' '; | ||
| 148 | @frame1 = ' '; | ||
| 149 | @carre = 0; | ||
| 150 | $option = $listoption->get('active'); | ||
| 151 | $option =~ s/^\s+//; # delete spaces beginning and end | ||
| 152 | my $reponse = tr1('NON'); | ||
| 153 | my $reponse1 = tr1('non'); | ||
| 154 | if ($option =~ m/$reponse/ or $option =~ m/$reponse1/) { | ||
| 155 | #print "importation\n"; | ||
| 156 | importation("","txt"); | ||
| 157 | } else { | ||
| 158 | #print "init\n"; | ||
| 159 | init_tableau(); | ||
| 160 | } | ||
| 161 | #print "OK1 " . $option . "\n"; | ||
| 162 | $trait = "T"; | ||
| 163 | $fin = 0; | ||
| 164 | affichage_grille('T'); | ||
| 165 | } | ||
| 166 | |||
| 167 | sub OK2 { # seizure answer to question difficult | ||
| 168 | use Games::Sudoku::sudokuprincipal; | ||
| 169 | use Games::Sudoku::tr1; | ||
| 170 | $option = $listdifficulte->get('active'); | ||
| 171 | $option =~ s/^\s+//; # delete spaces beginning and end | ||
| 172 | my $reponse = tr1('Facile'); | ||
| 173 | my $reponse1 = tr1('Difficile'); | ||
| 174 | |||
| 175 | my $reponse2 = tr1('Très difficile'); | ||
| 176 | if ($option eq $reponse1) { | ||
| 177 | $difficulte = 1; | ||
| 178 | } elsif ($option eq $reponse2) { | ||
| 179 | $difficulte = 2; | ||
| 180 | } else { | ||
| 181 | $difficulte = 0; | ||
| 182 | } | ||
| 183 | newgrille(); | ||
| 184 | } | ||
| 185 | |||
| 186 | sub affichage_grille { # posting grid | ||
| 187 | use Games::Sudoku::saisie1; | ||
| 188 | use Games::Sudoku::sudokuprincipal; | ||
| 189 | ($trait) = @_; | ||
| 190 | #print "affichage grille trait= " . $trait . "\n"; | ||
| 191 | $frame1->destroy; | ||
| 192 | $frame1 = $main->Frame(-width => 950, -height => 600); | ||
| 193 | $frame1->pack; | ||
| 194 | $frame2 = $frame1->Frame; | ||
| 195 | $frame2->pack; | ||
| 196 | $frame7 = $frame2->Frame->pack(-side=>'right'); # posting right side | ||
| 197 | $timefin = time; | ||
| 198 | my ($hh, $mn, $s) = caltime($timefin, $timedebut); | ||
| 199 | my $frame20 = $frame7->Label(-text => tr1('Temps : ') . $hh . tr1('h') . $mn . tr1('mn') . $s . tr1('s') . "\n\n\n", | ||
| 200 | -font => "Nimbus 10" | ||
| 201 | )->pack(); | ||
| 202 | if ($trait ne "F" or $fin != 1) { | ||
| 203 | if ($fonction ne "S") { | ||
| 204 | if ($trait ne "T" and $trait ne "V") { | ||
| 205 | if ($fin == 0) { | ||
| 206 | $frame10 = $frame7->Label(-text => tr1('Tout n\'est pas réglé'), | ||
| 207 | -font => "Nimbus 15" | ||
| 208 | )->pack(); | ||
| 209 | $frame8 = $frame7->Label(-text => | ||
| 210 | tr1('Supprimer le chiffre choisi'), | ||
| 211 | -font => "Nimbus 15" | ||
| 212 | )->pack(); | ||
| 213 | $frame9 = $frame7->Button ( | ||
| 214 | -command=>\&saisie1, | ||
| 215 | -text=>tr1('OK') | ||
| 216 | )->pack(); | ||
| 217 | } else { | ||
| 218 | $frame8 = $frame7->Label(-text => | ||
| 219 | tr1('Supprimer le chiffre choisi'), | ||
| 220 | -font => "Nimbus 15" | ||
| 221 | )->pack(); | ||
| 222 | } | ||
| 223 | } else { # T seizure ou V end seizure | ||
| 224 | if ($erreur_saisie == 1 and $trait eq "T") { | ||
| 225 | $frame11 = $frame7->Label(-text => tr1('Erreur de saisie'), | ||
| 226 | -font => "Nimbus 15" | ||
| 227 | )->pack(); | ||
| 228 | } | ||
| 229 | if ($erreur_saisie == 1 and $trait eq "V") { | ||
| 230 | $frame11 = $frame7->Label(-text => tr1('Erreur'), | ||
| 231 | -font => "Nimbus 15" | ||
| 232 | )->pack(); | ||
| 233 | } | ||
| 234 | if ($fin == 0) { # all is not found | ||
| 235 | if ($trait eq "V") { | ||
| 236 | $frame11 = $frame7->Frame; | ||
| 237 | $checkaide= $frame7->Checkbutton(-text | ||
| 238 | => tr1('Aide?'), | ||
| 239 | -font => "Nimbus 15", | ||
| 240 | -variable => \$aide, | ||
| 241 | -command => \&importations | ||
| 242 | )->pack(); | ||
| 243 | if ($aide == 1) { | ||
| 244 | $checkaide->select; | ||
| 245 | } else { | ||
| 246 | $checkaide->deselect; | ||
| 247 | } | ||
| 248 | if ($erreur_aide == 1) { | ||
| 249 | #print ("bonnevaleur = " . $bonnevaleur . "\n"); | ||
| 250 | $affichbonnevaleur = convertcase($bonnevaleur); | ||
| 251 | if ($dessin eq "animaux") { | ||
| 252 | $frame12 = $frame7->Frame; | ||
| 253 | $frame121 = $frame12->Label(-text | ||
| 254 | => tr1('Faux la bonne valeur est '), | ||
| 255 | -font => "Nimbus 15" | ||
| 256 | )->pack(-side => 'left'); | ||
| 257 | my $nomdessinanimaux = | ||
| 258 | $dessinanimaux{$affichbonnevaleur}; | ||
| 259 | my $fichier = | ||
| 260 | $pref . '/photos/' . $nomdessinanimaux; | ||
| 261 | my $image = "image" . ($affichbonnevaleur); | ||
| 262 | my $im = $frame12 | ||
| 263 | ->Photo($image, -file => $fichier); | ||
| 264 | my $button = $frame12 | ||
| 265 | ->Button(-height => 45, -width => 45, | ||
| 266 | -image => $im); | ||
| 267 | $button->pack(-side => 'left'); | ||
| 268 | } elsif ($dessin eq "couleurs") { | ||
| 269 | $frame12 = $frame7->Frame; | ||
| 270 | $frame121 = $frame12->Label(-text | ||
| 271 | => tr1('Faux la bonne valeur est '), | ||
| 272 | -font => "Nimbus 15" | ||
| 273 | )->pack(-side => 'left'); | ||
| 274 | my $nomdessincouleurs = | ||
| 275 | $dessincouleurs{$affichbonnevaleur}; | ||
| 276 | my $button = $frame12 | ||
| 277 | ->Button(-height => 3, -width => 5, | ||
| 278 | -background => $nomdessincouleurs); | ||
| 279 | $button->pack(-side => 'left'); | ||
| 280 | } elsif ($dessin eq "lettres") { | ||
| 281 | $affichbonnevaleur = convertlettre($bonnevaleur); | ||
| 282 | $frame12 = $frame7->Label(-text | ||
| 283 | => tr1('Faux la bonne valeur est ') | ||
| 284 | . $affichbonnevaleur, | ||
| 285 | -font => "Nimbus 15" | ||
| 286 | )->pack(); | ||
| 287 | } else { | ||
| 288 | $frame12 = $frame7->Label(-text | ||
| 289 | => tr1('Faux la bonne valeur est ') | ||
| 290 | . $affichbonnevaleur, | ||
| 291 | -font => "Nimbus 15" | ||
| 292 | )->pack(); | ||
| 293 | } | ||
| 294 | $frame12->pack; | ||
| 295 | } | ||
| 296 | $frame10 = $frame7->Label(-text | ||
| 297 | => tr1('Tout n\'est pas trouvé'), | ||
| 298 | -font => "Nimbus 15" | ||
| 299 | )->pack(); | ||
| 300 | } | ||
| 301 | if ($dessin eq "animaux") { | ||
| 302 | $frame8 = $frame7->Label(-text => tr1('Choisir dessin'), | ||
| 303 | -font => "Nimbus 15" | ||
| 304 | )->pack(); | ||
| 305 | } elsif ($dessin eq "lettres") { | ||
| 306 | $frame8 = $frame7->Label(-text => tr1('Saisir lettres'), | ||
| 307 | -font => "Nimbus 15" | ||
| 308 | )->pack(); | ||
| 309 | } elsif ($dessin eq "couleurs") { | ||
| 310 | $frame8 = $frame7->Label(-text => tr1('Choisir couleurs'), | ||
| 311 | -font => "Nimbus 15" | ||
| 312 | )->pack(); | ||
| 313 | } else { | ||
| 314 | $frame8 = $frame7->Label(-text => tr1('Saisir chiffres'), | ||
| 315 | -font => "Nimbus 15" | ||
| 316 | )->pack(); | ||
| 317 | } | ||
| 318 | $frame9 = $frame7->Button ( | ||
| 319 | -command=>\&fin_saisie, | ||
| 320 | -text=> tr1('FIN SAISIE') | ||
| 321 | )->pack(); | ||
| 322 | } else { # all is found | ||
| 323 | $frame10 = $frame7->Label(-text => tr1('Bravo'), | ||
| 324 | -font => "Nimbus 15" | ||
| 325 | )->pack(); | ||
| 326 | |||
| 327 | } | ||
| 328 | } | ||
| 329 | } else { | ||
| 330 | } | ||
| 331 | } else { | ||
| 332 | $frame10 = $frame7->Label(-text => tr1('Tout est réglé'), | ||
| 333 | -font => "Nimbus 15" | ||
| 334 | )->pack(); | ||
| 335 | } | ||
| 336 | # Preparation grid | ||
| 337 | $i = 0; | ||
| 338 | $j = 0; | ||
| 339 | ($wimax, $wjmax, $wimax1, $wjmax1) = calminmaxred($nbcase); | ||
| 340 | if ($nbcase == 4) { | ||
| 341 | $tailleborder = 2; | ||
| 342 | } else { | ||
| 343 | $tailleborder = 4; | ||
| 344 | } | ||
| 345 | for ($wi = 0; $wi < $wimax; $wi++) { # posting areas | ||
| 346 | $frame3[$wi] = $frame2->Frame(-borderwidth=>4)->pack; | ||
| 347 | for ($wj = 0; $wj < $wjmax; $wj++) { | ||
| 348 | $frame4[$wi][$wj] = $frame3[$wi]->Frame(-borderwidth=>$tailleborder) | ||
| 349 | ->pack(-side=>'left'); | ||
| 350 | for ($wwi = 0; $wwi < $wimax1; $wwi++) { | ||
| 351 | $frame5[$wi][$wj][$wwi] = $frame4[$wi][$wj]->Frame->pack; | ||
| 352 | for ($wwj = 0; $wwj < $wjmax1; $wwj++) { | ||
| 353 | $frame6[$wi][$wj][$wwi][$wwj] = $frame5[$wi][$wj][$wwi] | ||
| 354 | ->Frame(-borderwidth=>($tailleborder/2)) | ||
| 355 | ->pack(-side=>'left'); | ||
| 356 | $i = ($wimax1 * $wi) + $wwi; | ||
| 357 | $j = ($wjmax1 * $wj) + $wwj; | ||
| 358 | affich_case($i,$j); | ||
| 359 | } | ||
| 360 | } | ||
| 361 | } | ||
| 362 | } | ||
| 363 | #print "fin affich trait= " . $trait . "\n"; | ||
| 364 | if ($trait eq "V") { | ||
| 365 | |||
| 366 | $traitexport = " "; | ||
| 367 | exportation(); | ||
| 368 | } | ||
| 369 | $main->bind('<Key-Return>', => [\&saisie2]); | ||
| 370 | #} | ||
| 371 | } | ||
| 372 | |||
| 373 | sub affich_case { # posting a square | ||
| 374 | my ($i,$j) = @_; | ||
| 375 | #print ("affich_case " . $i . " " . $j . "\n"); | ||
| 376 | if ($nbcase == 9 or $nbcase == 4 or $nbcase == 6 or $nbcase == 8 | ||
| 377 | or $nbcase == 10) { | ||
| 378 | $width = 2; | ||
| 379 | $taillefont = "30"; | ||
| 380 | } else { | ||
| 381 | $width = 30; | ||
| 382 | $taillefont = "15"; | ||
| 383 | } | ||
| 384 | my $trouve = 0; | ||
| 385 | for (my $k = 0; $k < $nbcase; $k++) { | ||
| 386 | if ($precarre[$i][$j][$k] eq "S" or $precarre[$i][$j][$k] eq "C") { | ||
| 387 | $wk = $k + 1; | ||
| 388 | $wkaffich = convertcase($wk); | ||
| 389 | $trouve++; | ||
| 390 | } | ||
| 391 | } | ||
| 392 | if ($trouve != 0) { # posting big square because number is found | ||
| 393 | |||
| 394 | #print ("i= " . $i . " j= " . $j . " " . $precarre[$i][$j][$wk - 1] . "\n"); | ||
| 395 | if ($precarre[$i][$j][$wk - 1] eq "S") { | ||
| 396 | $backgroundcouleur = "red"; | ||
| 397 | } else { | ||
| 398 | $backgroundcouleur = "blue"; | ||
| 399 | } | ||
| 400 | affich(); | ||
| 401 | } elsif ($trait eq "T" or $trait eq "V") { #posting big white square | ||
| 402 | if ($dessin eq "animaux") { | ||
| 403 | fixwidthheight(); | ||
| 404 | $entrycarre[$i][$j][0] = $frame6[$wi][$wj][$wwi][$wwj] | ||
| 405 | ->Button(-text => ' ', -height => $height, -width => $width, | ||
| 406 | -activebackground => "yellow", | ||
| 407 | -command => [\&affichdessin,$i,$j,$wi,$wj,$wwi,$wwj]) | ||
| 408 | ->pack(-side=>'left'); | ||
| 409 | }elsif ($dessin eq "couleurs") { | ||
| 410 | fixwidthheight(); | ||
| 411 | $entrycarre[$i][$j][0] = $frame6[$wi][$wj][$wwi][$wwj] | ||
| 412 | ->Button(-text => ' ', -height => $height, -width => $width, | ||
| 413 | -activebackground => "yellow", | ||
| 414 | -command => [\&affichcouleurs,$i,$j,$wi,$wj,$wwi,$wwj]) | ||
| 415 | ->pack(-side=>'left'); | ||
| 416 | } else { | ||
| 417 | $entrycarre[$i][$j][0] = $frame6[$wi][$wj][$wwi][$wwj] | ||
| 418 | ->Entry(-width=>2,-font => "Nimbus " . $taillefont,-background => "white") | ||
| 419 | ->pack; | ||
| 420 | $entrycarre[$i][$j][0]->insert(0," "); | ||
| 421 | } | ||
| 422 | } else { # posting small square because number not found | ||
| 423 | for ($k = 0; $k < $nbcase; $k++) { | ||
| 424 | $wk = $k + 1; | ||
| 425 | $wkaffich = convertcase($wk); | ||
| 426 | if ($nbcase == 4) { # Enfant | ||
| 427 | $width = 2; | ||
| 428 | $taillefont = 4; | ||
| 429 | if ($k == 0 or $k == 2) { | ||
| 430 | if ($k == 0) { | ||
| 431 | $wwk = 0; | ||
| 432 | } else { | ||
| 433 | $wwk = 1; | ||
| 434 | } | ||
| 435 | $frame7[$wi][$wj][$wwi][$wwj][$wwk] = $frame6[$wi][$wj][$wwi][$wwj] | ||
| 436 | ->Frame(-borderwidth=>1); | ||
| 437 | $frame7[$wi][$wj][$wwi][$wwj][$wwk]->pack; | ||
| 438 | } | ||
| 439 | } elsif ($nbcase == 6) { # Simpliste | ||
| 440 | $width = 2; | ||
| 441 | $taillefont = 4; | ||
| 442 | if ($k == 0 or $k == 3) { | ||
| 443 | if ($k == 0) { | ||
| 444 | $wwk = 0; | ||
| 445 | } else { | ||
| 446 | $wwk = 1; | ||
| 447 | } | ||
| 448 | $frame7[$wi][$wj][$wwi][$wwj][$wwk] = $frame6[$wi][$wj][$wwi][$wwj] | ||
| 449 | ->Frame(-borderwidth=>1); | ||
| 450 | $frame7[$wi][$wj][$wwi][$wwj][$wwk]->pack; | ||
| 451 | } | ||
| 452 | } elsif ($nbcase == 8) { # Ardu | ||
| 453 | $width = 2; | ||
| 454 | $taillefont = 4; | ||
| 455 | if ($k == 0 or $k == 4) { | ||
| 456 | if ($k == 0) { | ||
| 457 | $wwk = 0; | ||
| 458 | } else { | ||
| 459 | $wwk = 1; | ||
| 460 | } | ||
| 461 | $frame7[$wi][$wj][$wwi][$wwj][$wwk] = $frame6[$wi][$wj][$wwi][$wwj] | ||
| 462 | ->Frame(-borderwidth=>1); | ||
| 463 | $frame7[$wi][$wj][$wwi][$wwj][$wwk]->pack; | ||
| 464 | } | ||
| 465 | } elsif ($nbcase == 9) { # Normal | ||
| 466 | $width = 2; | ||
| 467 | $taillefont = 4; | ||
| 468 | if ($k == 0 or $k == 3 or $k == 6) { | ||
| 469 | if ($k == 0) { | ||
| 470 | $wwk = 0; | ||
| 471 | } elsif ($k == 3) { | ||
| 472 | $wwk = 1; | ||
| 473 | } else { | ||
| 474 | $wwk = 2; | ||
| 475 | } | ||
| 476 | $frame7[$wi][$wj][$wwi][$wwj][$wwk] = $frame6[$wi][$wj][$wwi][$wwj] | ||
| 477 | ->Frame(-borderwidth=>1); | ||
| 478 | $frame7[$wi][$wj][$wwi][$wwj][$wwk]->pack; | ||
| 479 | } | ||
| 480 | } elsif ($nbcase == 10) { # Difficile | ||
| 481 | $width = 2; | ||
| 482 | $taillefont = 4; | ||
| 483 | if ($k == 0 or $k == 5) { | ||
| 484 | if ($k == 0) { | ||
| 485 | $wwk = 0; | ||
| 486 | } else { | ||
| 487 | $wwk = 1; | ||
| 488 | } | ||
| 489 | $frame7[$wi][$wj][$wwi][$wwj][$wwk] = $frame6[$wi][$wj][$wwi][$wwj] | ||
| 490 | ->Frame(-borderwidth=>1); | ||
| 491 | $frame7[$wi][$wj][$wwi][$wwj][$wwk]->pack; | ||
| 492 | } | ||
| 493 | } elsif ($nbcase == 12) { # Tresifficile | ||
| 494 | $width = 1; | ||
| 495 | $taillefont = 1; | ||
| 496 | if ($k == 0 or $k == 4 or $k == 8) { | ||
| 497 | if ($k == 0) { | ||
| 498 | $wwk = 0; | ||
| 499 | } elsif ($k == 4) { | ||
| 500 | $wwk = 1; | ||
| 501 | } else { | ||
| 502 | $wwk = 2; | ||
| 503 | } | ||
| 504 | $frame7[$wi][$wj][$wwi][$wwj][$wwk] = $frame6[$wi][$wj][$wwi][$wwj] | ||
| 505 | ->Frame(-borderwidth=>1); | ||
| 506 | $frame7[$wi][$wj][$wwi][$wwj][$wwk]->pack; | ||
| 507 | } | ||
| 508 | } else { #nbcase = 16 Maxi | ||
| 509 | $width = 1; | ||
| 510 | $taillefont = 1; | ||
| 511 | if ($k == 0 or $k == 4 or $k == 8 or $k == 12) { | ||
| 512 | if ($k == 0) { | ||
| 513 | $wwk = 0; | ||
| 514 | } elsif ($k == 4) { | ||
| 515 | $wwk = 1; | ||
| 516 | } elsif ($k == 8) { | ||
| 517 | $wwk = 2; | ||
| 518 | } else { | ||
| 519 | $wwk = 3; | ||
| 520 | } | ||
| 521 | $frame7[$wi][$wj][$wwi][$wwj][$wwk] = $frame6[$wi][$wj][$wwi][$wwj] | ||
| 522 | ->Frame(-borderwidth=>1); | ||
| 523 | $frame7[$wi][$wj][$wwi][$wwj][$wwk]->pack; | ||
| 524 | } | ||
| 525 | } | ||
| 526 | affich1(); # posting little square | ||
| 527 | } | ||
| 528 | } | ||
| 529 | } | ||
| 530 | |||
| 531 | sub affich { | ||
| 532 | use Games::Sudoku::conf; | ||
| 533 | conf(); | ||
| 534 | if ($dessin eq "animaux") { | ||
| 535 | if ($nbcase == 10 or $nbcase == 12 or $nbcase == 16) { | ||
| 536 | $width1 = 30; | ||
| 537 | $height1 = 30; | ||
| 538 | } else { | ||
| 539 | $width1 = 45; | ||
| 540 | $height1 = 45; | ||
| 541 | } | ||
| 542 | $entrycarre[$i][$j][$k] = $frame6[$wi][$wj][$wwi][$wwj] | ||
| 543 | ->Canvas('width' => $width1,-highlightbackground => 'black', | ||
| 544 | -height => $height1); | ||
| 545 | my $nomdessinanimaux = $dessinanimaux{$wkaffich}; | ||
| 546 | my $fichier; | ||
| 547 | if ($nbcase == 10 or $nbcase == 12 or $nbcase == 16) { | ||
| 548 | $fichier = $pref . '/photos/p' . $nomdessinanimaux; | ||
| 549 | } else { | ||
| 550 | $fichier = $pref . '/photos/' . $nomdessinanimaux; | ||
| 551 | } | ||
| 552 | my $image = "image" . $wkaffich; | ||
| 553 | $frame6[$wi][$wj][$wwi][$wwj] | ||
| 554 | ->Photo($image, -file => $fichier); | ||
| 555 | $entrycarre[$i][$j][$k]->createImage(0, 0, -anchor => 'nw', | ||
| 556 | -image => $image); | ||
| 557 | $entrycarre[$i][$j][$k]->pack; | ||
| 558 | } elsif ($dessin eq "couleurs") { | ||
| 559 | if ($nbcase == 10 or $nbcase == 12 or $nbcase == 16) { | ||
| 560 | $height2 = 1; | ||
| 561 | } else { | ||
| 562 | $height2 = 2; | ||
| 563 | } | ||
| 564 | my $couleur = $dessincouleurs{$wkaffich}; | ||
| 565 | $entrycarre[$i][$j][$k] = $frame6[$wi][$wj][$wwi][$wwj] | ||
| 566 | ->Entry(-width=> 2, | ||
| 567 | -font => "Nimbus " . $taillefont, | ||
| 568 | -background=>$couleur)->pack; | ||
| 569 | } else { | ||
| 570 | if ($nbcase == 10 or $nbcase == 12 or $nbcase == 16) { | ||
| 571 | $height2 = 1; | ||
| 572 | } else { | ||
| 573 | $height2 = 2; | ||
| 574 | } | ||
| 575 | $entrycarre[$i][$j][$k] = $frame6[$wi][$wj][$wwi][$wwj] | ||
| 576 | ->Entry(-width=> 2, | ||
| 577 | -font => "Nimbus " . $taillefont, | ||
| 578 | -background=>$backgroundcouleur)->pack; | ||
| 579 | if ($dessin eq "lettres") { | ||
| 580 | my $lettre = convertlettre($wkaffich); | ||
| 581 | $entrycarre[$i][$j][$k]->insert(0," " . $lettre); | ||
| 582 | } else { | ||
| 583 | $entrycarre[$i][$j][$k]->insert(0," " . $wkaffich); | ||
| 584 | } | ||
| 585 | } | ||
| 586 | } | ||
| 587 | |||
| 588 | sub affich1 { # posting square or image | ||
| 589 | $entrycarre[$i][$j][$k] = $frame7[$wi][$wj][$wwi][$wwj][$wwk] | ||
| 590 | ->Entry(-width=>$width,-selectforeground => 'red', | ||
| 591 | -font => "Nimbus " . $taillefont) | ||
| 592 | ->pack(-side=>'left'); | ||
| 593 | if ($precarre[$i][$j][$k] eq "P") { | ||
| 594 | $entrycarre[$i][$j][$k]->insert(0,$wkaffich); | ||
| 595 | } else { | ||
| 596 | $entrycarre[$i][$j][$k]->insert(0," "); | ||
| 597 | } | ||
| 598 | } | ||
| 599 | |||
| 600 | sub affichdessin { | ||
| 601 | my ($idessin, $jdessin, $wi, $wj, $wwi, $wwj, $code) = @_; | ||
| 602 | use Games::Sudoku::conf; | ||
| 603 | conf(); | ||
| 604 | #print "affichdessin $idessin $jdessin\n"; | ||
| 605 | fixwidthheight(); | ||
| 606 | $entrycarre[$idessin][$jdessin][0]->destroy; | ||
| 607 | $entrycarre[$idessin][$jdessin][0] = $frame6[$wi][$wj][$wwi][$wwj] | ||
| 608 | ->Button(-text => ' ', -height => $height, -width => $width, | ||
| 609 | -background => "yellow") | ||
| 610 | ->pack(-side=>'left'); | ||
| 611 | $frame3 = $frame7->Frame->pack; | ||
| 612 | my $textframe3 = $frame3->Label(-text => tr1('Choisissez'), | ||
| 613 | -font => "Nimbus 20")->pack; | ||
| 614 | $frame4 = $frame7->Frame->pack; | ||
| 615 | $frame5 = $frame7->Frame->pack; | ||
| 616 | for (my $i = 0; $i < $nbcase; $i++) { # posting drawings for choice | ||
| 617 | my $chiffre = convertcase($i + 1); | ||
| 618 | my $nomdessinanimaux = $dessinanimaux{$chiffre}; | ||
| 619 | my $fichier; | ||
| 620 | my $height; | ||
| 621 | my $width; | ||
| 622 | if ($nbcase == 10 or $nbcase == 12 or $nbcase == 16) { | ||
| 623 | $fichier = $pref . '/photos/p' . $nomdessinanimaux; | ||
| 624 | $width = 35; | ||
| 625 | $height = 35; | ||
| 626 | } else { | ||
| 627 | $fichier = $pref . '/photos/' . $nomdessinanimaux; | ||
| 628 | $width = 45; | ||
| 629 | $height = 45; | ||
| 630 | } | ||
| 631 | my $image = "image" . ($i + 1); | ||
| 632 | my $button; | ||
| 633 | if ($i <= 8) { | ||
| 634 | my $im = $frame4->Photo($image, -file => $fichier); | ||
| 635 | $button = $frame4->Button(-height => $height, -width => $width, | ||
| 636 | -image => $im, | ||
| 637 | -command => [\&saisiedessin,$idessin,$jdessin,$i + 1]); | ||
| 638 | } else { | ||
| 639 | $im = $frame5->Photo($image, -file => $fichier); | ||
| 640 | $button = $frame5->Button(-height => $height, -width => $width, | ||
| 641 | -image => $im, | ||
| 642 | -command => [\&saisiedessin,$idessin,$jdessin,$i + 1]); | ||
| 643 | } | ||
| 644 | $button->pack(-side => 'left'); | ||
| 645 | } | ||
| 646 | fixwidthheight(); | ||
| 647 | my $button = $frame5->Button(-height => $height, -width => $width + 4, | ||
| 648 | -text => tr1("annulation"), | ||
| 649 | -command => [\&annuldessin, $idessin, $jdessin, $wi, $wj, $wwi, $wwj]); | ||
| 650 | $button->pack(-side => 'left'); | ||
| 651 | } | ||
| 652 | |||
| 653 | sub annuldessin { | ||
| 654 | # step backwards on choice square in the case of drawings | ||
| 655 | my ($idessin, $jdessin, $wi, $wj, $wwi, $wwj, $code) = @_; | ||
| 656 | fixwidthheight(); | ||
| 657 | $entrycarre[$idessin][$jdessin][0]->destroy; | ||
| 658 | if ($dessin eq "animaux") { | ||
| 659 | $entrycarre[$idessin][$jdessin][0] = $frame6[$wi][$wj][$wwi][$wwj] | ||
| 660 | ->Button(-text => ' ', -height => $height, -width => $width, | ||
| 661 | -background => "white", | ||
| 662 | -command => [\&affichdessin,$idessin,$jdessin,$wi,$wj,$wwi,$wwj]) | ||
| 663 | ->pack(-side=>'left'); | ||
| 664 | } elsif ($dessin eq "couleurs") { | ||
| 665 | $entrycarre[$idessin][$jdessin][0] = $frame6[$wi][$wj][$wwi][$wwj] | ||
| 666 | ->Button(-text => ' ', -height => $height, -width => $width, | ||
| 667 | -background => "white", | ||
| 668 | -command => [\&affichcouleurs,$idessin,$jdessin,$wi,$wj,$wwi,$wwj]) | ||
| 669 | ->pack(-side=>'left'); | ||
| 670 | } | ||
| 671 | $frame4->destroy; | ||
| 672 | $frame5->destroy; | ||
| 673 | $frame3->destroy; | ||
| 674 | } | ||
| 675 | |||
| 676 | sub affichcouleurs { | ||
| 677 | my ($idessin, $jdessin, $wi, $wj, $wwi, $wwj, $code) = @_; | ||
| 678 | use Games::Sudoku::conf; | ||
| 679 | conf(); | ||
| 680 | #print "affichcouleur $idessin $jdessin\n"; | ||
| 681 | fixwidthheight(); | ||
| 682 | $entrycarre[$idessin][$jdessin][0]->destroy; | ||
| 683 | $entrycarre[$idessin][$jdessin][0] = $frame6[$wi][$wj][$wwi][$wwj] | ||
| 684 | ->Button(-text => ' ', -height => $height, -width => $width, | ||
| 685 | -background => "yellow") | ||
| 686 | ->pack(-side=>'left'); | ||
| 687 | $frame3 = $frame7->Frame->pack; | ||
| 688 | my $textframe3 = $frame3->Label(-text => tr1('Choisissez'), | ||
| 689 | -font => "Nimbus 20")->pack; | ||
| 690 | $frame4 = $frame7->Frame->pack; | ||
| 691 | $frame5 = $frame7->Frame->pack; | ||
| 692 | for (my $i = 0; $i < $nbcase; $i++) { # posting drawings for choice | ||
| 693 | my $chiffre = convertcase($i + 1); | ||
| 694 | my $couleur = $dessincouleurs{$chiffre}; | ||
| 695 | my $button; | ||
| 696 | if ($i <= 8) { | ||
| 697 | $button = $frame4->Button(-height => $height, -width => $width, | ||
| 698 | -background => $couleur, | ||
| 699 | -command => [\&saisiedessin,$idessin,$jdessin,$i + 1]); | ||
| 700 | } else { | ||
| 701 | $button = $frame5->Button(-height => $height, -width => $width, | ||
| 702 | -background => $couleur, | ||
| 703 | -command => [\&saisiedessin,$idessin,$jdessin,$i + 1]); | ||
| 704 | } | ||
| 705 | $button->pack(-side => 'left'); | ||
| 706 | } | ||
| 707 | fixwidthheight(); | ||
| 708 | my $button = $frame5->Button(-height => $height, -width => $width + 4, | ||
| 709 | -text => tr1("annulation"), | ||
| 710 | -command => [\&annuldessin, $idessin, $jdessin, $wi, $wj, $wwi, $wwj]); | ||
| 711 | $button->pack(-side => 'left'); | ||
| 712 | } | ||
| 713 | |||
| 714 | sub CType { # we choose the type of traitment | ||
| 715 | my ($trait, $code) = @_; | ||
| 716 | use Games::Sudoku::conf; | ||
| 717 | conf(); | ||
| 718 | if ($skin == 1) { # "beautiful" skin | ||
| 719 | if ($trait eq 'Normal') { | ||
| 720 | $Normal = 1; | ||
| 721 | $rbutton1->destroy; | ||
| 722 | my $Label20 = $frame5->Label(-image => "imagenormal")->pack(-side => 'left'); | ||
| 723 | } else { | ||
| 724 | $Normal = 0; | ||
| 725 | $rbutton1->destroy; | ||
| 726 | } | ||
| 727 | if ($trait eq 'Simpliste') { | ||
| 728 | $Simpliste = 1; | ||
| 729 | $rbutton2->destroy; | ||
| 730 | my $Label21 = $frame7->Label(-image => "imagesimpliste")->pack(-side => 'left'); | ||
| 731 | } else { | ||
| 732 | $Simpliste = 0; | ||
| 733 | $rbutton2->destroy; | ||
| 734 | } | ||
| 735 | if ($trait eq 'Ardu') { | ||
| 736 | $Ardu = 1; | ||
| 737 | $rbutton3->destroy; | ||
| 738 | my $Label22 = $frame8->Label(-image => "imageardu")->pack(-side => 'left'); | ||
| 739 | } else { | ||
| 740 | $Ardu = 0; | ||
| 741 | $rbutton3->destroy; | ||
| 742 | } | ||
| 743 | if ($trait eq 'MaxiSudoku') { | ||
| 744 | $MaxiSudoku = 1; | ||
| 745 | $rbutton4->destroy; | ||
| 746 | my $Label23 = $frame9->Label(-image => "imagemaxisudoku")->pack(-side => 'left'); | ||
| 747 | } else { | ||
| 748 | $MaxiSudoku = 0; | ||
| 749 | $rbutton4->destroy; | ||
| 750 | } | ||
| 751 | if ($trait eq 'Enfant') { | ||
| 752 | $Enfant = 1; | ||
| 753 | $rbutton5->destroy; | ||
| 754 | my $Label24 = $frame12->Label(-image => "imageenfant")->pack(-side => 'right'); | ||
| 755 | $dessin = "animaux"; # option by default | ||
| 756 | } else { | ||
| 757 | $Enfant = 0; | ||
| 758 | $rbutton5->destroy; | ||
| 759 | } | ||
| 760 | if ($trait eq 'Difficile') { | ||
| 761 | $Difficile = 1; | ||
| 762 | $rbutton6->destroy; | ||
| 763 | my $Label25 = $frame9->Label(-image => "imagedifficile") | ||
| 764 | ->pack(-side => 'left'); | ||
| 765 | } else { | ||
| 766 | $Difficile = 0; | ||
| 767 | $rbutton6->destroy; | ||
| 768 | } | ||
| 769 | if ($trait eq 'Tresdifficile') { | ||
| 770 | $Tresdifficile = 1; | ||
| 771 | $rbutton7->destroy; | ||
| 772 | my $Label26 = $frame9->Label(-image => "imagetresdifficile") | ||
| 773 | ->pack(-side => 'left'); | ||
| 774 | } else { | ||
| 775 | $Tresdifficile = 0; | ||
| 776 | $rbutton7->destroy; | ||
| 777 | } | ||
| 778 | } else { # Normal skin | ||
| 779 | if ($Normal == 0) { | ||
| 780 | $rbutton1->destroy; | ||
| 781 | $Normal = 2; | ||
| 782 | } | ||
| 783 | if ($Simpliste == 0) { | ||
| 784 | $rbutton2->destroy; | ||
| 785 | $Simpliste = 2; | ||
| 786 | } | ||
| 787 | if ($Ardu == 0) { | ||
| 788 | $rbutton3->destroy; | ||
| 789 | $Ardu = 2; | ||
| 790 | } | ||
| 791 | if ($MaxiSudoku == 0) { | ||
| 792 | $rbutton4->destroy; | ||
| 793 | $MaxiSudoku = 2; | ||
| 794 | } | ||
| 795 | if ($Enfant == 0) { | ||
| 796 | $rbutton5->destroy; | ||
| 797 | $Enfant = 2; | ||
| 798 | } | ||
| 799 | if ($Enfant == 1) { | ||
| 800 | $dessin = "animaux"; # option by default | ||
| 801 | } | ||
| 802 | if ($Difficile == 0) { | ||
| 803 | $rbutton6->destroy; | ||
| 804 | $Difficile = 2; | ||
| 805 | } | ||
| 806 | if ($tresdifficile == 0) { | ||
| 807 | $rbutton7->destroy; | ||
| 808 | $Tresdifficile = 2; | ||
| 809 | } | ||
| 810 | } | ||
| 811 | } | ||
| 812 | |||
| 813 | |||
| 814 | sub saisiedessin { | ||
| 815 | # we chose a drawings which is transformed into number | ||
| 816 | use Games::Sudoku::saisie1; | ||
| 817 | ($idessin, $jdessin, $valdessinin, $code) = @_; | ||
| 818 | #print "saisiedessin $idessin $jdessin $valdessinin\n"; | ||
| 819 | $valdessin = convertcase($valdessinin); | ||
| 820 | #print ("$valdessin\n"); | ||
| 821 | saisie1(); # Forcage at the end of seizure for backup | ||
| 822 | } | ||
| 823 | |||
| 824 | sub convertcase { # Conversion number | ||
| 825 | my ($chiffre, $code) = @_; | ||
| 826 | #print "convertcase $chiffre $chiffreconvert\n"; | ||
| 827 | my %val = (1,'1',2,'2',3,'3',4,'4',5,'5',6,'6',7,'7',8,'8',9,'9', | ||
| 828 | 10,'A',11,'B',12,'C',13,'D',14,'E',15,'F',16,'G'); | ||
| 829 | my $chiffreconvert = $val{$chiffre}; | ||
| 830 | return $chiffreconvert; | ||
| 831 | } | ||
| 832 | |||
| 833 | sub fixwidthheight { # determination of $height and $width | ||
| 834 | if ($system eq "linux") { | ||
| 835 | if ($nbcase == 10 or $nbcase == 12 or $nbcase == 16) { | ||
| 836 | $height = 1; | ||
| 837 | $width = 1; | ||
| 838 | } else { | ||
| 839 | $height = 2; | ||
| 840 | $width = 2; | ||
| 841 | } | ||
| 842 | } else { # windows | ||
| 843 | if ($nbcase == 10 or $nbcase == 12 or $nbcase == 16) { | ||
| 844 | $height = 2; | ||
| 845 | $width = 3; | ||
| 846 | } else { | ||
| 847 | $height = 3; | ||
| 848 | $width = 7; | ||
| 849 | } | ||
| 850 | } | ||
| 851 | } | ||
| 852 | |||
| 853 | sub caltime { # compute time | ||
| 854 | my ($timefin, $timedebut, $code) = @_; | ||
| 855 | #print ("timefin " . $timefin . " timedebut " . $timedebut . "\n"); | ||
| 856 | my $dif = $timefin - $timedebut; | ||
| 857 | my $hh = int($dif / 3600); | ||
| 858 | my $dif1 = $dif - ($hh * 3600); | ||
| 859 | my $mn = int($dif1 / 60); | ||
| 860 | my $s = $dif1 - ($mn * 60); | ||
| 861 | return ($hh, $mn, $s); | ||
| 862 | } | ||
| 863 | |||
| 864 | sub convertlettre { # Conversion number in letter | ||
| 865 | my ($chiffre, $code) = @_; | ||
| 866 | my %let = ('1','A','2','B','3','C','4','D','5','E','6','F','7','G','8','H','9','I', | ||
| 867 | '10','J','11','K','12','L','13','M','14','N','15','O','16','P'); | ||
| 868 | my $lettre = $let{$chiffre}; | ||
| 869 | #print ("convertlettre " . $chiffre . " " . $lettre . "\n"); | ||
| 870 | return $lettre; | ||
| 871 | } |