Code: Select all
<?php
$Category = "";
# list of words (phrases) to guess below, separated by new line
$list = "Pig
Cat
Dog
Matthew
Mattie
Chris
";
# make sure that any characters to be used in $list are in either
# $alpha OR $additional_letters, but not in both. It may not work if you change fonts.
# You can use either upper OR lower case of each, but not both cases of the same letter.
# below ($alpha) is the alphabet letters to guess from.
# you can add international (non-English) letters, in any order, such as in:
# $alpha = "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÑÒÓÔÕÖØÙÚÛÜÝŸABCDEFGHIJKLMNOPQRSTUVWXYZ";
$alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
# below ($additional_letters) are extra characters given in words; '?' does not work
# these characters are automatically filled in if in the word/phrase to guess
$additional_letters = " -.,;!?%&0123456789";
#========= do not edit below here ======================================================
echo<<<endHTML
<HTML><HEAD><TITLE>Hangman Game</TITLE>
<meta content="text/html; charset=windows-1252" http-equiv=content-type>
<meta http-equiv="Content-Style-Type" content="text/css">
<script type="javascript">document.attachEvent("onkeydown", DisableKeys);
document.oncontextmenu = new Function("return false");
document.ondrag = new Function("return false");</script>
<style type="text/css">
<!--
H1 {font-family: "Courier New", Courier, monospace; font-size: 18pt;}
P {font-family: Verdana, Arial, sans-serif; font-size: 12pt;}
A:link {COLOR: #000000; TEXT-DECORATION: none;}
A:visited {COLOR: #000000; TEXT-DECORATION: none;}
A:active {COLOR: #000000; TEXT-DECORATION: none;}
A:hover {COLOR: #000000; TEXT-DECORATION: none;}<br />
#normal {text-decoration:underline !important; color:#0000FF !important;}
#strike {text-decoration:line-through;}
#hidden {visibility:hidden; font-size: 1px;}
-->
</style>
endHTML;
include("../../Include Content/Scripts/No Select Text.php");
include("../../Include Content/Scripts/Right Click.php");
echo<<<endHTML
</HEAD>
<BODY bgColor="#9CDCC8" link="navy" vlink="navy" alink="navy">
<DIV ALIGN="center">
endHTML;
$len_alpha = strlen($alpha);
if(isset($_GET["n"])) $n=$_GET["n"];
if(isset($_GET["letters"])) $letters=$_GET["letters"];
if(!isset($letters)) $letters="";
if(isset($PHP_SELF)) $self=$PHP_SELF;
else $self=$_SERVER["PHP_SELF"];
$links="";
$max=6; # maximum number of wrong
# error_reporting(0);
$list = strtoupper($list);
$words = explode("\n",$list);
srand ((double)microtime()*1000000);
$all_letters=$letters.$additional_letters;
$wrong = 0;
echo "<P><B>Hangman</B><BR>\n";
if (!isset($n)) { $n = rand(1,count($words)) - 1; }
$word_line="";
$word = trim($words[$n]);
$done = 1;
for ($x=0; $x < strlen($word); $x++)
{
if (strstr($all_letters, $word[$x]))
{
if ($word[$x]==" ") $word_line.=" "; else $word_line.=$word[$x];
}
else { $word_line.="_<font size=1> </font>"; $done = 0; }
}
if (!$done)
{
for ($c=0; $c<$len_alpha; $c++)
{
if (strstr($letters, $alpha[$c]))
{
if (strstr($words[$n], $alpha[$c])) {$links .= "\n<B><FONT id=\"hidden\">$alpha[$c]</font></B> "; }
else { $links .= "\n<FONT color=\"red\">$alpha[$c]</font>"; $wrong++; }
}
else
{ $links .= "\n<A HREF=\"$self?letters=$alpha[$c]$letters&n=$n\"><b>$alpha[$c]</b></A> "; }
}
$nwrong=$wrong; if ($nwrong>6) $nwrong=6;
echo "\n<p><BR>\n<IMG SRC=\"hangman_$nwrong.gif\" ALIGN=\"MIDDLE\" BORDER=0 WIDTH=100 HEIGHT=100 ALT=\"Wrong: $wrong out of $max\">\n";
if ($wrong >= $max)
{
$n++;
if ($n>(count($words)-1)) $n=0;
echo "<BR><BR><H1><font size=5>\n$word_line</font></H1>\n";
echo "<p><BR><FONT color=\"red\"><BIG>SORRY, YOU LOSE!!!</BIG></FONT><BR><BR>";
if (strstr($word, " ")) $term="phrase"; else $term="word";
echo "The $term was \"<B>$word</B>\"<BR><BR>\n";
echo "<A HREF=$self?n=$n><FONT id=\"normal\" color=\"blue\">Play again.</font></A>\n\n";
}
else
{
echo " Wrong Guesses Left: <B>".($max-$wrong)."</B><BR>\n";
echo "<H1><font size=5>\n$word_line</font></H1>\n";
echo "<P><BR>Choose a letter:<BR><BR>\n";
echo "$links\n";
}
}
else
{
$n++; # get next word
if ($n>(count($words)-1)) $n=0;
echo "<BR><BR><H1><font size=5>\n$word_line</font></H1>\n";
echo "<P><BR><BR><B>Congratulations!!! You win!!!</B><BR><BR><BR>\n";
echo "<A HREF=$self?n=$n><FONT id=\"normal\" color=\"blue\">Play again</font></A>\n\n";
}
echo<<<endHTML
</DIV></BODY></HTML>
endHTML;
?>