<?mml version=0.5 ?>

<mml>

<!-- mml_hangman by bits -->

<interface cosmetic_name="mml_games" unique_name="bits/hangman/1.0">

	<exports>
		<remote name="hangman!" window="main_window" />	
	</exports>

	<fontstyle name="verdana" face="Verdana" size="9" style="normal"/>
	<fontstyle name="verdana2" face="Verdana" size="12" style="normal"/>
	<fontstyle name="verdana3" face="Verdana" size="20" style="normal"/>

<window name="main_window" default_size="302,502" hitstyle="drag" shape="the_shape" >
	<shape name="the_shape">
		<shape_rect alignment=0,0,1,1 offset=0,450,0,0 />
		<shape_rect alignment=0,0,1,0 offset=0,0,0,440 />
	</shape>

<window name="top_window" alignment=0,0,1,0 offset=0,0,0,440 transparent="true">
	<imagestyle name="background">
		<color_fill color="0xff666666" />
		<color_rect color="0xffffffff" />
		<text color="0xffffffff" alignment=0,0,0,0 offset=7,2,100,12 justification="h_center" font_style="verdana">hangman 0.50</text>
	</imagestyle>

	<window name="close" type="button" transparent="true" alignment="1,0,1,0" offset="-10,0,-2,10" hitstyle="ACTIVE">
		<imagestyle name="state0">
			<text color="0xffffffff" justification="h_center" font_style="verdana">x</text>
		</imagestyle>
		<script name="OnClick">
			parent.parent.DestroyWindow();
		</script>
	</window>

	<window name="min" type="button" transparent="true" alignment="1,0,1,0" offset="-20,0,-12,10" hitstyle="ACTIVE">
		<imagestyle name="state0">
			<text color="0xffffffff" justification="h_center" font_style="verdana">_</text>
		</imagestyle>
		<script name="OnClick">
			MinimizeWindow(1);
		</script>
	</window>

	<window name="ourline" type="textdisplay" transparent="true" alignment="0,1,1,1" offset="0,-30,0,-10">
		<property font_style="verdana2" font_color=#ffffff font_justification="h_center" />
	</window>

	<window name="side" alignment="0,0,0,0" offset="30,60,120,390">
			<imagestyle name="background">
				<color_fill color="0xff666666" />
			</imagestyle>
		<window name="support" alignment="0,1,1,1" offset="1,-90,0,0">
			<imagestyle name="background">
				<color_fill color="0xff666666" />
				<color_line />
			</imagestyle>
		</window>
		<window name="left" alignment="0,0,0,1" offset="0,0,5,0">
			<imagestyle name="background">
				<color_fill />
			</imagestyle>
		</window>
	</window>

	<window name="rope" alignment="0,0,0,0" offset="149,60,151,110">
		<imagestyle name="background">
			<color_fill color="0xff8D5921" />
		</imagestyle>
	</window>

	<window name="top" alignment="0,0,1,0" offset="30,60,-30,65">
		<imagestyle name="background">
			<color_fill />
		</imagestyle>
	</window>

	<window name="bottom" alignment="0,0,1,0" offset="30,385,-30,390">
		<imagestyle name="background">
			<color_fill />
		</imagestyle>
	</window>

	<window name="leftarm" alignment="0,0,0,0" offset="120,175,150,220">
		<imagestyle name="background">
			<color_fill color="0xff666666" />
			<color_line alignment="1,0,0,1" />
		</imagestyle>
	</window>

	<window name="leftleg" alignment="0,0,0,0" offset="120,265,150,350">
		<imagestyle name="background">
			<color_fill color="0xff666666" />
			<color_line alignment="1,0,0,1" />
		</imagestyle>
	</window>

	<window name="rightarm" alignment="0,0,0,0" offset="150,175,180,220">
		<imagestyle name="background">
			<color_fill color="0xff666666" />
			<color_line />
		</imagestyle>
	</window>

	<window name="rightleg" alignment="0,0,0,0" offset="150,265,180,350">
		<imagestyle name="background">
			<color_fill color="0xff666666" />
			<color_line />
		</imagestyle>
	</window>

	<window name="body" alignment="0,0,0,0" offset="149,150,151,270">
		<imagestyle name="background">
			<color_fill color="0xff666666" />
			<color_line alignment="0,0,1,1" offset="1,0,-1,0" />
		</imagestyle>
	</window>

	<window name="noose" alignment="0,0,0,0" offset="135,110,165,153">
		<imagestyle name="background">
			<color_fill color="0xff666666" />
			<color_ellipse color="0xff8D5921" />
		</imagestyle>
	</window>

	<window name="head" alignment="0,0,0,0" offset="132,110,168,150">
		<imagestyle name="background">
			<color_fill color="0xff666666" />
			<color_ellipse />
		</imagestyle>
	</window>

	<window name="gamewon" alignment="0,0.5,1,0.5" offset="70,-20,-70,20">
		<imagestyle name="background">
			<color_fill color="0xff666666" />
			<text font_style="verdana3" color="0xffffffff" justification="h_center">You won.</text>
		</imagestyle>
	</window>

	<window name="gamelost" alignment="0,0.5,1,0.5" offset="70,-20,-70,20">
		<imagestyle name="background">
			<color_fill color="0xff666666" />
			<text font_style="verdana3" color="0xffffffff" justification="h_center">You Kill Him!!</text>
		</imagestyle>
	</window>

	<script name=OnInit>
		testing="-1";
		gamearray={{"b","i","t","s", " ", "m", "a", "d", "e", " ", "t", "h", "i", "s"},
				{"c","h","a","r", "l", "i","e"," ", "i", "s", " ", "a", " ", "c", "u", "t", "i", "e"},
				{"y", "o", "u", " ", "a", "r", "e", " ", "t", "h", "e", " ", "p", "e", "r", "f", "e", "c", "t", " ", "d", "r", "u", "g"},
				{"s", "o", "n", "i", "q", "u", "e", "2", " ", "m", "m", "l", " ", "g", "a", "m", "i", "n", "g"},
				{"m", "s", "n", "8", " ", "l", "e", "a", "k", "s", " ", "t", "o", " ", "n", "e", "t"},
				{"l", "a", "t", "e", " ", "n", "i", "g", "h", "t", " ", "c", "o", "d", "i", "n", "g"},
				{"t", "r", "i", "l", "l", "i", "a", "n", " ", "p", "r", "o", " ", "o", "w", "n", "z"},
				{"m", "m", "l", " ", "h", "a", "n", "g", "m", "a", "n", " ", "p", "r", "e", "a", "l", "p", "h", "a", " ", "t", "e", "s", "t"},
				{"s", "q", "u", "e", "e", "d", " ", "f", "i", "n", "i", "s", "h", " ", "p", "o", "n", "g"},
				{"f", "i", "n", "a", "l", " ", "o", "n", "e", " ", "f", "o", "r", " ", "t", "e", "s", "t"}};

		this.m = 0; this.a = 0; this.p = 0; 
		this.q1 = 0; this.q2 = 0; this.q3 = 0; this.q4 = 0; 
		this.v1 = 4; this.v2 = 3; this.v3 = 1; 
		game();
	</script>

	<script name="game">
		:system.timer.UnsetTimer("reset", top_window);

		// $j = random(0,9);
		testing+=1;
		// linearray = gamearray[$j];
		linearray = gamearray[testing];
		complete=0;

		for ($i in 0 to linearray.ArraySize()-1) {
			if (linearray[$i] != " " and $i == 0) {
				shownarray={"_"};
			}
			if (linearray[$i] != " " and $i != 0) {
				shownarray=shownarray|{"_"};
			}
			else if (linearray[$i] == " ") {
				shownarray=shownarray|{" "};
				complete+=1;
			}
			if ($i == 0) {
				winstring=linearray[$i];
				shownstring=shownarray[$i];
			}
			if ($i != 0) {
				winstring=winstring|linearray[$i];
				shownstring=shownstring|shownarray[$i];
			}
		}

		bottom.Hide();
		side.Hide();
		top.Hide();
		rope.Hide();
		noose.Hide();
		head.Hide();
		body.Hide();
		leftarm.Hide();
		rightarm.Hide();
		leftleg.Hide();
		rightleg.Hide();
		gamewon.Hide();
		gamelost.Hide();

		completesize=linearray.ArraySize();
		hang=0;
		hangsize=11;
		checking=0;
		userchar="null";

		ourline.SetText(shownstring);
	</script>

	<script name=check>
		checking=complete;
		for ($i in 0 to linearray.ArraySize()-1) {
			if (userchar == linearray[$i]) {
				shownarray[$i]=linearray[$i];
				complete+=1;
			}
			if ($i == 0) {
				shownstring=shownarray[$i];
			}
			if ($i != 0) {
				shownstring=shownstring|shownarray[$i];
			}
			if (checking == complete+1) {
				checking=0;
			}
			if ($i == linearray.ArraySize()-1) {
				if (checking == complete) {
					if (userchar != winstring) {
						hang+=1;
						drawhim();
						checking=0;
					}
				}
			}
		}
		ourline.SetText(shownstring);
		if (complete == completesize) {
			gamewon.Show();
			:system.timer.SetTimer("reset", 2500, "top_window.game();", top_window, "false");
		}
		if (hang == hangsize) {
			ourline.SetText(winstring);
			gamelost.Show();
			:system.timer.SetTimer("reset", 2500, "top_window.game();", top_window, "false");
		}
	</script>

	<script name="drawhim">
		if (hang=="1") {
			bottom.Show();
		}
		if (hang=="2") {
			side.Show();
		}
		if (hang=="3") {
			top.Show();
		}
		if (hang=="4") {
			rope.Show();
		}
		if (hang=="5") {
			noose.Show();
		}
		if (hang=="6") {
			head.Show();
		}
		if (hang=="7") {
			body.Show();
		}
		if (hang=="8") {
			leftarm.Show();
		}
		if (hang=="9") {
			rightarm.Show();
		}
		if (hang=="10") {
			leftleg.Show();
		}
		if (hang=="11") {
			rightleg.Show();
		}
	</script>

	<script name=random>
		// random( min, max );
		$range = $params[1] - $params[0]; 
		if (this.m == 0) {this.a = 1; this.m = 32000;} 
		this.m--; 
		this.q1 += 1; 
		if (this.q1 gte this.v1) {this.q1 = 0; this.p = this.p + this.a; this.v1 = -this.v1;} 
		this.q2 += 1; 
		if (this.q2 gte this.v2) {this.q2 = 0; this.p = this.p + this.a; this.v2 = -this.v2;} 
		this.q3 += 1; 
		if (this.q3 gte this.v3) {this.q3 = 0; this.p = this.p + this.a; this.v3 = -this.v3;} 
		this.q4 += 1; 
		this.q4 %= $range; 
		this.p %= $range; 
		if (this.q4 == this.p) {this.a += 1; this.a %= 15;} 
		this.v1 = p; 
		this.p += this.v1 + this.v2 + this.v3; 
		this.p %= $range; 
		this.v3 = this.v2; 
		this.v2 = this.v1; 
		return (this.v1 + $params[0]);
	</script>
