# # Uma Game for Tcl/Tk V1.2 # Copyright (C) 1996-2003 Satoshi Imai # set pi 3.14159 array set u { 0 A 1 B 2 C 3 D } array set c { 0 red 1 blue 2 yellow 3 cyan } array set x { 0 0 1 0 2 0 3 0 } set delay 200 set loop 1 set first 1 if { $tcl_platform(platform) == "windows" } { option add *Font {{Times New Roman} 11} } else { option add *Font {*-fixed-medium-r-normal--11-*} } expr srand([expr [clock seconds]+[pid]]) proc random {range} { return [expr int(rand() * 10) % $range] } proc paint { n } { global x y u i c pi if { $x($n) } { catch {.c delete $u($n)} } set x($n) [expr (116.0-($n*10.0))*sin(2.0*$pi*$i($n)/100.0)+145.0] set y($n) [expr (-65.0+($n*10.0))*cos(2.0*$pi*$i($n)/100.0)+80.0] .c create text $x($n) $y($n) -text $u($n) -fill $c($n) -tag $u($n) } proc init {} { global i rank juni u first end loop over x if { !$first } { set r [format "1st:%s 2nd:%s 3rd:%s 4th:%s" $u($rank(0)) $u($rank(1)) $u($rank(2)) $u($rank(3))] .c delete result } set juni 0 set end [expr $loop*100+1] for { set n 0 } { $n < 4 } {incr n} { set i($n) 0 set over($n) 0 paint $n } } proc result {} { global rank u set r [format "1st:%s 2nd:%s 3rd:%s 4th:%s" $u($rank(0)) $u($rank(1)) $u($rank(2)) $u($rank(3))] .c create text 148 165 -text $r -fill magenta -tag result .b configure -state normal } proc race {} { global x y u i delay over juni end rank for {set n 0} {$n < 4} {incr n} { if { !$over($n) && $i($n) > $end } { set rank($juni) $n set over($n) 1 incr juni } if { $over(0) && $over(1) && $over(2) && $over(3) } { after cancel race result return } paint $n set i($n) [expr $i($n)+[random 2]+1] } after $delay race } proc run {} { global first init if {!$first} { update after 1000 } set first 0 .b configure -state disabled race } pack [canvas .c] -fill x .c create oval 20 8 270 155 -outline green .c create oval 64 51 225 108 -fill green .c create line 149 8 149 52 label .l1 -text "Uma Game" -bg green .c create window 150 70 -window .l1 label .l2 -text "(C) 1996 s-imai" -bg green .c create window 145 86 -window .l2 button .b -text "Start" -command { run } -pady 0 -highlightthickness 0 -width 6 .c create window 310 20 -window .b scale .s -from 1 -to 400 -label Delay: -showvalue yes -variable delay \ -orient horizontal -length 70 -width 10 -highlightthickness 0 .c create window 315 62 -window .s scale .l -from 1 -to 10 -label Loop: -showvalue yes -variable loop \ -orient horizontal -length 70 -width 10 -highlightthickness 0 .c create window 315 116 -window .l init # end of file