#!/usr/bin/perl ########################################### # Guess Game v1.0 by Allen C. Huffman # # Copyright (C) 2001 by Sub-Etha Software # # FREEWARE! # # subetha@pobox.com # # http://disneyfans.com/subetha # ########################################### # # You may do whatever you want with this code, provided you put a comment in that # says "Baseed on" (or similar) and my original copyright notice above. # # Revision History: # # 2001/08/03 1.0 Initial (working) version. # # # A number between 1 and ... ? # $max = 100; # # Where do we send the user when they are done playing? # $done_playing_URL = "http://yourdomain.com/yourpage.htm"; # # If you want to count how many play the game, specify # a path to the count data file here, else leave it empty. # $counter_path = "seguessgame.dat"; # # Location/name of this script... Hopefully you won't have to change # this, but if you do it should be something like "/cgi-bin/seguessgame.cgi" # or wherver your script is and whatever it is called... # $this_script = "$ENV{'SCRIPT_NAME'}"; #################################################################################### # # Begin processing... Nothing below this line needs to be modified. # &ReadParse; # if no input, this must be the first time the script has ran... if (!$in) { $tries = 0; $magic = int(rand($max-1)); $magic++; &do_top; print "
Welcome to Sub-Etha Software's GUESS THE NUMBER game!
\n"; # if we have specified a counter file, let's use it. if ( $counter_path ) { unless ( open(FILE, "+<$counter_path") ) { open( FILE,"+>$counter_path") || die ("Unable to create file.\n" ); } $count =This game has been played $count time"; if ( $count!=1 ) { print "s"; } print " so far.
\n"; } &do_form; &do_end; exit(0); } $magic = $in{'magic'}; $tries = $in{'tries'}; # first, are we done? $playagain = $in{'playagain'}; if ( $playagain eq 'Yes' ) { print "Location: $this_script\n\n"; } elsif ( $playagain eq 'No' ) { print "Location: $done_playing_URL\n\n"; } elsif ( $playagain eq 'Give Up' ) { &do_top; print "The magic number was $magic..." . "You gave up after $tries "; if ( $tries==1 ) { print "try"; } else { print "tries"; } print ".
\n"; &play_again; &do_end; exit(0); } $guess = $in{'guess'}; $tries++; &do_top; if ( $guess < $magic ) { print "That guess was too low!
\n"; } elsif ( $guess > $magic ) { print "That guess was too high!
\n"; } else { print "You gueesed it, and it only took you $tries "; if ( $tries==1 ) { print "try"; } else { print "tries"; } print "!
\n"; &play_again; &do_end; exit(0); } &do_form; &do_end; exit(0); sub do_top { print "Content-Type: text/html\n\n"; print "I am thinking of a number between 1 and $max.