home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff216.lzh / Wanderer / src / jump.c < prev    next >
C/C++ Source or Header  |  1989-06-02  |  5KB  |  207 lines

  1. #include "wand_head.h"
  2.  
  3. extern int debug_disp;
  4. extern int no_passwords;
  5. extern int maxscreens;
  6.  
  7. #ifndef DICTIONARY
  8.     /* use this stuff if no dictionary file is defined */
  9.     /* feel free to change the words, but don't change how many there are */
  10.  
  11. char *dictionary[] = {  /* 8 per line, total 128 (16 lines) */
  12. "zero","frog","insanity","hack","stardust","whimpy","lost","rattlesnake",
  13. "panic","crisis","centipede","zaxxon","birdbrain","feeble","juggler","eunuchs",
  14. "unix","amigoid","squirrel","moose","natasha","gyroscope","relax","superstar",
  15. "winner","cheater","liberal","quail","insignificant","oxen","leap","orange",
  16. "troll","zipper","drum","nuke","waste","want","secretword","wyrm",
  17. "english","allegro","treefrog","bullfrog","dump","lunch","donut","lemon",
  18. "helpme","fly","swim","joystick","rambo","leaf","horrible","unknown",
  19. "high","mountain","mispeled","valley","zappa","glass","crunch","sdi",
  20. "squiggly","worms","hint","wanderer","rogue","people","veggie","barf",
  21. "exhausted","raygun","butcher","reebok","gnu","bicycle","fish","boulder",
  22. "repeat","crisis","centipede","birdbrain","lost","rattler","snake","oops",
  23. "squirrel","panic","zero","insanity","whimpy","nifty","crunch","oops",
  24. "paperclip","keynote","keystone","vail","aspen","fall","short","dwarf",
  25. "oboe","bazooka","bassoon","torpedo","risky","bored","cat","music",
  26. "tinker","thunk","liver","onions","tastey","uggh","badnews","whynot",
  27. "because","monster","quest","griffin","gomf","shoe","serpent","tammy"
  28. };
  29. #endif
  30.  
  31. int scrn_passwd(num, passwd)    /* reads password num into passwd */
  32. int num;
  33. char *passwd;
  34. {
  35. #ifdef DICTIONARY
  36.     long position;
  37.     FILE *fp;
  38.  
  39.     position = PASSWD;
  40.     while(position > 200000)
  41.         position -= 200000;
  42.     if((fp = fopen(DICTIONARY,"r")) == NULL)
  43.         return 0;
  44.     fseek(fp,position,ftell(fp));
  45.     while(fgetc(fp) != '\n');
  46.     fscanf(fp,"%s\n",passwd);
  47.     /* read a word into passwd */
  48.     fclose(fp);
  49.     return (1);
  50. #else
  51.     static int firsttime = 1;
  52.     if (firsttime)
  53.     {
  54.         /* first time thru, shuffle the passwords in memory */
  55.         /* this thwarts the disk browsers */
  56.         register int i;
  57.         register char *temp;
  58.  
  59.         firsttime = 0;
  60.         for (i=0; i<64; i+=2)
  61.         {
  62.             temp = dictionary[i];
  63.             dictionary[i] = dictionary[i+64];
  64.             dictionary[i+64] = temp;
  65.         }
  66.         for (i=0; i<123; i+=3)
  67.         {
  68.             temp = dictionary[i];
  69.             dictionary[i] = dictionary[i+2];
  70.             dictionary[i+2] = dictionary[i+1];
  71.             dictionary[i+1] = temp;
  72.         }
  73.     }
  74.     strcpy(passwd, dictionary[num&127]);
  75.     return (1);
  76. #endif
  77. }
  78.  
  79. void showpass(num)
  80. int num;
  81. {
  82. char correct[20];
  83. char buffer[100];
  84. char ch;
  85. int  passline;
  86. if(no_passwords)
  87.     return;
  88. if(!debug_disp)
  89.     passline = 18;
  90. else
  91.     passline = 20;
  92. move(passline,0);
  93.  
  94. if(!scrn_passwd(num,correct))
  95.     return;
  96. (void) sprintf(buffer,"The password to jump to level %d ( using ~ ) is : %s        \n",(num+1),correct);
  97. addstr(buffer);
  98. addstr("PRESS ANY KEY TO REMOVE IT AND CONTINUE                          \n");
  99. refresh();
  100. ch = getch();
  101. move(passline,0);
  102. addstr("                                                                        \n");
  103. addstr("                                              ");
  104. move(passline,0);
  105. refresh();
  106. }
  107.  
  108. int jumpscreen(num)
  109. int num;
  110. {
  111. char word[20],
  112.      buffer[100],
  113.      correct[20];
  114. int index=0;
  115. int  scrn;
  116. int  passline;
  117.  
  118. if (!debug_disp)
  119.     passline = 16;
  120. else
  121.     passline = 18;
  122.  
  123. if(no_passwords == 1) {
  124.     move(passline,0);
  125.     addstr("Enter number of desired level.\n");
  126.     refresh();
  127.     scrn = getnum();
  128.     if(scrn > num) {
  129.         move(passline,0);
  130.         addstr("                                                ");
  131.     return scrn;
  132.     }
  133.     move(passline,0);
  134.     addstr("No way, Jose! Back-jumping is prohibited!");
  135.     refresh();
  136.     return num;
  137.     }
  138.  
  139. move(passline,0);
  140. addstr("Please enter password of screen to jump to:");
  141. refresh();
  142. while(((word[index++] = getch()) != '\n')&&(index < 19))
  143.     {
  144.     addch('*');
  145.     refresh();
  146.     }
  147. word[--index]='\0';
  148. move(passline,0);
  149. addstr("Validating...                                             \n");
  150. refresh();
  151.  
  152. if(strcmp(word,MASTERPASSWORD) == 0)
  153.     {
  154.     move(passline,0);
  155.     addstr("Enter number of desired level.");
  156.     refresh();
  157.     num = getnum();
  158.     (void) scrn_passwd(num-1,correct);
  159.     sprintf(buffer,"Certainly master, but the correct word is %s.       \n",correct);
  160.     move(passline,0);
  161.     addstr(buffer);
  162.     addstr("PRESS ANY KEY TO REMOVE IT AND CONTINUE                          \n");
  163.     refresh();
  164.     getchar();
  165.     move(passline,0);
  166.     addstr("                                                             ");
  167.     move(passline+1,0);
  168.     addstr("                                                             ");
  169.     move(passline,0);
  170.     refresh();
  171.     return num;
  172.     }
  173.  
  174. for(scrn = num;scrn < maxscreens;scrn++) {
  175.     if(!scrn_passwd(scrn,correct))
  176.     break;
  177.     if(strcmp(correct,word) == 0)
  178.         {
  179.         move(passline,0);
  180.         addstr("Password Validated..... Jumping to desired screen.        ");
  181.         refresh();
  182.         return ++scrn;
  183.         }
  184.     }
  185.  
  186. move(passline,0);
  187. addstr("PASSWORD NOT RECOGNISED!  Press any key...  ");
  188. refresh();
  189. getchar();
  190. move(passline,0);
  191. addstr("                                                          ");
  192. refresh();
  193.  
  194. return num;
  195. }
  196.  
  197. int getnum()
  198. {
  199. char ch;
  200. int num = 0;
  201.     for(ch = getch(),addch(ch),refresh(); ch >= '0' && ch <= '9'; ch = getch(),addch(ch),refresh())
  202.     {
  203.     num = num * 10 + ch - '0';
  204.     }
  205.     return num;
  206. }
  207.