home *** CD-ROM | disk | FTP | other *** search
- #include <iostream.h>
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include "./cgi.h"
-
- int print_form(char *, char *);
-
- cgi_main(cgi_info *ci)
- { form_entry *params = NULL;
- char guess[10];
- char *nnew, *reall;
- int gue,i,g,num,n;
-
- params = get_form_entries(ci);
- reall = parmval(params,"reall");
- print_mimeheader("text/html");
-
- if(params != NULL) {
- cout << "<title> Hangman </title>"
- << "<h1>The Hangman Game ...</h1>";
- if (!(strcmp(parmval(params,"guess"),"done"))) /* they guessed */
- { if (!(strcmp(reall,parmval(params,"nnew")))) /* correct? */
- { cout << "You were right.";}
- else { cout << "You were WRONG!<p>"
- << "It was reallly %s.",reall;}
- cout << "<p><p>Click <a href=""/cgi-bin/nik/hangman"">"
- << "here</a> to play again.";
- return 1;
- }
- nnew = parmval(params,"nnew");
- sprintf(guess,"%s%c",parmval(params,"guess"),nnew[0]);
- gue = strlen(guess);
- num = strlen(reall);
- cout << "<p>So far you have guessed:<p>";
- n=0;
- for (i=0;i<num;i++)
- { for (g=0;g<gue;g++)
- { if (guess[g] == reall[i])
- { cout << reall[i];
- g=-1;
- n++;
- break;
- }
- }
- if (g==-1) continue;
- cout << "_ ";
- }
- cout << "<p>";
- if ((gue-n) < 6) {
- cout << "Please type your next guess<p>"
- << "You have " << (6-(gue-n)) << " guesse(s) left!<p>";
- print_form(reall,guess);
- }
- else{
- cout << "Sorry the game is over.<p>"
- << "The correct answer is " << reall << "<p>"
- << "click <a href=""/cgi-bin/nik/hangman"">"
- << "here</a> to play again.";
- }
- }
- else {
- cout << "<title> Hangman </title>"
- << "<h1> Hangman Game.</h1><br>";
- reall = "first";
- num = strlen(reall);
- for (i=1;i<=num;i++)
- { cout << "_ ";
- }
- cout << "<p>"
- << "Type in your first guess at the above unknown word.<p>";
- print_form(reall,"");
- }
- }
-
- print_form(char *reall,char *guess)
- { cout << "<form method=""post"" action=""/cgi-bin/nik/hangman"">"
- << "<input name = ""nnew""><p>"
- << "<input type=""hidden"" name=""guess"" value="""
- << guess << """>"
- << "<input type=""hidden"" name=""reall"" value="""
- << reall << """>"
- << "<INPUT TYPE=""reset"" VALUE=""Clear"">"
- << "<input type=""submit"" value=""Continue"">"
- << "</form>"
- << "Or if you are daring type in what"
- << " you think that the word is.<p>"
- << "<form method=""post"" action=""/cgi-bin/nik/hangman"">"
- << "<input name=""nnew""><p>"
- << "<input type=""hidden"" name=""guess"" value=""done"">"
- << "<input type=""hidden"" name=""reall"" value="""
- << reall << """>"
- << "<INPUT TYPE=""reset"" VALUE=""Clear"">"
- << "<input type=""submit"" value=""Guess It"">"
- << "</form> </html>";
- return 1;
- }
-
-