home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / TOP / USR / SRC / wanderer2.t.Z / wanderer2.t / jump.c < prev    next >
C/C++ Source or Header  |  1988-10-21  |  4KB  |  193 lines

  1. #include "wand_head.h"
  2.  
  3. extern int debug_disp;
  4. extern int no_passwords;
  5. extern int maxscreens;
  6.  
  7. int scrn_passwd(num, passwd)    /* reads password num into passwd */
  8. int num;
  9. char *passwd;
  10. {
  11.     long position;
  12.     FILE *fp;
  13.  
  14.     position = PASSWD;
  15.     while(position > 200000)
  16.         position -= 200000;
  17.     if((fp = fopen(DICTIONARY,"r")) == NULL)
  18.         return 0;
  19.     fseek(fp,position,ftell(fp));
  20.     while(fgetc(fp) != '\n');
  21.     fscanf(fp,"%s\n",passwd);
  22.     /* read a word into passwd */
  23.     fclose(fp);
  24.     return (1);
  25. }
  26.  
  27. void showpass(num)
  28. int num;
  29. {
  30. long position;
  31. char correct[20];
  32. char buffer[100];
  33. FILE *fp;
  34. char ch;
  35. if(no_passwords)
  36.     return;
  37. if(!debug_disp)
  38.     move(18,0);
  39. else
  40.     move(20,0);
  41. if(!scrn_passwd(num,correct))
  42.     return;
  43. (void) sprintf(buffer,"The password to jump to level %d ( using ~ ) is : %s        \n",(num+1),correct);
  44. addstr(buffer);
  45. addstr("PRESS ANY KEY TO REMOVE IT AND CONTINUE                          \n");
  46. refresh();
  47. ch = getch();
  48. if(!debug_disp)
  49.     move(18,0);
  50. else
  51.     move(20,0);
  52. addstr("                                                                        \n");
  53. addstr("                                              ");
  54. if(!debug_disp)
  55.     move(18,0);
  56. else
  57.     move(20,0);
  58. refresh();
  59. }
  60.  
  61. int jumpscreen(num)
  62. int num;
  63. {
  64. char word[20],
  65.      buffer[100],
  66.      correct[20];
  67. int index=0, input;
  68. char ch;
  69. long position;
  70. int  fp, scrn;
  71.  
  72. if(no_passwords == 1) {
  73.     if(!debug_disp)
  74.         move(16,0);
  75.     else
  76.         move(18,0);
  77.     addstr("Enter number of desired level.\n");
  78.     refresh();
  79.     scrn = getnum();
  80.     if(scrn > num) {
  81.         if(!debug_disp)
  82.             move(16,0);
  83.         else
  84.             move(18,0);
  85.         addstr("                                                ");
  86.     return scrn;
  87.     }
  88.     if(!debug_disp)
  89.         move(16,0);
  90.     else
  91.         move(18,0);
  92.     addstr("No way, Jose! Back-jumping is prohibited!");
  93.     refresh();
  94.     return num;
  95.     }
  96.  
  97. if(!debug_disp)
  98.     move(16,0);
  99. else
  100.     move(18,0);
  101. addstr("Please enter password of screen to jump to:");
  102. refresh();
  103. while(((word[index++] = getch()) != '\n')&&(index < 19))
  104.     {
  105.     addch('*');
  106.     refresh();
  107.     }
  108. word[--index]='\0';
  109. if(!debug_disp)
  110.     move(16,0);
  111. else
  112.     move(18,0);
  113. addstr("Validating...                                             \n");
  114. refresh();
  115.  
  116. if(strcmp(word,MASTERPASSWORD) == 0)
  117.     {
  118.     if(!debug_disp)
  119.         move(16,0);
  120.     else
  121.         move(18,0);
  122.     addstr("Enter number of desired level.");
  123.     refresh();
  124.     num = getnum();
  125.     (void) scrn_passwd(num-1,correct);
  126.     sprintf(buffer,"Certainly master, but the correct word is %s.       \n",correct);
  127.     if(!debug_disp)
  128.         move(16,0);
  129.     else
  130.         move(18,0);
  131.     addstr(buffer);
  132.     addstr("PRESS ANY KEY TO REMOVE IT AND CONTINUE                          \n");
  133.     refresh();
  134.     getchar();
  135.     if(!debug_disp)
  136.         move(16,0);
  137.     else
  138.         move(18,0);
  139.     addstr("                                                             ");
  140.     if(!debug_disp)
  141.         move(17,0);
  142.     else
  143.         move(19,0);
  144.     addstr("                                                             ");
  145.     if(!debug_disp)
  146.         move(16,0);
  147.     else
  148.      move(18,0);
  149.     refresh();
  150.     return num;
  151.     }
  152.  
  153. for(scrn = num;scrn < maxscreens;scrn++) {
  154.     if(!scrn_passwd(scrn,correct))
  155.     break;
  156.     if(strcmp(correct,word) == 0)
  157.         {
  158.         if(!debug_disp)
  159.             move(16,0);
  160.         else
  161.             move(18,0);
  162.         addstr("Password Validated..... Jumping to desired screen.        ");
  163.         refresh();
  164.         return ++scrn;
  165.         }
  166.     }
  167.  
  168. if(!debug_disp)
  169.     move(16,0);
  170. else
  171.     move(18,0);
  172.         addstr("PASSWORD NOT RECOGNISED!                    ");
  173. refresh();
  174. if(!debug_disp)
  175.     move(16,0);
  176. else
  177.     move(18,0);
  178. addstr("                                                          ");
  179.  
  180. return num;
  181. }
  182.  
  183. int getnum()
  184. {
  185. char ch;
  186. int num = 0;
  187.     for(ch = getch(),addch(ch),refresh(); ch >= '0' && ch <= '9'; ch = getch(),addch(ch),refresh())
  188.     {
  189.     num = num * 10 + ch - '0';
  190.     }
  191.     return num;
  192. }
  193.