#! ./tkmem -f

# $Header: /sda3/home/klausf/schule/mata/projekt/memory/RCS/spieltkmem,v 1.6 1995/08/01 13:23:25 klausf Exp $

# $Log: spieltkmem,v $
# Revision 1.6  1995/08/01  13:23:25  klausf
# Nearly all strings are now setable in an application-default-file.
#
# Revision 1.4  1994/11/07  05:55:46  klausf
# *** empty log message ***
#
# Revision 1.3  1994/08/04  08:29:01  klausf
# CChanged documentation to English (half Way)
# Prepared for standard-Xt-Way of application-defaults
#
# Revision 1.2  1994/08/03  18:44:22  klausf
# About korrigiert
#
# Revision 1.1  1994/08/03  18:36:35  klausf
# Initial revision
#

# of cards (duplicates variable in .c-File)
set N 25

#	Prepare for overriding of options
set appDefault /usr/lib/X11/app-defaults/spieltkmem
if [file readable $appDefault] {
	option readfile $appDefault startupFile
}

#	As we have lots of Bitmaps defined we may use one of them
#	as the bitmap if iconified.
wm iconbitmap . pix_3
wm title . "Memory"
wm protocol . WM_DELETE_WINDOW {SpielendeExit}

# *****	Create Window 
# -----	Menu-Bar
frame .mbar -relief raised -bd 2

#	Two buttons
#	(configurable button-label)
option add spieltkmem.mbar.game.text "Spiel" widgetDefault
menubutton .mbar.game -menu .mbar.game.menu
#	(hardcoded button-label)
menubutton .mbar.help -text "?" -menu .mbar.help.menu
                
#	Arrange buttons on Menu bar
pack .mbar.game -side left
pack .mbar.help -side right
tk_menuBar .mbar .mbar.game .mbar.help

#	Pull-down-menus
# It is a bit tricky to get configurable labels on Pull-down-menues.
# We actually define ressources under the existing pull-down-widget
# with english names.
menu .mbar.game.menu
option add spieltkmem.mbar.game.menu.newgame "Neues Spiel" widgetDefault
.mbar.game.menu add command \
	-label [option get .mbar.game.menu newgame NewGame] \
	-command doNew
option add spieltkmem.mbar.game.menu.end "Ende" widgetDefault
.mbar.game.menu add command \
	-label [option get .mbar.game.menu end End] \
	-command {SpielendeExit}

menu .mbar.help.menu
option add spieltkmem.mbar.help.menu.about "ber" widgetDefault
.mbar.help.menu add command \
	-label [option get .mbar.help.menu about About] \
	-command showAbout
option add spieltkmem.mbar.help.menu.help "Hilfe" widgetDefault
.mbar.help.menu add command \
	-label [option get .mbar.help.menu help Help] \
	-command showHelp

#	Auxilary functions for main-menu
proc Spielende {} {
	# You may save the score here.
}

proc SpielendeExit {} {
	Spielende
	exit
}

proc doNew {} {
	# If - in a future version - the # of cards have changed
	# one may destroy or create buttons here
	global N
	NeuesSpiel $N
}

# source /usr/X386/lib/X11/tk/dialog.tcl
source $tk_library/dialog.tcl

option add spieltkmem.helplabel "Hilfe fr Memory" widgetDefault
option add spieltkmem.helptext "Welche Hilfe erwarten Sie fr\
	Memory?  Nehmen Sie Gedchtnispillen!" widgetDefault
proc showHelp {} {
	tk_dialog .d \
		[option get . helplabel HelpLabel] \
		[option get . helptext HelpText] \
		questhead -1 ok
}

option add spieltkmem.aboutlabel "ber ..." widgetDefault
proc showAbout {} {
	tk_dialog .d \
		[option get . aboutlabel AboutLabel] \
		{ Memory-Spiel unter X-Windows und Tcl/Tk
(c) Klaus Fller, Lichtenberg-Gymnasium Kassel
$Id: spieltkmem,v 1.6 1995/08/01 13:23:25 klausf Exp $} \
		questhead -1 ok
}

# -----	Game-Area
# frame .desk -width 10c -height 5c
frame .desk

# ----- Statistic-bar with two centered fields
frame .stat -relief raised -bd 2
#	Hack to get fields centered
frame .stat.dummy
pack .stat.dummy 
option add spieltkmem.stat.trytext.text "Versuche: " widgetDefault
label .stat.trytext 
label .stat.try -relief sunken -textvariable try -width 4
option add spieltkmem.stat.successtext.text "Erfolg: " widgetDefault
label .stat.successtext
label .stat.success -relief sunken -textvariable success -width 3 \
	-foreground green
pack .stat.trytext .stat.try .stat.successtext .stat.success \
	-side left -in .stat.dummy
set success 0
set try 0

# ----- Arrange components of main window
pack .mbar .desk .stat -side top -fill x
proc zeigeKarte {N I} {
	.desk.button($N) configure -bitmap pix_$I
}

proc Statistik {v e} {
	global try
	global success
	set try $v
	set success $e
}

# ***** Create rows of buttons on .desk

proc createCards {N} {
	set card 0
	set cols [expr sqrt(2 * $N)]
	set col 0
	set row 0
	while {$card < [expr 2 * $N]} {
		if {$col > $cols} {set col 0}
		if {$col == 0} {
			incr row
			frame .desk.zeile($row)
			pack .desk.zeile($row)
		}
		incr col
		button .desk.button($card) -relief raised -width 32 -height 32 \
			-bitmap pix_0 -command "DeckeAuf $card"
		pack .desk.button($card) -in .desk.zeile($row) -side left
		incr card
	}
}

createCards $N

# ***** Initialize Game
NeuesSpiel $N
