# This demonstration script creates a 15-puzzle game using a collection
# of buttons.
#
# widet demo 'puzzle' (called by 'widget')
#
# toplevel widget
ifdefined?($puzzle_demo)&&$puzzle_demo
$puzzle_demo.destroy
$puzzle_demo=nil
end
# demo toplevel widget
$puzzle_demo=TkToplevel.new{|w|
title("15-Puzzle Demonstration")
iconname("15-Puzzle")
positionWindow(w)
}
# label
msg=TkLabel.new($puzzle_demo){
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."
}
msg.pack('side'=>'top')
# frame
TkFrame.new($puzzle_demo){|frame|
TkButton.new(frame){
text'Dismiss'
commandproc{
tmppath=$puzzle_demo
$puzzle_demo=nil
tmppath.destroy
}
}.pack('side'=>'left','expand'=>'yes')
TkButton.new(frame){
text'Show Code'
commandproc{showCode'puzzle'}
}.pack('side'=>'left','expand'=>'yes')
}.pack('side'=>'bottom','fill'=>'x','pady'=>'2m')
# frame
# Special trick: select a darker color for the space by creating a