</window>

<window name="bottom_window" alignment=0,0,1,1 offset=0,450,0,0 transparent="true">
	<imagestyle name="background">
		<color_fill color="0xff666666" />
		<color_rect color="0xffffffff" />
	</imagestyle>

	<window name="ourbox" type="EditBox" offset="10,20,-60,40" alignment="0,0,1,0">
		<imagestyle name="background_inactive">
			<color_fill alignment="entire" color="0xFF000080" />
		</imagestyle>
		<imagestyle name="background_active">
			<color_fill alignment="entire" color="0xFF0000FF" />
		</imagestyle>
		<property font_color="0xffffffff" cursor_on_color="0xff000040" cursor_off_color="0xff0000FF"/>
	</window>

	<window name="set" type="button" transparent="true" alignment="1,0,1,0" offset="-40,22,-5,38" hitstyle="ACTIVE">
		<property hover="true" default_delay="150" text="go" font_color="0xffffffff" />
		<imagestyle name="state0">
			<color_fill color="0xFF6060C0" state="normal"/>
			<color_fill color="0xFF7070D0" state="hover" />
			<color_fill color="0xFF8080FF" state="hit"   />
		</imagestyle>
		<script name="OnClick">
			if (ourbox.GetText() != " ") {
				main_window.top_window.userchar=ourbox.GetText();
				main_window.top_window.check();
			}
			if (ourbox.GetText() == main_window.top_window.winstring) {
				main_window.top_window.ourline.SetText(ourbox.GetText());
				main_window.top_window.gamewon.Show();
				:system.timer.SetTimer("reset", 2500, "top_window.game();", top_window, "false");
			}
			ourbox.SetText("");
		</script>
	</window>
</window>

</window>

</interface>

</mml>
