#!/usr/bin/perl ############################################################################## # Cliff's Hangman Version 1.0 # # Copyright 1998 Shaven Ferret Productions # # Created 10/18/98 # # Available at http://www.shavenferret.com/scripts # ############################################################################## # COPYRIGHT NOTICE # # Copyright 1998 Shaven Ferret Productions All Rights Reserved. # # # # This script can be used\modified free of charge as long as you don't # # change this header, the part that makes the return link, and any parts # # that call the part that makes the return link. If you really need to # # remove the return link, go to # # http://www.shavenferret.com/scripts/register.shtml . By using this script # # you agree to indemnify me from any liability that might arise from its use.# # # # Redistributing\selling the code for this program without prior written # # consent is expressly forbidden. # ############################################################################## # If the text file containing the words and phrases that will be used in the # game are not in the same directory as this script, enter the server path # (not the URL) to the file. $wordfile = "hangman.txt"; # If these words involve a common theme, enter that here. $clue = "Videogame History!"; # Set the next variable to the URL of the directory that contains the images. # Do not include a trailing slash. $imagedir = "http://www.vgln.com/online/hangman"; ############################################################################## # Congratulations! You've finished defining the variables. If you want to, # # you can continue screwing with the script, but it isn't necessary. # ############################################################################## open(FILE,"$wordfile"); @words = ; close(FILE); read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s/\n/ /g; $FORM{$name} = $value; } print "Content-type: text/html\n\n"; if ($FORM{'action'}) { &start; } unless ($FORM{'word'}) { &start; } else { &guess; } sub start { srand(); $FORM{'word'} = int(rand($#words+1)); print "Hangman\n"; print "

Hangman

\n"; chomp($words[$FORM{'word'}]); @word_chars = split(//, $words[$FORM{'word'}]); $words[$FORM{'word'}] =~ tr/A-Z/a-z/; @l_word_chars = split(//, $words[$FORM{'word'}]); @wrong = (); @right = (); $FORM{'wrong'} = ""; $FORM{'right'} = ""; &makepage; } sub makepage { print "
\n"; print "\n"; print "\n"; print "\n"; print "
\n"; if ($won) { print "

You Won!!!

\n"; } if ($lost) { print "

You Lost...

The word was $words[$FORM{'word'}]
\n"; } if ($clue) { print "
This word would fit in the catagory of: $clue
\n"; } print "
\n"; print "
\n"; if ($#wrong >= 0) { print "
\n"; } if ($#wrong == 1) { print "
\n"; } if ($#wrong == 2) { print "
\n"; } if ($#wrong >= 3) { print "
\n"; } if ($#wrong == 4) { print "
\n"; } if ($#wrong >= 5) { print "
\n"; } if ($#wrong == 6) { print "
\n"; } if ($#wrong == 7) { print "
\n"; } print "
Word or phrase
\n"; for ($i = 0; $i <= $#word_chars; $i++) { my $guess = 0; if ($word_chars[$i] =~ /(\W|\s)/) { print "$word_chars[$i]"; } else { $guessed = 0; foreach $guess(@right) { if ($guess eq $l_word_chars[$i]) { $guessed = -1; } } if ($guessed == -1) { print "$word_chars[$i]"; } else { print "_"; } } } print "

Correct Guesses:
\n"; foreach $guess(@right) { print "$guess "; } print "

Incorrect Guesses:
\n"; foreach $guess(@wrong) { print "$guess "; } unless ($won == -1 || $lost == -1) { print "

Guess a letter or number:"; print "

\n"; } print "
\n"; print "

Hangman s"; print "cript hosted by VGLN.com 2001(tm), Back "; print "to games index, Game made at http://www."; print "shavenferret.com/scripts.
\n"; print "\n"; exit; } sub guess { if ($FORM{'guess'} =~ /(\W|\s)/) { print "Please guess a letter or number\n"; print "

Please guess a letter or number.

\n"; &makepage; } chomp($words[$FORM{'word'}]); @word_chars = split(//, $words[$FORM{'word'}]); $words[$FORM{'word'}] =~ tr/A-Z/a-z/; @l_word_chars = split(//, $words[$FORM{'word'}]); @wrong = split(//, $FORM{'wrong'}); @right = split(//, $FORM{'right'}); foreach $char(@wrong) { if ($char eq $FORM{'guess'}) { $guessed = -1; } } foreach $char(@right) { if ($char eq $FORM{'guess'}) { $guessed = -1; } } if ($guessed == -1) { print "You already guessed that one, genius boy\n"; print "

Try a letter you haven't guessed...

\n"; &makepage; } foreach $char(@l_word_chars) { if ($char eq $FORM{'guess'}) { $guessed = -1; } } if ($guessed == -1) { push(@right,$FORM{'guess'}); $FORM{'right'} = $FORM{'guess'} . $FORM{'right'}; print "Correct!\n"; print "

Correct!

\n"; $won = -1; foreach $char(@l_word_chars) { $done = 0; foreach $char2(@right) { if ($char eq $char2) { $done = 1; } } if ($char =~ /(\W|\s)/) { $done = 1; } if ($done == 0) { $won = 0; } } &makepage; } else { push(@wrong,$FORM{'guess'}); $FORM{'wrong'} = $FORM{'guess'} . $FORM{'wrong'}; if ($#wrong == 7) { $lost = -1; } print "Wrong.\n"; print "

Wrong.

\n"; &makepage; } }