[HJG] 2014-03-25 - Work in progress / GUI only. ... ====== # http://wiki.tcl.tk/39566 # 1k-p03.tcl # A small game with numbers, # like 1024 by Veewo Studio, 2048 by Gabriele Cirulli, or Threes by Asher Vollmer. package require Tk global Prg set Prg(Title) "1K-Puzzle" set Prg(Version) "v0.03" set Prg(Date) "2014-03-21" set Prg(Author) "Hans-Joachim Gurt" set Prg(Contact) [string map -nocase {: @ ! .} gurt:gmx!de] set Prg(About) "Combine equeal numbers, to reach 1024" set Prg(Msg) "Press up/down,left/right." proc Start {} { Fill_Test after 1000 { Fill_Zero } } proc Fill_Test {} { set ::Prg(Msg) "Starting..." .b11 configure -text "1" .b12 configure -text "2" .b13 configure -text "4" .b14 configure -text "8" .b21 configure -text "16" .b22 configure -text "32" .b23 configure -text "64" .b24 configure -text "128" .b31 configure -text "256" .b32 configure -text "512" .b33 configure -text "1024" .b34 configure -text "2048" .b41 configure -text "Press" .b42 configure -text "keys" .b43 configure -text "to" .b44 configure -text "play" } proc Fill_Zero {} { for {set r 1} {$r<=4} {incr r} { for {set c 1} {$c<=4} {incr c} { .b$r$c configure -text " " } } } proc X { x } { x } proc Move { dir } { set ::Prg(Msg) "Button pressed: $dir" ## TODO ... } proc InitGUI {} { global Prg wm title . "$Prg(Title) $Prg(Version)" puts "$Prg(Title) $Prg(Version)" frame .f0 -background grey ;# Outer frame pack .f0 -padx 10 -pady 10 label .lb_1 -text $Prg(Title) -width 10 -bg white -pady 8 label .lb_2 -textvariable Prg(Msg) -width 30 -bg grey -pady 8 # rows: frame .f1 -background red frame .f2 -background yellow frame .f3 -background green frame .f4 -background blue frame .fJ -background grey80 -pady 8 ;# Joystick-Buttons frame .fB -background cyan -pady 2 ;# Start/Quit-Buttons pack .lb_1 -in .f0 -pady 5 pack .f1 .f2 .f3 .f4 -in .f0 pack .lb_2 -in .f0 -pady 5 pack .fJ pack .fB option add *Button.width 4 option add *Button.height 2 for {set r 1} {$r<=4} {incr r} { for {set c 1} {$c<=4} {incr c} { button .b$r$c -text " " } } option add *Button.width 1 option add *Button.height 1 button .b1 -text "^" -command { Move 1 } button .b2 -text "v" -command { Move 2 } button .b3 -text "<" -command { Move 3 } button .b4 -text ">" -command { Move 4 } label ._ -text "+" option add *Button.width 6 option add *Button.height 1 button .bt_start -text "Start" -command { Start } button .bt_quit -text "Quit" -command { exit } pack .b11 .b12 .b13 .b14 -in .f1 -side left -padx 0 pack .b21 .b22 .b23 .b24 -in .f2 -side left -padx 0 pack .b31 .b32 .b33 .b34 -in .f3 -side left -padx 0 pack .b41 .b42 .b43 .b44 -in .f4 -side left -padx 0 pack .b1 -in .fJ -side top pack .b2 -in .fJ -side bottom pack .b3 -in .fJ -side left pack ._ -in .fJ -side left pack .b4 -in .fJ -side right pack .bt_start .bt_quit -in .fB -side left -padx 18 -pady 2 } InitGUI #. ====== <>Game