|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T h
Length: 5561 (0x15b9) Types: TextFile Names: »hangman.c«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987 └─⟦this⟧ »EUUGD18/General/Hangman1/hangman.c«
/* hangman.c * * hangman game. uses termcap...terminal must be in /etc/termcap * written by: ritcv!jxs7451 * help with screen.c from: ritcv!jeb1265 (from ogre i guess) * * To run on another system: adjust WORDL and WORDMAX * * Program is designed and tested on Ultrix 1.1 and 4.2BSD */ #include "hangman.h" #include<stdio.h> #include<strings.h> #include<signal.h> main(argc, argv) int argc; char *argv[]; { int debug = 0; /* 1 if debug permission granted */ int hard = 0; /* 1 if hard is requested */ int length = 0; /* minimum length of a word */ int nl = 0; /* loop counter variable */ int right = 0; /* 1 if got word right */ int ch = 0; /* holds users guess */ int left; /* tries left */ int att = 0; /* attempts used */ int flag = 0; /* general flag */ char word[MAXLINE]; /* string for actuall word */ char guess[MAXLINE]; /* the string guessed */ int tried[127]; /* entry 1 if char tried */ doargs(argc, argv, &debug, &hard, &length); switch (length) { case 1: /* harder */ length = LMINWORD; break; case 2: /* hard */ length = LLMINWORD; break; default: /* normal */ length = MINWORD; break; } switch (hard) { case 1: left = HTRIES; /* hard */ break; case 2: left = ETRIES; /* easy */ break; default: left = TRIES; /* norm */ break; } /* set so cannot stop or break. term gets messed up if stop abnormally */ signal(SIGTSTP, SIG_IGN); /* stop signal */ signal(SIGINT, SIG_IGN); /* interupt */ signal(SIGQUIT, SIG_IGN); /* quit */ initman(left); srandom(time()); init_term(); getwd(word, &length); cltried(tried); for (nl=0;word[nl] != '\0';nl++) /* putting - in guess string */ guess[nl] = '-'; drawscrn(); while (!right && left) { turninfo(guess,att,left,tried,word,debug); setcur(ERROR - 1,1); erasel(0,0); printf(PROMPT); while (tried[(ch = getlet())] != 0) { switch (ch) { case '!' : doshell(); init_term(); drawscrn(); turninfo(guess,att,left,tried,word,debug); break; case 'G' : clbtm(); setcur(ERROR,1); puts("Enter the whole word."); printf("enter the word: "); nl = wordguess(word); switch (nl) { case 1: /* win */ turninfo(word,att,left,tried,word,debug); puts("\nSuper guess!! You got it right."); if (left > 1) printf("You had %d guesses left.\n",left); else puts("You had 1 guess left."); reset_term(); exit(0); break; case 2: /* lose */ att++; killman(); turninfo(word,att,left,tried,word,debug); clbtm(); setcur(ERROR,1); puts("Nope, thats not it."); die(att); /* echo hangman */ reset_term(); exit(0); /* quit */ break; default: /* continue */ break; } turninfo(guess,att,left,tried,word,debug); break; case 'Q' : doquit(); turninfo(guess,att,left,tried,word,debug); break; case '?' : help(); turninfo(guess,att,left,tried,word,debug); break; case 18 : drawscrn(); turninfo(guess,att,left,tried,word,debug); break; default: clbtm(); setcur(ERROR,1); puts("You already tried that letter."); break; } /* end of switch */ setcur(ERROR - 1,1); erasel(0,0); printf(PROMPT); } tried[ch] = 1; /* set tried */ for (nl=flag=0;word[nl] != '\0';nl++) /* check if guess in word */ if (word[nl] == (char) ch) { guess[nl] = (char) ch; flag++; /* set flag */ } if (!flag) /* flag set if gets 1 right */ { left--; incman(); clbtm(); setcur(ERROR,1); printf("nope, no '%c' in the word.\n",ch); } else { clbtm(); setcur(ERROR,1); printf("Good guess!!"); } right = !(strcmp(guess,word)); /* check if done */ att++; /* increment tries */ } clbtm(); turninfo(word,att,left,tried,word,debug); if (right) if (left > 1) printf("You got it in %d attempts, with %d misses left.\n",att,left); else printf("You got it in %d attempts, with %d miss left.\n",att,left); else die(att); reset_term(); }