source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/vrippack-0.31/src/vrip/lib/tk/demos/puzzle.tcl @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 2.5 KB
Line 
1# puzzle.tcl --
2#
3# This demonstration script creates a 15-puzzle game using a collection
4# of buttons.
5#
6# RCS: @(#) $Id: puzzle.tcl,v 1.2 1998/09/14 18:23:29 stanton Exp $
7
8if {![info exists widgetDemo]} {
9    error "This script should be run from the \"widget\" demo."
10}
11
12# puzzleSwitch --
13# This procedure is invoked when the user clicks on a particular button;
14# if the button is next to the empty space, it moves the button into th
15# empty space.
16
17proc puzzleSwitch {w num} {
18    global xpos ypos
19    if {(($ypos($num) >= ($ypos(space) - .01))
20            && ($ypos($num) <= ($ypos(space) + .01))
21            && ($xpos($num) >= ($xpos(space) - .26))
22            && ($xpos($num) <= ($xpos(space) + .26)))
23            || (($xpos($num) >= ($xpos(space) - .01))
24            && ($xpos($num) <= ($xpos(space) + .01))
25            && ($ypos($num) >= ($ypos(space) - .26))
26            && ($ypos($num) <= ($ypos(space) + .26)))} {
27        set tmp $xpos(space)
28        set xpos(space) $xpos($num)
29        set xpos($num) $tmp
30        set tmp $ypos(space)
31        set ypos(space) $ypos($num)
32        set ypos($num) $tmp
33        place $w.frame.$num -relx $xpos($num) -rely $ypos($num)
34    }
35}
36
37set w .puzzle
38catch {destroy $w}
39toplevel $w
40wm title $w "15-Puzzle Demonstration"
41wm iconname $w "15-Puzzle"
42positionWindow $w
43
44label $w.msg -font $font -wraplength 4i -justify left -text "A 15-puzzle appears below as a collection of buttons.  Click on any of the pieces next to the space, and that piece will slide over the space.  Continue this until the pieces are arranged in numerical order from upper-left to lower-right."
45pack $w.msg -side top
46
47frame $w.buttons
48pack $w.buttons -side bottom -fill x -pady 2m
49button $w.buttons.dismiss -text Dismiss -command "destroy $w"
50button $w.buttons.code -text "See Code" -command "showCode $w"
51pack $w.buttons.dismiss $w.buttons.code -side left -expand 1
52
53# Special trick: select a darker color for the space by creating a
54# scrollbar widget and using its trough color.
55
56scrollbar $w.s
57frame $w.frame -width 120 -height 120 -borderwidth 2 -relief sunken \
58        -bg [$w.s cget -troughcolor]
59pack $w.frame -side top -pady 1c -padx 1c
60destroy $w.s
61
62set order {3 1 6 2 5 7 15 13 4 11 8 9 14 10 12}
63for {set i 0} {$i < 15} {set i [expr $i+1]} {
64    set num [lindex $order $i]
65    set xpos($num) [expr ($i%4)*.25]
66    set ypos($num) [expr ($i/4)*.25]
67    button $w.frame.$num -relief raised -text $num -highlightthickness 0 \
68            -command "puzzleSwitch $w $num"
69    place $w.frame.$num -relx $xpos($num) -rely $ypos($num) \
70        -relwidth .25 -relheight .25
71}
72set xpos(space) .75
73set ypos(space) .75
Note: See TracBrowser for help on using the repository browser.