Page 1 of 1

PHP Game not working

Posted: Sat Jul 08, 2006 1:42 pm
by mmcoolkid94
I am having a problem with this code. After you choose your first or second letter it sends you to example.com. Its in the folder: http://website.com/example.com/Hangman/ so i think it think to go to example.com. Can anyone help?

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.="&nbsp; "; else $word_line.=$word[$x];
  } 
  else { $word_line.="_<font size=1>&nbsp;</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 " &nbsp; 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!!! &nbsp;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;
?>

Posted: Sat Jul 08, 2006 3:32 pm
by Ollie Saunders
Bloody hell, when I was 11 I couldn't write a proper sentence in English let alone any PHP.

I had a good look at your code and it's very difficult to understand. You have a lot of redundency in there, that is, your doing things in obsecure ways that make it unnecessarily complicated.

Also I don't know what exactly this game does, if you could explain that to me I'll be able to understand where you are going wrong.

oh and by the way for commenting

Code: Select all

# hash style comments -- bad

Code: Select all

// c++ style comments -- good

Posted: Sat Jul 08, 2006 3:53 pm
by mmcoolkid94
Well then how can I improve it? I am still having the problem with the game. Can someone else test the code and see if you get the same problem?

Posted: Sat Jul 08, 2006 4:24 pm
by nickvd
ole wrote:oh and by the way for commenting

Code: Select all

# hash style comments -- bad

Code: Select all

// c++ style comments -- good
Is this personal preference/style? or is there a different reason for this.

Posted: Sat Jul 08, 2006 4:33 pm
by mmcoolkid94
I forgot to tell you what the game is it is simple hangman game.

Posted: Sat Jul 08, 2006 4:36 pm
by Ollie Saunders
i'm pretty sure its deprecated so you won't be able to use it come PHP 6, also its always been the "other way" of commenting so fewer people know it.