<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");    // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); 
                                                     // always modified
header("Cache-Control: no-store, no-cache, must-revalidate");  // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");                          // HTTP/1.0
?>
<html>
<!--
Hangman - mitzu2006
(I'm taking credit for writing this code, not for inventing the game of hangman :) )

Add words to words.txt, separated with \n (this can be done with addaword.php)

chmod 666 words.txt to allow it to be edited on the server
Remove link to 'addaword.php' from this page if you do not want to allow users to add new words

Feel free to email me any questions about this code.
Much of the code in this file was adapted from a section in 'Beginning PHP4' published by Wrox, ISBN 1-861003-73-0
I'd recommend this book to anyone who wants to start learning PHP

calum

t2shady4u_2006@yahoo.com
-->
<head>
<title>Hangman</title>
</head>
<body bgcolor="#FFFFFF">
			
<div align='center'>
<h1>Hangman</h1>
<?php



$alphabet = array("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");


//open wordlist file
$file = "words.txt"; // words file
$fd = fopen($file, "r"); // open the file in read-only mode
$words = file($file);  // put each word in the array
fclose ($fd);



$wrong = 0;



if (!isset($word_number)) { $word_number = rand(1,count($words)) - 1; }



$word = $words[$word_number];
$word = ereg_replace("\n", "", $word);
// uncomment for debugging
// echo("<p>Word is $word</p>");
// echo("<p>Word number $word_number</p>");

echo"<h1>";
$finished = 1;
for ($i=0; $i < strlen($word); $i++) {
	if (ereg($word[$i], $letters)) {
		echo $word[$i];
	}
	else {
		echo "-";
		$finished = 0;
	}
}
echo"</h1>";


if ($finished) {
	echo "<br><br><font size=4>Congratulations! You win!</font><br><br>";
	echo "<a href=$PHP_SELF><font size=4>Play again</font></a>";
	}
	else {
		foreach ($alphabet as $var) {
			if (ereg($var, $letters)) {
				if (ereg($var, $words[$word_number])) {
					$links .= "<b>$var</b>  ";
				} else {
					$links .= "$var  ";
					$wrong++;
				}
			}
		else {
			$links .= "<a href=\"$PHP_SELF?letters=$letters$var&word_number=$word_number\">$var</a>  ";
		}
	}

	echo "<br><img src=\"./hangman_img.php?wrong=$wrong\"><br>";

	if ($wrong == 11) {
		echo "<br><font size=4>You lose!!!</font><br><br>";
		echo "<font size=4>The word you were looking for was \"$word\"</font><br><br>";
		echo "<a href=$PHP_SELF>Play again</a>";
	} else {
		echo "Tries remaining: ".(11-$wrong)."<br>";
		echo "<br>Choose a letter.<br><br>";
		echo $links;
echo "<br/>";


echo "<a title=\"Enter\" href=\"welcome.php?username=$username&amp;password=$password\">Back to ChevysLounge</a>";
echo "<br/>";

	}
}
?>
<p>&nbsp;</p>

 
</div>
</body>
</html>
