home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / W / ATIMPY.ZIP / STIMP8.C < prev    next >
C/C++ Source or Header  |  1992-03-20  |  17KB  |  659 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <io.h>
  4. #include <fcntl.h>
  5.  
  6. #define DATAF "matcher\\matcher.dat"
  7. #define QUESTIONS "matcher\\quest.txt"
  8. #define NUMBER_OF_MATCHES 5
  9. #define MINIMUM_COMPATABILITY 01
  10.  
  11.  
  12. void nogo();
  13. void help();
  14. void ballroom();
  15. void entrance();
  16. void stairs();
  17. void living();
  18. void patio();
  19. void quit();
  20. void landing();
  21. void dining();
  22. void study();
  23. void green();
  24. void kitchen();
  25. void drive();
  26. void bath();
  27. void pantry();
  28. void backpat();
  29.  
  30. int    usernum,         /* user number for the user */
  31.        age,             /* age of the user */
  32.        screenchars,     /* chars/line user has specified */
  33.        screenlines,     /* lines/screen user has specified */
  34.        sl,              /* sec lev for user (0-255) */
  35.        so,              /* non-zero if user is sysop (sl=255) */
  36.        cs,              /* non-zero if user is co-sysop */
  37.        okansi,          /* non-zero if user can support ANSI */
  38.        incom,           /* non-zero if user is calling remotely */
  39.        comport;         /* com port user is on */
  40. char   name[81],        /* name/alias of user */
  41.        realname[81],    /* real name of user */
  42.        callsign[10],    /* amateur radio callsign of user */
  43.        sex,             /* sex of user, M or F */
  44.        laston[81],      /* date user was last on */
  45.        gfiles[81],      /* directory for text files, ends in \ */
  46.        data[81],        /* directory for non-text files, ends in \ */
  47.        sysoplog[81],    /* full path & filename for sysop log */
  48.        curspeed[81];    /* speed user is on at, "KB" if local */
  49. double gold,            /* gold user has */
  50.        timeallowed;     /* number of seconds before user logged off */
  51.   int     numdaters;
  52.   char    works[21],
  53.           cho;
  54.  
  55.  
  56.     FILE *df,*qf; /* user data file */
  57.  
  58.  
  59.   struct{
  60.         char name[81],
  61.              sex,
  62.              phone[20],
  63.              answ[44],     /* array of answers to 43 questions */
  64.              ans1[242],     /* 3 short answer strings */
  65.              ans2[242],
  66.              ans3[242];
  67.  
  68.         int  age;          /* p is the current person. */
  69.                     }  p,x;          /* x is someone being compared */
  70.                            /* to the current user. */
  71.  
  72.  
  73. int read_in_data(char *fn)
  74.  
  75. {
  76.   char buf[1024];  /* This is where the file will be put for fast access. */
  77.   char *ptr[30];   /* This will hold pointers to parts of the buf array,
  78.                       acting as an index. */
  79.   int i,f,len,i1;  /* i, i1 = loop control variables;
  80.                       len = number of bytes read from file;
  81.                       f = file descriptor number for the filename. */
  82.   float fl;        /* This holds a temporary value of the user's gold. */
  83.                    /* fn = the filename of the CHAIN.TXT file. */
  84.  
  85.   f=open(fn,O_RDONLY | O_BINARY);  /* Open the file for input as a binary file,
  86.                                       i.e. without character translations. */
  87.   if (f<0) {                       /* If the file descriptor (f) is less than
  88.                                       0 (i.e. it is -1) then abort the
  89.                                       function and return error (-1). */
  90.     return(-1);
  91.   }
  92.   i1=1;                            /* Initialize i1. */
  93.   ptr[0]=buf;                      /* Point the first index to the first character
  94.                                       of the buf array. */
  95.   len=read(f,(void *)buf,1024);    /* Read in from the file f into buf up to
  96.                                       1024 characters (until the EOF is reached)
  97.                                       and return the actual number of characters
  98.                                       read in len. */
  99.   close(f);                        /* We're finished with the file so put it
  100.                                       away. */
  101.   for (i=0; i<len; i++)            /* This for loop goes through the buf array
  102.                                       (which now contains the contents of the
  103.                                       chain info file) and assigns indices to
  104.                                       the ptr array of pointers. It causes all
  105.                                       returns to be mapped into null characters
  106.                                       (ASCII 0) for use as strings, and skips
  107.                                       over the following LF character. In this
  108.                                       way, ptr will end up pointing to a bunch
  109.                                       of character strings. */
  110.     if (buf[i]==13) {
  111.       buf[i]=0;
  112.       ptr[i1++]=&buf[i+2];
  113.     }
  114.   while (*ptr[6]==32)              /* Remove leading spaces for the float
  115.                                       values by incrementing the pointer
  116.                                       by one character. */
  117.     ++(ptr[6]);
  118.   while (*ptr[15]==32)
  119.     ++(ptr[15]);
  120.   usernum=atoi(ptr[0]);            /* From here on it is straight translation
  121.                                       from the ptr index array into the global
  122.                                       variables. */
  123.                                    /* Get the user number from index 0. */
  124.   strcpy(name,ptr[1]);             /* Get the name, real name, and callsign. */
  125.   strcpy(realname,ptr[2]);
  126.   strcpy(callsign,ptr[3]);
  127.   age=atoi(ptr[4]);                /* Get the user's age. */
  128.   sex=*ptr[5];                     /* Get the user's sex. */
  129.   sscanf(ptr[6],"%f",&fl);         /* These two lines read in the user's gold
  130.                                       and typecast it into a double float. */
  131.   gold=(double)fl;
  132.   strcpy(laston,ptr[7]);           /* Get his date of last being on. */
  133.   screenchars=atoi(ptr[8]);        /* Get the size of his screen. */
  134.   screenlines=atoi(ptr[9]);
  135.   sl=atoi(ptr[10]);                /* Get his seclev. */
  136.   so=atoi(ptr[11]);                /* Is he a sysop? (nonzero if true) */
  137.   cs=atoi(ptr[12]);                /* How about a cosysop? */
  138.   okansi=atoi(ptr[13]);            /* Does he use ANSI graphics? */
  139.   incom=atoi(ptr[14]);             /* Is he calling remotely (1) or not? */
  140.   sscanf(ptr[15],"%f",&fl);        /* These two lines read in the number of
  141.                                       seconds left to the user and typecast
  142.                                       the value into a double float. */
  143.   timeallowed=(double)fl;
  144.   strcpy(gfiles,ptr[16]);          /* What is the gfiles dir? */
  145.   strcpy(data,ptr[17]);            /* What is the data dir? */
  146.   strcpy(sysoplog,gfiles);         /* These two lines get the full pathname
  147.                                       for the sysoplog file. */
  148.   strcat(sysoplog,ptr[18]);
  149.   strcpy(curspeed,ptr[19]);        /* A string containing the user's
  150.                                       bps/baud rate or KB if local. */
  151.   comport=atoi(ptr[20]);           /* The user's comport if remote. */
  152.   return(0);                       /* Return and give a 'we read it in fine'
  153.                                       message. */
  154.  
  155.  
  156. }
  157.  
  158. char upcase(char ch)
  159. /* This converts a character to uppercase */
  160. {
  161.   if ((ch > '`') && (ch < '{'))
  162.     ch = ch - 32;
  163.   return(ch);
  164. }
  165.  
  166. void quit()
  167. {
  168. exit(0);
  169. }
  170.  
  171. void nogo()
  172. {
  173. printf("\nYou can't go that way!\n");
  174. }
  175.  
  176. void help()
  177. {
  178. printf("\nGame Commands:\n");
  179. printf("N North\n");
  180. printf("S South\n");
  181. printf("E East\n");
  182. printf("W West\n");
  183. printf("? Help\n");
  184. printf("U Up\n");
  185. printf("D Down\n");
  186. printf("Q Quit\n");
  187. }
  188.  
  189. void entrance()
  190. {
  191.   printf("\n\nYou are in the Entrance Hall\n");
  192.   printf("Command?  ");
  193.    cho=upcase(getche());
  194.    switch(cho) {
  195.      case 'N':
  196.        stairs();
  197.      case 'S':
  198.        nogo();
  199.        puts("A locked door blocks your exit.");
  200.        entrance();
  201.      case 'E':
  202.        ballroom();
  203.      case 'W':
  204.        living();
  205.      case '?':
  206.        help();
  207.        entrance();
  208.      case 'Q':
  209.        quit();
  210.      default:
  211.        entrance();
  212.    }
  213. }
  214.  
  215. void ballroom()
  216. {
  217.   printf("\n\nYou are in the ballroom\n");
  218.   printf("Command?  ");
  219.    cho=upcase(getche());
  220.    switch(cho) {
  221.      case 'N':
  222.        patio();
  223.      case 'S':
  224.        puts("\nThere are only barred windows here.");
  225.        ballroom();
  226.      case 'E':
  227.        puts("\nThere are only barred windows here.");
  228.        ballroom();
  229.      case 'W':
  230.        entrance();
  231.      case '?':
  232.        help();
  233.        ballroom();
  234.      case 'Q':
  235.        quit();
  236.      default:
  237.        ballroom();
  238.    }
  239. }
  240.  
  241. void stairs()
  242. {
  243.   printf("\n\nYou are at the bottom of a staircase.\n");
  244.   printf("Command?  ");
  245.   cho=upcase(getche());
  246.   switch(cho) {
  247.     case 'N':
  248.       nogo();
  249.       stairs();
  250.     case 'S':
  251.       entrance();
  252.     case 'E':
  253.       nogo();
  254.       stairs();
  255.     case 'W':
  256.       nogo();
  257.       stairs();
  258.     case 'U':
  259.       landing();
  260.     case 'D':
  261.       puts("\nYou are already down.");
  262.       stairs();
  263.     case '?':
  264.       help();
  265.       stairs();
  266.     case 'Q':
  267.       quit();
  268.     default:
  269.       stairs();
  270.   }
  271. }
  272.  
  273. void living()
  274. {
  275.   printf("\n\nYou are in the living room.\n");
  276.   printf("Command?  ");
  277.   cho=upcase(getche());
  278.   switch(cho) {
  279.     case 'N':
  280.       dining();
  281.     case 'S':
  282.       puts("\nThere are only barred windows here.");
  283.       living();
  284.     case 'E':
  285.       entrance();
  286.     case 'W':
  287.       study();
  288.     case '?':
  289.       help();
  290.       living();
  291.     case 'Q':
  292.       quit();
  293.     default:
  294.       living();
  295.   }
  296. }
  297.  
  298. void patio()
  299. {
  300.   printf("\n\nYou are outside on the patio.\n");
  301.   printf("Command?  ");
  302.   cho=upcase(getche());
  303.   switch(cho) {
  304.     case 'N':
  305.       puts("\nA huge wall of shrubbery blocks your way!");
  306.       patio();
  307.     case 'S':
  308.       ballroom();
  309.     case 'E':
  310.       puts("\nYou wouldn't survive the drop off the patio.");
  311.       patio();
  312.     case 'W':
  313.       puts("\nYou can't walk through the side of the house!");
  314.       patio();
  315.     case '?':
  316.       help();
  317.       patio();
  318.     case 'Q':
  319.       quit();
  320.     default:
  321.       patio();
  322.   }
  323. }
  324.  
  325. void landing()
  326. {
  327.   printf("\n\nYou are on the landing at the top of the stairs.\n");
  328.   printf("Command?  ");
  329.   cho=upcase(getche());
  330.   switch(cho) {
  331.     case 'N':
  332.       nogo();
  333.       landing();
  334.     case 'S':
  335.       nogo();
  336.       landing();
  337.     case 'E':
  338.       nogo();
  339.       landing();
  340.     case 'W':
  341.       nogo();
  342.       landing();
  343.     case 'U':
  344.       puts("\nYou are already up!");
  345.       landing();
  346.     case 'D':
  347.       stairs();
  348.     case '?':
  349.       help();
  350.       landing();
  351.     case 'Q':
  352.       quit();
  353.     default:
  354.       landing();
  355.   }
  356. }
  357.  
  358. void dining()
  359. {
  360.   printf("\n\nYou are in the vast dining hall.\n");
  361.   printf("Command?  ");
  362.   cho=upcase(getche());
  363.   switch(cho) {
  364.     case 'N':
  365.       backpat();
  366.     case 'S':
  367.       living();
  368.     case 'E':
  369.       kitchen();
  370.     case 'W':
  371.       nogo();
  372.       dining();
  373.     case '?':
  374.       help();
  375.       dining();
  376.     case 'Q':
  377.       quit();
  378.     default:
  379.       dining();
  380.   }
  381. }
  382.  
  383. void study()
  384. {
  385.   printf("\n\nYou are in the study.\n");
  386.   printf("Command?  ");
  387.   cho=upcase(getche());
  388.   switch(cho) {
  389.     case 'N':
  390.       green();
  391.     case 'S':
  392.       nogo();
  393.       study();
  394.     case 'E':
  395.       living();
  396.     case 'W':
  397.       nogo();
  398.       study();
  399.     case '?':
  400.       help();
  401.       study();
  402.     case 'Q':
  403.       quit();
  404.     default:
  405.       study();
  406.   }
  407. }
  408.  
  409. void green()
  410. {
  411.   printf("\n\nYou are now in the greenhouse.\n");
  412.   printf("Command?  ");
  413.   cho=upcase(getche());
  414.   switch(cho) {
  415.     case 'N':
  416.       backpat();
  417.     case 'S':
  418.       study();
  419.     case 'E':
  420.       nogo();
  421.       green();
  422.     case 'W':
  423.       nogo();
  424.       green();
  425.     case '?':
  426.       help();
  427.       green();
  428.     case 'Q':
  429.       quit();
  430.     default:
  431.       green();
  432.   }
  433. }
  434.  
  435. void kitchen()
  436. {
  437.   printf("\n\nYou are in the kitchen.\n");
  438.   printf("Command?  ");
  439.   cho=upcase(getche());
  440.   switch(cho) {
  441.     case 'N':
  442.       drive();
  443.     case 'S':
  444.       bath();
  445.     case 'E':
  446.       pantry();
  447.     case 'W':
  448.       dining();
  449.     case '?':
  450.       help();
  451.       kitchen();
  452.     case 'Q':
  453.       quit();
  454.     default:
  455.       kitchen();
  456.   }
  457. }
  458.  
  459. void drive()
  460. {
  461.   printf("\n\nYou are on the driveway.\n");
  462.   printf("Command?  ");
  463.   cho=upcase(getche());
  464.   switch(cho) {
  465.     case 'N':
  466.       puts("\nA huge iron fence blocks your way.");
  467.       drive();
  468.     case 'S':
  469.       kitchen();
  470.     case 'E':
  471.       puts("\nA huge locked gate blocks your way.");
  472.       drive();
  473.     case 'W':
  474.       puts("\nYou can't get through the bushes.");
  475.       drive();
  476.     case '?':
  477.       help();
  478.       drive();
  479.     case 'Q':
  480.       quit();
  481.     default:
  482.       drive();
  483.   }
  484. }
  485.  
  486. void bath()
  487. {
  488.   printf("\n\nYou are in the bathroom.\n");
  489.   printf("Command?  ");
  490.   cho=upcase(getche());
  491.   switch(cho) {
  492.     case 'N':
  493.       kitchen();
  494.     case 'S':
  495.       puts("\nYou see the toilet.");
  496.       bath();
  497.     case 'E':
  498.       puts("\nYou see yourself in the mirror.");
  499.       bath();
  500.     case 'W':
  501.       puts("\nOoo! See the pretty wallpaper!");
  502.       bath();
  503.     case '?':
  504.       help();
  505.       bath();
  506.     case 'Q':
  507.       quit();
  508.     default:
  509.       bath();
  510.   }
  511. }
  512.  
  513. void pantry()
  514. {
  515.   printf("\n\nYou are in the pantry.\n");
  516.   printf("Command?  ");
  517.   cho=upcase(getche());
  518.   switch(cho) {
  519.     case 'N':
  520.       nogo();
  521.       pantry();
  522.     case 'S':
  523.       nogo();
  524.       pantry();
  525.     case 'E':
  526.       nogo();
  527.       pantry();
  528.     case 'W':
  529.       kitchen();
  530.     case '?':
  531.       help();
  532.       pantry();
  533.     case 'Q':
  534.       quit();
  535.     default:
  536.       pantry();
  537.   }
  538. }
  539.  
  540. void backpat()
  541. {
  542.   printf("\n\nYou are on the back patio.\n");
  543.   printf("Command?  ");
  544.   cho=upcase(getche());
  545.   switch(cho) {
  546.     case 'N':
  547.       nogo();
  548.       backpat();
  549.     case 'S':
  550.       puts("\n\nThere are two doors, left to the dining room, right to the greenhouse.");
  551.       printf("Which door? (L or R)  ");
  552.       cho=upcase(getche());
  553.     switch(cho) {
  554.       case 'L':
  555.         dining();
  556.       case 'R':
  557.         green();
  558.       default:
  559.         backpat();
  560.       }
  561.     case 'E':
  562.       puts("\nThere are bushes in your way.");
  563.       backpat();
  564.     case 'W':
  565.       puts("\nThere are bushes in your way.");
  566.     case '?':
  567.       help();
  568.       backpat();
  569.     case 'Q':
  570.       quit();
  571.     default:
  572.       backpat();
  573.   }
  574. }
  575.  
  576.  
  577.  
  578.  
  579. void newperson()
  580. {
  581.  
  582. int qn; /* question number */
  583. char question[81], /* stores the question read in from a file */
  584.      choice;               /* stores user's answer */
  585.  
  586.  
  587. printf("You are a new prospect.\n");
  588. strcpy(p.name,name);
  589. p.sex=sex;
  590. printf("Would you like to play?\n");
  591. cho=getche();
  592. if (cho=='N' || cho=='n') {
  593. printf("\nToo bad. C-ya!\n");
  594. exit(0); }
  595. printf("\nOh Joy of Joys! You are going to play!\n\n");
  596. p.age=age;
  597. printf("Welcome, %s.\n",p.name);
  598. printf("Have fun and enjoy the game!\n\n");
  599. printf("You have just stepped into a large seemingly abandoned mansion. You are\n");
  600. printf("standing in the entrace hall. Suddenly the large heavy front door swings\n");
  601. printf("shut behind you and locks itself. You must explore this huge structure\n");
  602. printf("and try to find your way home. You may need to pick up some seemingly useless\n");
  603. printf("items on the way.");
  604. printf("\n\n");
  605.   entrance();
  606. }
  607.  
  608. void main(int argc, char *argv[])
  609. {
  610.   int zots=0;  /* zots is a flag to tell if the user is new */
  611.                /* zots==1 means his record has been found, and
  612.                   his record will not be appended at the end. */
  613.  
  614.   argc=argc;
  615.   argv=argv;
  616.  
  617.   if (read_in_data("chain.txt")==-1) { /* Try to read in the parameter file
  618.                                       and if it returns the -1 error message,
  619.                                       quit the program with an error message. */
  620.     printf("\nData file not found\n\n");
  621. /*    abort(); */
  622.   }
  623.   if (okansi) printf("\x1B[2J");
  624.     printf("Welcome to the Quest For Freedom game!\n");
  625.     printf("This game is brought to you by Stimpy\n");
  626.     printf("Sysop of The Devil's Doorknob (410-442-1601)\n");
  627.  
  628.   df=fopen(DATAF,"r");
  629.   if (df==NULL)
  630.     {
  631.     df=fopen(DATAF,"w");
  632.         printf("Initializing data file.\n\n");
  633.         strcpy(p.name,"nul");
  634.     p.sex='N';
  635.     strcpy(p.phone,"555-1212");
  636.     strcpy(p.answ,"2222222222222222222222222222222222222222222");
  637.     strcpy(p.ans1," "); strcpy(p.ans2," "); strcpy(p.ans3," ");
  638.     fwrite(&p,sizeof(p),1,df);
  639.     }
  640.   else
  641.     {
  642.         printf("Loading data file.\n\n");
  643.     do
  644.       {
  645.       zots=fread(&p,sizeof(p),1,df);
  646.       } while ((zots==1) && (strcmp(name,p.name)!=0));
  647.     }
  648.   fclose(df);
  649.   if (zots==0)
  650.         {
  651.         newperson();
  652.         df=fopen(DATAF,"a");
  653.         fwrite(&p,sizeof(p),1,df);
  654.         fclose(df);
  655.         }
  656.     else printf("Welcome back, %s.\n",name);
  657.     newperson();
  658. }
  659.