<html>
<head> <title> Hangman </title> </head>
<body>
<h1> Hangman  </h1>

<server>  
// Initialize gameno if have not played before
// client.newgame is set to "True" for first game and by youwon/youlost
   if (client.gameno == null)
   {
      client.gameno = 1;
      client.newgame = "true";
   }
   // Initialize secret word, answer, and used for each new game.
   if (client.newgame=="true")
   {
      if (client.gameno % 3 == 1)
        client.word = "LIVEWIRE";
      if (client.gameno % 3 == 2)
        client.word = "NETSCAPE";
      if (client.gameno % 3 == 0)
        client.word = "COMMUNICATIONS";   

      client.answer = InitAnswer(client.word);
      client.used = "";
      client.num_misses = 0;
   }

   client.newgame = "false";  // set flag to indicate not to initialize next time
   
   // Make guess if specified in request context
   if (request.guess != null)
   {
      request.guess = request.guess.toUpperCase();
      debug(request.guess);
      client.used = client.used + request.guess + " ";
      request.old_answer = client.answer;
      client.answer = Substitute(request.guess, client.word, client.answer);
      if (request.old_answer == client.answer)
         client.num_misses = 1 + parseInt(client.num_misses,10); 
   }

   if (client.answer == client.word)
      redirect("youwon.html");  // redirect if you win.
   else if (client.num_misses > 6)
      redirect("youlost.html");  // redirect if you lose. 
</server>

<P>
<img src=`"images/hang"+client.num_misses+".gif"`>

<pre><server>write(client.answer);</server></pre>

You have used the following letters so far: <server>write(client.used);</server>

<form method="post" action="2">
<P>
What is your guess?
<input type="text" name="guess" size="1">
<p>
<input type="submit" value="Enter">  
<input type="reset" value="Clear">

</body>
</html>


