/* * May 28, 1991 * _ . . _ _ __ * /_)_(_/_/_)_ " * and replace the function Random(), with the one provided by * your compiler. Also, you should **rewrite** the function: disk_free() * --------- * (If you don't know how to code the function disk_free() on your * computer, just use the following code: * * long disk_free() * { * return( (long)sizeof(hi_table) ); * } * * It will work, unless your disk does not have room to save the table * of scorers (normally this is 132 bytes, but it will change if you * change the values of the macros defined below) * ) * * * * * ================================================================== * Disclaimer * ================================================================== * "I make no warranty with respect to this file, or the programs * it describes, and disclaim any implied or explicit suggestions of * usefulness for any particular purpose. Use this software only if * you are willing to assume all risks and damages, if any, arising * as a result, even if it is caused by negligence or other fault." * ================================================================== */ #include #include /* * the following header file is only included for * the machine depended call: Random(). If you * compile the program on a computer other than the * ST, you may have to use a different header file * (or none: I think Turbo C on the IBM PC has a * random function in its standard library) */ #include /* MACRO Definitions * ----------------- * if you don't like the current values of the following * macros you can change them. The game will be still running fine */ #define MAXTURN 12 /* Maximum # of turns */ #define MAXNAME 10 /* Maximum # of letters in player's name */ #define MAXSYMB 5 /* Maximum # of symbols in hidden pattern */ #define MAXTABL 11 /* Maximum # of entries in table of hi-scores */ /* * the following macro clears the screen on a VT52 terminal (ST screen). * you should modify it according to your terminal's escape sequences * (if you are using Turbo C on an IBM PC (or compatible), you should * use the function ClrScr() instead) */ #define clear() putchar(27); putchar('E'); /* TYPE Definitions * ---------------- */ typedef struct{ /* current player's name and score */ int score; char name[MAXNAME]; }REC_TYPE; /* GLOBAL Variables * ---------------- */ long seedval; /* used for the random-value calculation */ FILE *seedfile; /* file to keep the seed-value */ FILE *hi_file; /* file holding the High Scores */ FILE *lastgame; /* file keeping last player's performance */ int tab_changed; /* TRUE when table-of-scores has been changed */ REC_TYPE hi_table[MAXTABL]; /* table of high scorers */ /* ======================================================================== * * main * * ======================================================================== */ main() { /* VARIABLE Declarations * --------------------- */ REC_TYPE lastrec; /* last player's record */ char name[MAXNAME]; /* player's name */ char secret[MAXSYMB]; /* the hidden pattern */ char inptrn[MAXSYMB]; /* the input (guessing) pattern */ char hlpsecret[MAXSYMB]; /* - look in function check() - */ char hlpinptrn[MAXSYMB]; /* - look in function check() - */ char answer[2]; int same, identical; /* - look in function check() - */ int errid; /* error id */ int score, turn, found; /* FUNCTION References * ------------------- */ long getseed(); void gethitab(); void welcome(), readstr(), strupper(); void init(), info(), error_check(); void check(), give_hints(), comments(), show_hitab(); void upd_table(), upd_lastfile(), upd_tabfile(), upd_seed(); REC_TYPE *getlastgame(); gethitab(hi_table); /* get/init the hi-table */ lastrec = *getlastgame(); /* get/init last player's record */ seedval = getseed(); /* get/init value of seed */ strcpy(answer,"Y"); tab_changed = 0; /* init flag to FALSE */ do{ init(secret, hlpsecret, &score); /* set initial values */ welcome(hi_table); /* show welcome screen */ if ( answer[0] != 'A' ){ printf("\tWhat is your name? "); readstr(name,MAXNAME); strupper(name); } else{ printf("\tPress to start the game "); rewind(stdin); getchar(); } info(lastrec,name); found = 0; turn = 1; printf(" ????? Enter guess # 1: "); do{ readstr(inptrn,MAXSYMB); strupper(inptrn); /* convert pattern to uppercase */ error_check(inptrn,&errid,&turn); /* check for any errors */ if ( !strcmp(inptrn,"Q") || !strcmp(inptrn,"QUIT") ){ score = turn = 0; break; } if ( !strcmp(inptrn,"R") ) strcpy(inptrn," "); strcpy(hlpsecret,secret); strcpy(hlpinptrn,inptrn); check(hlpsecret, hlpinptrn, &identical, &same); score = score - turn*100 + (5*identical + 3*same); printf("%5d %s ", score, inptrn); give_hints(identical,same); if ( !strcmp(secret,inptrn) ){ found = 1; /* TRUE */ break; } turn++; if ( turn<=MAXTURN ) printf(" Enter guess #%2d: ", turn); }while( turn<=MAXTURN && !found ); if (!found){ printf("\nThe hidden pattern was <%s>", secret); score = 0; } puts("\n----------------------------------------------------------------\ ---------------"); printf("FINAL SCORE:%-5d >>> ", score); comments(turn); puts("------------------------------------------------------------------\ -------------"); upd_table(hi_table, name, score); strcpy(lastrec.name, name); lastrec.score = score; printf("Do you wanna play again (y/n/a)? "); rewind(stdin); gets(answer); strupper(answer); seedval = Random(); }while( answer[0] == 'Y' || answer[0] == 'A' ); puts("\n\n"); show_hitab(hi_table); puts("\n\n"); upd_lastfile(lastrec); upd_tabfile(hi_table); upd_seed(); exit(0); } /* ======================================================================== * * gethitab * * ======================================================================== */ void gethitab( hi_table ) REC_TYPE hi_table[]; { /* * load (or initialize) the table of scorers into the array 'hitable[]' */ register int i; /* load the table */ if ( hi_file=fopen("TABLE.DAT","rb") ){ for (i=0; iname, &(temp->score) ); fclose(lastgame); } /* if not on disk, initialize it */ else{ strcpy(temp->name,"harryk"); temp->score = 1100; } return(temp); } /* ======================================================================== * * welcome * * ======================================================================== */ void welcome( table ) REC_TYPE table[]; /* table of scorers */ { /* * display welcome screen and table of scorers */ void show_hitab(); clear(); /* display the welcome screen */ puts("\0"); puts(" () _ _ _ __ __ _ __ "); puts(" /\\ ' ) / ' ) ) / ` ' ) ) "); puts(" / ) / / /--' /-- /--' "); puts(" /__/_ (__/ / (___, / \\_ "); putchar('\n'); puts(" _ _ _ __ () ______ __ _ __ _ _ _ _ _ __ __ "); puts(" ' ) ) ) / ) /\\ / / ` ' ) ) ' ) ) ) | ) ' ) ) / )"); puts(" / / / /--/ / ) --/ /-- /--' / / / ,---|/ / / / / "); puts(" / ' (_/ ( /__/_ (_/ (___, / \\_ / ' (_ \\_/ \\ / (_/__/_ "); putchar('\n'); /* display the table of scorers */ show_hitab( table ); } /* ======================================================================== * * info * * ======================================================================== */ void info( last, name ) REC_TYPE last; /* information about the last player */ char name[]; /* name of the current player */ { /* * display some useful information for the gameplay */ clear(); printf("Last Player was: %10s - %5d pts\t * - Right symbol,right place\n", last.name, last.score); printf("Current Player: %10s \t\t# - Right symbol,wrong place\n", name); puts("----------------------------------------------------------------------\ ---------"); puts("SCORE PATTERN HINTS (valid symbols -> A, B, C, D, E, F, G, H)"); puts("----------------------------------------------------------------------\ ---------"); } /* ======================================================================== * * readstr * * ======================================================================== */ void readstr( str, max ) char str[]; /* the string to be read */ short max; /* the maximum number of chars to be read */ { /* * read a string up to 'max' characters long */ register short i; rewind(stdin); for (i=0; (str[i]=getchar()) != '\n' && i