<commit_before>REBOL [
	title: "Hangman"
	author: "Asmodehn"
	version: 0.2.0
	date: 26-Nov-2008
	copyright: "Freeware"
]

hangman: context [
	;TODO :  font/image loading
	
	do %Hangman-data.r
	
	main-size: 800x600
	;wordlist: [ "croissant" "baguette" ]	
	
	do %Hangman-dictionary.r
	
	sound-port: open sound:// 
	max-life: 5
	
	init: does [
		;print "!!! init !!!"
		random/seed now 
		hangword: copy pick wordlist (random length? wordlist)
		hiddenword: copy "" loop (length? hangword) [ append hiddenword "_" ]
		;probe hiddenword
		unguessed: copy [ #"a" #"b" #"c" #"d" #"e" #"f" #"g" #"h" #"i" #"j" #"k" #"l"
					 #"m" #"n" #"o" #"p" #"q" #"r" #"s" #"t" #"u" #"v" #"w" #"x" #"y" #"z"]
		guessed: copy []
		life: max-life
		;probe life
	]

	restart: does [
					hangman/main/pane: [ startup ] 
				    clear hangman/sound-port
					play-sound %Hangman-data/Mortalk1.wav
					view center-face hangman/main
	]

	startup: layout/offset [ 
					origin 0x0
					space 0x0
					size main-size
					backdrop %Hangman-data/TitleScreen.png
					
					at 333x400
					start-btn: button 134x50 %Hangman-data/Start.png backcolor white 
					backcolor green
	] 0x0

	animidle: []
	file-list: read %./Hangman-data/idle/
	foreach file file-list [
		if find to-string file "idle" [
			append animidle rejoin [ %./Hangman-data/idle/ file ]
		]
	]
	
	animcar: []
	file-list: read %./Hangman-data/car/
	foreach file file-list [
		if find to-string file "car" [
			append animcar rejoin [ %./Hangman-data/car/ file ]
		]
	]
	
	animgrenade: []
	file-list: read %./Hangman-data/grenade/
	foreach file file-list [
		if find to-string file "grenade" [
			append animgrenade rejoin [ %./Hangman-data/grenade/ file ]
		]
	]
	
	
	animwinner: []
	file-list: read %./Hangman-data/winner/
	foreach file file-list [
		if find to-string file "winner" [
			append animwinner rejoin [ %./Hangman-data/winner/ file ]
		]
	]
	
	animloser: []
	file-list: read %./Hangman-data/loser/
	foreach file file-list [
		if find to-string file "loser" [
			append animloser rejoin [ %./Hangman-data/loser/ file ]
		]
	]
	
	gamerunning: layout/offset [ 
				origin 0x0
				space 0x0
				size main-size
				anim-pane: box 666x535 red
				
				at 8x525
				life-bar: box 650x60 white
				at 0x535
				word-pane: box 666x65 white
				return			
				btn-pane: box 134x600 white
				backcolor white
	] 0x0
	
	play-anim-idle: does [
		anim-pane/pane: layout/offset [ 
							origin 0x0
							anim 666x535 rate 24 frames animidle effect [ fit ]
						] 0x0
		show anim-pane
	]
	
	play-anim-car: does [
		hide btn-pane
		anim-time: ( length? animcar ) / 24 
		anim-pane/pane: layout/offset [
							origin 0x0
							anim 666x535 rate 24 frames animcar	effect [ fit ]
						] 0x0
		show anim-pane
		wait anim-time
		show btn-pane
		play-anim-idle 
	]

	play-anim-grenade: does [
		hide btn-pane
		anim-time: ( length? animgrenade ) / 24 
		anim-pane/pane: layout/offset [
							origin 0x0
							anim 666x535 rate 24 frames animgrenade	effect [ fit ]
						] 0x0
		show anim-pane
		wait anim-time
		show btn-pane
		play-anim-idle 
	]
	
	draw-life-bar: does [ 
		life-box: reduce [ 'origin 0x0 'space 0x0 'box to-pair rejoin [( 650 * life / max-life ) "x10" ] 'black ] 
		life-bar/pane: layout/offset life-box 0x0
		show life-bar
	] 

	gameover: layout/offset [
				origin 0x0
				space 0x0 
				size main-size
				anim 800x600 rate 24 frames animloser
				at 90x0
				image 620x167 %Hangman-data/lose.png
				at 400x300
				button 100x50 %Hangman-data/lose.png [
					restart
				]
				backcolor red	
	] 0x0
 
	gamesuccess: layout/offset [ 
				origin 0x0
				space 0x0
				size main-size
				anim 800x600 rate 24 frames animwinner
				at 124x0
				image 552x167 %Hangman-data/win.png
				at 400x300
				button 100x50 %Hangman-data/win.png [
					restart
				] 
				backcolor green
	] 0x0
	
	main: layout [ 
				size main-size 
				title "Hangman"
				backcolor black
	]
	
	start-btn/action: [ 
		init
		main/pane: [ gamerunning ]
		draw-text hiddenword
		remake-buttons
		draw-life-bar
		play-anim-idle
		show main
	]	   

	lose-life: func [] [
		life: life - 1
		draw-life-bar
		show gamerunning<commit_msg>try again button now in<commit_after>REBOL [
	title: "Hangman"
	author: "Asmodehn"
	version: 0.2.0
	date: 26-Nov-2008
	copyright: "Freeware"
]

hangman: context [
	;TODO :  font/image loading
	
	do %Hangman-data.r
	
	main-size: 800x600
	;wordlist: [ "croissant" "baguette" ]	
	
	do %Hangman-dictionary.r
	
	sound-port: open sound:// 
	max-life: 5
	
	init: does [
		;print "!!! init !!!"
		random/seed now 
		hangword: copy pick wordlist (random length? wordlist)
		hiddenword: copy "" loop (length? hangword) [ append hiddenword "_" ]
		;probe hiddenword
		unguessed: copy [ #"a" #"b" #"c" #"d" #"e" #"f" #"g" #"h" #"i" #"j" #"k" #"l"
					 #"m" #"n" #"o" #"p" #"q" #"r" #"s" #"t" #"u" #"v" #"w" #"x" #"y" #"z"]
		guessed: copy []
		life: max-life
		;probe life
	]

	restart: does [
					hangman/main/pane: [ startup ] 
				    clear hangman/sound-port
					play-sound %Hangman-data/Mortalk1.wav
					view center-face hangman/main
	]

	startup: layout/offset [ 
					origin 0x0
					space 0x0
					size main-size
					backdrop %Hangman-data/TitleScreen.png
					
					at 333x400
					start-btn: button 134x50 %Hangman-data/Start.png backcolor white 
					backcolor green
	] 0x0

	animidle: []
	file-list: read %./Hangman-data/idle/
	foreach file file-list [
		if find to-string file "idle" [
			append animidle rejoin [ %./Hangman-data/idle/ file ]
		]
	]
	
	animcar: []
	file-list: read %./Hangman-data/car/
	foreach file file-list [
		if find to-string file "car" [
			append animcar rejoin [ %./Hangman-data/car/ file ]
		]
	]
	
	animgrenade: []
	file-list: read %./Hangman-data/grenade/
	foreach file file-list [
		if find to-string file "grenade" [
			append animgrenade rejoin [ %./Hangman-data/grenade/ file ]
		]
	]
	
	
	animwinner: []
	file-list: read %./Hangman-data/winner/
	foreach file file-list [
		if find to-string file "winner" [
			append animwinner rejoin [ %./Hangman-data/winner/ file ]
		]
	]
	
	animloser: []
	file-list: read %./Hangman-data/loser/
	foreach file file-list [
		if find to-string file "loser" [
			append animloser rejoin [ %./Hangman-data/loser/ file ]
		]
	]
	
	gamerunning: layout/offset [ 
				origin 0x0
				space 0x0
				size main-size
				anim-pane: box 666x535 red
				
				at 8x525
				life-bar: box 650x60 white
				at 0x535
				word-pane: box 666x65 white
				return			
				btn-pane: box 134x600 white
				backcolor white
	] 0x0
	
	play-anim-idle: does [
		anim-pane/pane: layout/offset [ 
							origin 0x0
							anim 666x535 rate 24 frames animidle effect [ fit ]
						] 0x0
		show anim-pane
	]
	
	play-anim-car: does [
		hide btn-pane
		anim-time: ( length? animcar ) / 24 
		anim-pane/pane: layout/offset [
							origin 0x0
							anim 666x535 rate 24 frames animcar	effect [ fit ]
						] 0x0
		show anim-pane
		wait anim-time
		show btn-pane
		play-anim-idle 
	]

	play-anim-grenade: does [
		hide btn-pane
		anim-time: ( length? animgrenade ) / 24 
		anim-pane/pane: layout/offset [
							origin 0x0
							anim 666x535 rate 24 frames animgrenade	effect [ fit ]
						] 0x0
		show anim-pane
		wait anim-time
		show btn-pane
		play-anim-idle 
	]
	
	draw-life-bar: does [ 
		life-box: reduce [ 'origin 0x0 'space 0x0 'box to-pair rejoin [( 650 * life / max-life ) "x10" ] 'black ] 
		life-bar/pane: layout/offset life-box 0x0
		show life-bar
	] 

	gameover: layout/offset [
				origin 0x0
				space 0x0 
				size main-size
				anim 800x600 rate 24 frames animloser
				at 90x0
				image 620x167 %Hangman-data/lose.png
				at 251x300
				button 298x88 %Hangman-data/TryAgain.png [
					restart
				]
				backcolor red	
	] 0x0
 
	gamesuccess: layout/offset [ 
				origin 0x0
				space 0x0
				size main-size
				anim 800x600 rate 24 frames animwinner
				at 124x0
				image 552x167 %Hangman-data/win.png
				at 251x300
				button 298x88 %Hangman-data/TryAgain.png [
					restart
				] 
				backcolor green
	] 0x0
	
	main: layout [ 
				size main-size 
				title "Hangman"
				backcolor black
	]
	
	start-btn/action: [ 
		init
		main/pane: [ gamerunning ]
		draw-text hiddenword
		remake-buttons
		draw-life-bar
		play-anim-idle
		show main
	]	   

	lose-life: func [] [
		life: life - 1
		draw-life-bar
		show gamerunning
{'fraction_non_alphanumeric': 0.11901619676064787, 'fraction_numerical': 0.04583083383323335, 'mean_word_length': 2.4094069529652353, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1595962', 'n_tokens_mistral': 4226, 'n_tokens_neox': 3201, 'n_words': 829}