#!/bin/sh # -*- Tcl -*- \ exec wish "$0" "$@" # postreh -- procvičování postřehu a zvětšování zorného pole # Copyright (C) 1996-1997 Pavel Rychlý # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. set stav zacatek set uspechu 0 set chyb 0 set druhZnaku cislice set druhMezer pravidelne set pocZnaku 5 if [catch {random seed}] { #nemame random -> udelame primitivni nahradu set random_state [expr 41592 + [pid] + [string range [exec date] 17 18]] proc random {max} { global random_state set random_state [expr ($random_state * 2837 +1) & 0xffff] return [expr $random_state % $max] } } label .generovany -textvar sviti -width 20 \ -font "*-courier-bold-r-*-240-*" -cursor tcross entry .vstup -textvar vstzn -relief sunken -width 8\ -font "-*-courier-bold-r-*-*-14-*" #-font "-misc-fixed-medium-r-normal-*-150-*-c-*" button .dal -text Dale -command dale proc dale {} { global stav vstzn genzn sviti chyb uspechu switch $stav { zacatek { generuj set vstzn "" set sviti "" set stav pripraveno after 1000 zobraz } vstup { if { "$vstzn" == [join $genzn ""] } { incr uspechu } else { incr chyb } set stav zacatek set sviti $genzn } } } proc generuj {} { global genzn druhZnaku druhMezer pocZnaku # local dz i baze mezera hodnota # set genzn [random 10000] switch $druhZnaku { cislice {set baze "0123456789"} mala_p {set baze "abcdefghijklmnopqrstuvwxyz"} velka_p {set baze "ABCDEFGHIJKLMNOPQRSTUVWXYZ"} vse {set baze "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"} } switch $druhMezer { pravidelne {set mezera {expr 1} } kompresne {set mezera {expr 0} } nepravidelne {set mezera {random 4}} } for {set i 0} {$i<$pocZnaku} {incr i} { lappend hodnota [string index $baze [ random [string length $baze]]] \ [format "%*s" [eval $mezera] ""] } regsub { *$} [join $hodnota ""] {} genzn } button .konec -text Konec -command { destroy . } proc vytvor_but {Name Var List} { foreach B $List { radiobutton $Name.[lindex $B 0] -text [lindex $B 1] \ -variable $Var -relief flat -anchor w \ -value [lindex $B 2] } } button .volby -text "Volby" -comman { if [winfo exists .v] { destroy .v return } toplevel .v wm title .v Volby button .v.ok -text OK -command {destroy .v} pack .v.ok -padx 4 -pady 4 -side bottom -fill x frame .v.dz -borderwidth 10 frame .v.dm -borderwidth 10 frame .v.pz -borderwidth 10 pack .v.dz .v.dm .v.pz -side left label .v.dz.0 -text "Druh znaku" vytvor_but .v.dz druhZnaku { {1 "Cislice" cislice } {2 "Mala pismena" mala_p } {3 "Velka pismena" velka_p } {4 "Vse" vse } } pack .v.dz.0 .v.dz.1 .v.dz.2 .v.dz.3 .v.dz.4 -side top -fill x label .v.dm.0 -text "Druh mezer" vytvor_but .v.dm druhMezer { {1 "Pravidelne" pravidelne } {2 "Komresne" kompresne} {3 "Nepravidelne" nepravidelne}} pack .v.dm.0 .v.dm.1 .v.dm.2 .v.dm.3 -side top -fill x label .v.pz.0 -text "Pocet znaku" vytvor_but .v.pz pocZnaku { {1 3 3} {2 4 4} {3 5 5} {4 6 6}} pack .v.pz.0 .v.pz.1 .v.pz.2 .v.pz.3 .v.pz.4 -side top -fill x } button .vysledky -text "Vysledky" -command { if [winfo exists .s] { destroy .s return } toplevel .s wm title .s Vysledky pack [frame .s.us] [frame .s.ch] [frame .s.but] -side top -fill x \ -padx 5 -pady 2 button .s.but.ok -text OK -command {destroy .s} button .s.but.null -text "Znovu" -command {set uspechu 0 ; set chyb 0} pack .s.but.ok .s.but.null -padx 2 -pady 2 -side left -fill x -expand yes label .s.us.l -text "Uspechu:" -anchor e label .s.us.v -textvariable uspechu -width 4 pack .s.us.l .s.us.v -side left label .s.ch.l -text "Chyb:" -anchor e label .s.ch.v -textvariable chyb -width 4 pack .s.ch.l .s.ch.v -side left } proc zobraz {} { global stav genzn sviti set sviti $genzn set stav zobrazeno after 100 zhasni } proc zhasni {} { global stav sviti set sviti "" set stav vstup } pack .generovany -side top -fill both -padx 3 -pady 3 pack .vstup -side top -fill y -padx 3 -pady 3 pack .dal .volby .vysledky .konec -side left -fill both \ -expand yes -padx 3 -pady 3 bind .vstup { dale } bind .vstup { dale } bind . {destroy .} bind . {destroy .} focus .vstup