home *** CD-ROM | disk | FTP | other *** search
/ Packard Bell - Internet on a CD / internet on a cd.cdr / Internet / sites / HTML_1 / hangman.pl < prev    next >
Encoding:
Perl Script  |  1998-07-16  |  3.2 KB  |  100 lines

  1. #!/bin/perl
  2.  
  3. require "cgi-lib.pl";
  4.  
  5. if (&ReadParse(*input)) {
  6.      print &PrintHeader;
  7.      print "<title> Hangman </title>";
  8.      print "<h1>The Hangman Game ...</h1>";
  9.      if ($input{'done'} eq 'done') # the person guessed the word
  10.     { if ($input{'real'} eq $input{'new'}) # did they get it right?
  11.             {print 'You were right.';}
  12.           else {print 'You were WRONG!<p>';
  13.                 print 'It was really ',$input{'real'},'.';}
  14.           print '<p><p>Click <a href="/cgi-bin/nik/hangman.pl>';
  15.           print 'here</a> to play again.';
  16.           return;
  17.        }
  18.      $input{'new'} =~ s/^(.)(.*)/$1/;  # only get the 1st char
  19.      $guess = $input{'new'}.' '.$input{'guess'}; # put the new one in $guess
  20.      @sofar = split(/\s+/,$guess); # make guess into an array
  21.      $gue = @sofar;
  22.      $num = length($input{'real'});
  23.      @rreal = split(/ */,$input{'real'}); # make the real word into an array
  24.                       # buy splitting on space or nil
  25.      print '<p>';
  26.      print 'So far you have guessed:<p>';
  27.      $gotten = 0;
  28.      LET: for ($i=0;$i<$num;$i++)  #go through the real word
  29.        { $temp = $rreal[$i];
  30.          for ($g=0;$g<$gue;$g++) #go through the guesses
  31.         { if ($sofar[$g] eq $temp) 
  32.              { print $temp;
  33.                $gotten = $gotten +1;
  34.                next LET;
  35.                }
  36.         }
  37.              print '_ ';
  38.          }
  39.      print '<p>';
  40.      if (($gue-$gotten) < 6) {
  41.         print 'Please type your next guess<p>';
  42.     print 'You have ',(6-($gue-$gotten)),' guesse(s) left!<p>';
  43.  
  44.     print <<EOF
  45. <form method="post" action="/cgi-bin/nik/hangman.pl">
  46. <input name = "new"><p>
  47. <input type="hidden" name="guess" value="$guess">
  48. <input type="hidden" name="real" value="$input{'real'}">
  49. <INPUT TYPE="reset" VALUE="Clear">
  50. <input type="submit" value="Continue">
  51. </form>
  52. Or if you are daring type in what you think that the word is.<p> 
  53. <form methos="post" action="/cgi-bin/nik/hangman.pl">
  54. <input name="new"><p> 
  55. <input type="hidden" name="done" value="done"> 
  56. <input type="hidden" name="real" value="$input{'real'}">
  57. <INPUT TYPE="reset" VALUE="Clear"> 
  58. <input type="submit" value="Guess It">
  59. </form> </html>
  60. EOF
  61.         }
  62.      else{
  63.     print <<EOF
  64. Sorry the game is over.<p>
  65. The correct answer is $input{'real'}.<p>
  66. click <a href="/cgi-bin/nik/hangman.pl"> here</a> to play again.
  67. EOF
  68.         }
  69.      }
  70. else {
  71.     print &PrintHeader;
  72.     print '<title> Hangman </title>';
  73.     print '<h1> Hangman Game.</h1><br>';
  74.     $real = "first";
  75.     $num = length($real);
  76.     for ($i=1;$i<=$num;$i++)
  77.      { print '_ ';
  78.       }
  79.     print '<p>';
  80.     print '<img src="http://blackcat.brynmawr.edu/~nswoboda/scripts/hang0.gif"><p>';
  81.     print 'Type in your first guess at the above unknown word.<p>';
  82.     print <<EOF
  83. <form method="post" action="/cgi-bin/nik/hangman.pl">
  84. <input name = "new"><p>
  85. <input type="hidden" name="guess" value="">
  86. <input type="hidden" name="real" value="$real">
  87. <INPUT TYPE="reset" VALUE="Clear">
  88. <input type="submit" value="Continue">
  89. </form>
  90. Or if you are daring type in what you think that the word is.<p>
  91. <form method="post" action="/cgi-bin/nik/hangman.pl">
  92. <input name="new"><p>
  93. <input type="hidden" name="done" value="done">
  94. <input type="hidden" name="real" value="$real">
  95. <INPUT TYPE="reset" VALUE="Clear">
  96. <input type="submit" value="Guess It">
  97. </form> </html>
  98. EOF
  99.     }
  100.