home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / games / vmsnet / mineswp2 / part01 < prev    next >
Encoding:
Text File  |  1992-08-01  |  54.7 KB  |  2,617 lines

  1. Newsgroups: vmsnet.sources.games
  2. Path: uunet!cs.utexas.edu!torn!cunews!nrcnet0!cu23.crl.aecl.ca!wl.aecl.ca!jeremiahw
  3. From: jeremiahw@wl.aecl.ca
  4. Subject: Minesweeper Version 2.0 for VMS by TAB and JJ
  5. Message-ID: <2AUG92.22263234@wl.aecl.ca>
  6. Sender: news@cu23.crl.aecl.ca (USENET News System)
  7. Nntp-Posting-Host: wc4.wl.aecl.ca
  8. Organization: AECL RESEARCH
  9. Date: Mon, 3 Aug 1992 04:26:32 GMT
  10. Lines: 2605
  11.  
  12. /*****************************************************************************/
  13. /*                                         */
  14. /*    Troy Baker & Jerry Jeremiah    MineSweeper Version 2.0 for VAX         */
  15. /*                                         */
  16. /*    Help will be given to anyone whose name is not in the high score.    */
  17. /*                                         */
  18. /*    This is version 2.0 of our minesweeper program.  Although we have    */
  19. /*    done extensive testing and we are not aware of any errors, if any    */
  20. /*    are found, bug reports may be made to jeremi@bode.ee.ualberta.ca     */
  21. /*                                         */
  22. /*    If you do not want multiple versions of the high score file, you     */
  23. /*    may execute the following command after the game has been run once:  */
  24. /*                                         */
  25. /*            set file/version=1 highscore.ms                 */
  26. /*                                         */
  27. /*****************************************************************************/
  28.  
  29. /*
  30. The main problem with this program being portable is that several VAX-only
  31. system services had to be used:
  32.  
  33. On a machine that does not buffer input,  getchar could have been used.
  34. As it was we used a larger segment of code.
  35.  
  36. On another machine, the time will have to be called differently.  But it must
  37. come back integer.
  38.  
  39. On another machine, the terminal size will have to be called differently.
  40.  
  41. There is a function used that gets the user id for the purposes of the
  42. high score identification.  It will have to be redone for another platform.
  43.  
  44. The escape sequenses may not work for anything but a VAX.
  45. */
  46.  
  47. #include stdio
  48. #include string
  49. #include jpidef
  50. #include descrip
  51. #include libdtdef
  52. #include ssdef
  53. #include iodef
  54. #include rmsdef
  55.  
  56. #define NORMAL    "\033[0m"
  57. #define BOLD      "\033[1m"
  58. #define UNDERLINE "\033[4m"
  59. #define FLASH     "\033[5m"
  60. #define REVERSE   "\033[7m"
  61.  
  62. typedef
  63.     struct entry 
  64.         {
  65.         int x;
  66.         int y;
  67.         struct entry *next;
  68.         }
  69.     STACK;
  70.  
  71. typedef
  72.     struct element 
  73.         {
  74.         int cover;    /*This tells if it is selected or flagged*/
  75.         int board;    /*This is the mines and numbers*/
  76.         int stack;    /*This tells if it is on the stack*/
  77.         }
  78.     TABLE;
  79.  
  80. TABLE    *game1,**game;            /*These will be our array*/
  81. STACK    *bottom,*top;            /*These are our stack pointers*/
  82. int     quit_flag;            
  83. int    mine_total=0;            /*This is the real number of mines*/
  84. int    XSIZE,YSIZE,MINES,DEBUG=0;    /*These are the command line params*/ 
  85. int    slength,swidth;            /*This is the game size*/
  86. int    length,width;            /*This is the terminal size*/
  87. int    hint=0,HINTS=3;
  88. int    view_flag;
  89. int    real_flag_counter=0,flag_counter=0,counter=0;
  90.                     /*These are our win tracking counters*/
  91.  
  92. /*This uses DEC escape sequences to clear the screen.*/
  93.  
  94. clear()
  95. {
  96. printf("\033[0m\033[2J\033[1;1H");
  97. }
  98.  
  99. /*This uses DEC escape sequences to locate the cursor.*/
  100.  
  101. locate(x,y)
  102. int    x,y;
  103. {
  104. printf("\033[%d;%dH",y+2,x+2);
  105. }
  106.  
  107. /*This uses DEC escape sequences to make big characters.*/
  108.  
  109. big(str)
  110. char str[]; 
  111. {
  112. clear();
  113. locate(0,YSIZE);        
  114. printf("\033#3%s\n",str);
  115. locate(0,YSIZE+1);
  116. printf("\033#4%s",str);
  117. exit(0);
  118. }
  119.  
  120. /*This uses DEC escape sequences to turn off all other DEC escape sequences.*/
  121.  
  122. normal()
  123. {
  124. printf(NORMAL);
  125. }                                         
  126.  
  127. /*This uses DEC escape sequences to bold the characters printed after this.*/
  128.  
  129. bold()
  130. {
  131. printf(BOLD);
  132. }
  133.  
  134. /*This uses DEC escape sequences to flash the characters printed after this.*/
  135.  
  136. flash()
  137. {
  138. printf(FLASH);
  139. }
  140.  
  141. /*This uses DEC escape sequences to reverse the characters printed after this.*/
  142.  
  143. reverse()
  144. {
  145. printf(REVERSE);
  146. }
  147.  
  148. /*This uses DEC escape sequences to underline the chars printed after this.*/
  149.  
  150. underline()
  151. {
  152. printf(UNDERLINE);
  153. }
  154.  
  155. /*This pushes a location on the stack.*/
  156.  
  157. push(x,y)
  158. int    x,y;
  159. {
  160. STACK    *piece;
  161.  
  162. game[x][y].stack = 1;
  163. piece = (STACK *) malloc( sizeof(STACK) );
  164. piece->x    = x;
  165. piece->y    = y;
  166. piece->next    = top;
  167. top        = piece;
  168. }
  169.  
  170. /*This routine is accessed when there is a stack error (Never hopefully)
  171.   It lists the contents of the stack.*/
  172.  
  173. links()
  174. {
  175. STACK *piece;
  176.  
  177. piece = top;
  178. if (atbottom(piece)!=1)
  179.     {
  180.     locate (0,YSIZE);
  181.     printf (">");
  182.     }
  183. while (atbottom(piece)!=1)
  184.     {
  185.     printf ("%d,%d ",piece->x,piece->y);
  186.     piece = piece->next;
  187.     }
  188. if (atbottom(piece)!=1)
  189.     {
  190.     printf ("\n");
  191.     }
  192. }
  193.  
  194. /*Takes the top stack piece and frees the memory.*/
  195.  
  196. pop(x,y)
  197. int    *x,*y;
  198. {
  199. STACK    *piece;
  200.  
  201. piece    = top;
  202. if (isempty()!=1)
  203.     {
  204.     *x    = piece->x;
  205.     *y    = piece->y;
  206.     top    = piece->next;
  207.     free (piece);
  208.     game[*x][*y].stack = 0;
  209.     }
  210. else
  211.     {
  212.     links();
  213.     printf("Stack Error!");
  214.     exit(1);
  215.     }
  216. }
  217.  
  218. /*Logical routine returns true if the pointer is at the bottom of the stack.*/
  219.  
  220. atbottom(ptr)
  221. STACK    *ptr;
  222. {
  223. if (ptr == bottom) return (1);
  224. }
  225.  
  226. /*Logical routine returns true if the stack is empty.*/
  227.  
  228. isempty()
  229. {
  230. if (top == bottom) return (1);
  231. }
  232.  
  233. /*Creates the stack by initializing the pointers*/
  234.  
  235. create()
  236. {
  237. top = NULL;
  238. bottom = NULL;
  239. }
  240.  
  241. /*Pops the stack top, displays it, and pushes the neighbours on the stack if
  242.   what it popped off was a zero.  Continues until the stack is empty.  Is
  243.   basically a flood fill routine.*/
  244.  
  245. expose(x,y)
  246. int    x,y;
  247. {
  248.  
  249. if (game[x][y].cover != 'X') counter++;
  250. locate(x,y);
  251. game[x][y].cover = 'X';
  252. if (game[x][y].board != 0)
  253.     {
  254.     if (view_flag == 0)
  255.         {
  256.         bold();
  257.         view_flag = 1;
  258.         }
  259.     else    if (view_flag != 1)
  260.         {
  261.         normal();
  262.         bold();
  263.         view_flag = 1;
  264.         }
  265.     printf ("%d",game[x][y].board);
  266.     }
  267. else
  268.     {
  269.     if (view_flag != 0)
  270.         {
  271.         normal();
  272.         view_flag = 0;
  273.         }
  274.     printf(" ");
  275.     }
  276.  
  277. if (game[x][y].board == 0)
  278.     {
  279.     if (x==0 && y==0)
  280.         {
  281.         if (game[x+1][y].cover==' '    &&
  282.             game[x+1][y].stack==0    )       push(x+1,y);
  283.         if (game[x][y+1].cover==' '    &&
  284.             game[x][y+1].stack==0    )    push(x,y+1);
  285.         if (game[x+1][y+1].cover==' '    &&
  286.             game[x+1][y+1].stack==0    )    push(x+1,y+1);
  287.         }
  288.     if (x>0 && x<XSIZE-1 && y==0)
  289.         {
  290.         if (game[x-1][y].cover==' '    &&
  291.             game[x-1][y].stack==0    )    push(x-1,y);
  292.         if (game[x+1][y].cover==' '    &&
  293.             game[x+1][y].stack==0    )    push(x+1,y);
  294.         if (game[x-1][y+1].cover==' '    &&
  295.             game[x-1][y+1].stack==0    )    push(x-1,y+1);
  296.         if (game[x][y+1].cover==' '    &&
  297.             game[x][y+1].stack==0    )    push(x,y+1);
  298.         if (game[x+1][y+1].cover==' '    &&
  299.             game[x+1][y+1].stack==0    )    push(x+1,y+1);
  300.         }
  301.     if (x==XSIZE-1 && y==0)
  302.         {
  303.         if (game[x-1][y].cover==' '    &&
  304.             game[x-1][y].stack==0    )    push(x-1,y);
  305.         if (game[x-1][y+1].cover==' '    &&
  306.             game[x-1][y+1].stack==0    )    push(x-1,y+1);
  307.         if (game[x][y+1].cover==' '    &&
  308.             game[x][y+1].stack==0    )    push(x,y+1);
  309.         }
  310.     if (x==0 && y>0 && y<YSIZE-1)
  311.         {
  312.         if (game[x][y-1].cover==' '    &&
  313.             game[x][y-1].stack==0    )    push(x,y-1);
  314.         if (game[x+1][y-1].cover==' '    &&
  315.             game[x+1][y-1].stack==0    )    push(x+1,y-1);
  316.         if (game[x+1][y].cover==' '    &&
  317.             game[x+1][y].stack==0    )    push(x+1,y);
  318.         if (game[x][y+1].cover==' '    &&
  319.             game[x][y+1].stack==0    )    push(x,y+1);
  320.         if (game[x+1][y+1].cover==' '    &&
  321.             game[x+1][y+1].stack==0    )    push(x+1,y+1);
  322.         }
  323.     if (x>0 && x<XSIZE-1 && y>0 && y<YSIZE-1)
  324.         {
  325.         if (game[x-1][y-1].cover==' '    &&
  326.             game[x-1][y-1].stack==0    )    push(x-1,y-1);
  327.         if (game[x][y-1].cover==' '    &&
  328.             game[x][y-1].stack==0    )    push(x,y-1);
  329.         if (game[x+1][y-1].cover==' '    &&
  330.             game[x+1][y-1].stack==0    )    push(x+1,y-1);
  331.         if (game[x-1][y].cover==' '    &&
  332.             game[x-1][y].stack==0    )    push(x-1,y);
  333.         if (game[x+1][y].cover==' '    &&
  334.             game[x+1][y].stack==0    )    push(x+1,y);
  335.         if (game[x-1][y+1].cover==' '    &&
  336.             game[x-1][y+1].stack==0    )    push(x-1,y+1);
  337.         if (game[x][y+1].cover==' '    &&
  338.             game[x][y+1].stack==0    )    push(x,y+1);
  339.         if (game[x+1][y+1].cover==' '    &&
  340.             game[x+1][y+1].stack==0    )    push(x+1,y+1);
  341.         }
  342.     if (x==XSIZE-1 && y>0 && y<YSIZE-1)
  343.         {
  344.         if (game[x-1][y-1].cover==' '    &&
  345.             game[x-1][y-1].stack==0    )    push(x-1,y-1);
  346.         if (game[x][y-1].cover==' '    &&
  347.             game[x][y-1].stack==0    )    push(x,y-1);
  348.         if (game[x-1][y].cover==' '    &&
  349.             game[x-1][y].stack==0    )    push(x-1,y);
  350.         if (game[x-1][y+1].cover==' '    &&
  351.             game[x-1][y+1].stack==0    )    push(x-1,y+1);
  352.         if (game[x][y+1].cover==' '    &&
  353.             game[x][y+1].stack==0    )    push(x,y+1);
  354.         }
  355.     if (x==0 && y==YSIZE-1)
  356.         {
  357.         if (game[x][y-1].cover==' '    &&
  358.             game[x][y-1].stack==0    )    push(x,y-1);
  359.         if (game[x+1][y-1].cover==' '    &&
  360.             game[x+1][y-1].stack==0    )    push(x+1,y-1);
  361.         if (game[x+1][y].cover==' '    &&
  362.             game[x+1][y].stack==0    )    push(x+1,y);
  363.         }
  364.     if (x>0 && x<XSIZE-1 && y==YSIZE-1)
  365.         {
  366.         if (game[x-1][y-1].cover==' '    &&
  367.             game[x-1][y-1].stack==0    )    push(x-1,y-1);
  368.         if (game[x][y-1].cover==' '    &&
  369.             game[x][y-1].stack==0    )    push(x,y-1);
  370.         if (game[x+1][y-1].cover==' '    &&
  371.             game[x+1][y-1].stack==0    )    push(x+1,y-1);
  372.         if (game[x-1][y].cover==' '    &&
  373.             game[x-1][y].stack==0    )    push(x-1,y);
  374.         if (game[x+1][y].cover==' '    &&
  375.             game[x+1][y].stack==0    )    push(x+1,y);
  376.         }
  377.     if (x==XSIZE-1 && y==YSIZE-1)
  378.         {
  379.         if (game[x-1][y-1].cover==' '    &&
  380.             game[x-1][y-1].stack==0    )    push(x-1,y-1);
  381.         if (game[x][y-1].cover==' '    &&
  382.             game[x][y-1].stack==0    )    push(x,y-1);
  383.         if (game[x-1][y].cover==' '    &&
  384.             game[x-1][y].stack==0    )    push(x-1,y);
  385.         }
  386.     while (isempty()!=1)
  387.         {
  388.         pop(&x,&y);
  389.  
  390.         if (game[x][y].cover != 'X') counter++;
  391.         locate(x,y);
  392.         game[x][y].cover = 'X';
  393.         if (game[x][y].board != 0)
  394.             {
  395.             if (view_flag == 0)
  396.                 {
  397.                 bold();
  398.                 view_flag = 1;
  399.                 }
  400.             else    if (view_flag != 1)
  401.                 {
  402.                 normal();
  403.                 bold();
  404.                 view_flag = 1;
  405.                 }
  406.             printf ("%d",game[x][y].board);
  407.             }
  408.         else
  409.             {
  410.             if (view_flag != 0)
  411.                 {
  412.                 normal();
  413.                 view_flag = 0;
  414.                 }
  415.             printf(" ");
  416.             }
  417.  
  418.         if (game[x][y].board == 0)
  419.             {
  420.             if (x==0 && y==0)
  421.                 {
  422.                 if (game[x+1][y].cover==' '    &&
  423.                     game[x+1][y].stack==0    ) push(x+1,y);
  424.                 if (game[x][y+1].cover==' '    &&
  425.                     game[x][y+1].stack==0    ) push(x,y+1);
  426.                 if (game[x+1][y+1].cover==' '    &&
  427.                     game[x+1][y+1].stack==0    ) push(x+1,y+1);
  428.                 }
  429.             if (x>0 && x<XSIZE-1 && y==0)
  430.                 {
  431.                 if (game[x-1][y].cover==' '    &&
  432.                     game[x-1][y].stack==0    ) push(x-1,y);
  433.                 if (game[x+1][y].cover==' '    &&
  434.                     game[x+1][y].stack==0    ) push(x+1,y);
  435.                 if (game[x-1][y+1].cover==' '    &&
  436.                     game[x-1][y+1].stack==0    ) push(x-1,y+1);
  437.                 if (game[x][y+1].cover==' '    &&
  438.                     game[x][y+1].stack==0    ) push(x,y+1);
  439.                 if (game[x+1][y+1].cover==' '    &&
  440.                     game[x+1][y+1].stack==0    ) push(x+1,y+1);
  441.                 }
  442.             if (x==XSIZE-1 && y==0)
  443.                 {
  444.                 if (game[x-1][y].cover==' '    &&
  445.                     game[x-1][y].stack==0    ) push(x-1,y);
  446.                 if (game[x-1][y+1].cover==' '    &&
  447.                     game[x-1][y+1].stack==0    ) push(x-1,y+1);
  448.                 if (game[x][y+1].cover==' '    &&
  449.                     game[x][y+1].stack==0    ) push(x,y+1);
  450.                 }
  451.             if (x==0 && y>0 && y<YSIZE-1)
  452.                 {
  453.                 if (game[x][y-1].cover==' '    &&
  454.                     game[x][y-1].stack==0    ) push(x,y-1);
  455.                 if (game[x+1][y-1].cover==' '    &&
  456.                     game[x+1][y-1].stack==0    ) push(x+1,y-1);
  457.                 if (game[x+1][y].cover==' '    &&
  458.                     game[x+1][y].stack==0    ) push(x+1,y);
  459.                 if (game[x][y+1].cover==' '    &&
  460.                     game[x][y+1].stack==0    ) push(x,y+1);
  461.                 if (game[x+1][y+1].cover==' '    &&
  462.                     game[x+1][y+1].stack==0    ) push(x+1,y+1);
  463.                 }
  464.             if (x>0 && x<XSIZE-1 && y>0 && y<YSIZE-1)
  465.                 {
  466.                 if (game[x-1][y-1].cover==' '    &&
  467.                     game[x-1][y-1].stack==0    ) push(x-1,y-1);
  468.                 if (game[x][y-1].cover==' '    &&
  469.                     game[x][y-1].stack==0    ) push(x,y-1);
  470.                 if (game[x+1][y-1].cover==' '    &&
  471.                     game[x+1][y-1].stack==0    ) push(x+1,y-1);
  472.                 if (game[x-1][y].cover==' '    &&
  473.                     game[x-1][y].stack==0    ) push(x-1,y);
  474.                 if (game[x+1][y].cover==' '    &&
  475.                     game[x+1][y].stack==0    ) push(x+1,y);
  476.                 if (game[x-1][y+1].cover==' '    &&
  477.                     game[x-1][y+1].stack==0    ) push(x-1,y+1);
  478.                 if (game[x][y+1].cover==' '    &&
  479.                     game[x][y+1].stack==0    ) push(x,y+1);
  480.                 if (game[x+1][y+1].cover==' '    &&
  481.                     game[x+1][y+1].stack==0    ) push(x+1,y+1);
  482.                 }
  483.             if (x==XSIZE-1 && y>0 && y<YSIZE-1)
  484.                 {
  485.                 if (game[x-1][y-1].cover==' '    &&
  486.                     game[x-1][y-1].stack==0    ) push(x-1,y-1);
  487.                 if (game[x][y-1].cover==' '    &&
  488.                     game[x][y-1].stack==0    ) push(x,y-1);
  489.                 if (game[x-1][y].cover==' '    &&
  490.                     game[x-1][y].stack==0    ) push(x-1,y);
  491.                 if (game[x-1][y+1].cover==' '    &&
  492.                     game[x-1][y+1].stack==0    ) push(x-1,y+1);
  493.                 if (game[x][y+1].cover==' '    &&
  494.                     game[x][y+1].stack==0    ) push(x,y+1);
  495.                 }
  496.             if (x==0 && y==YSIZE-1)
  497.                 {
  498.                 if (game[x][y-1].cover==' '    &&
  499.                     game[x][y-1].stack==0    ) push(x,y-1);
  500.                 if (game[x+1][y-1].cover==' '    &&
  501.                     game[x+1][y-1].stack==0    ) push(x+1,y-1);
  502.                 if (game[x+1][y].cover==' '    &&
  503.                     game[x+1][y].stack==0    ) push(x+1,y);
  504.                 }
  505.             if (x>0 && x<XSIZE-1 && y==YSIZE-1)
  506.                 {
  507.                 if (game[x-1][y-1].cover==' '    &&
  508.                     game[x-1][y-1].stack==0    ) push(x-1,y-1);
  509.                 if (game[x][y-1].cover==' '    &&
  510.                     game[x][y-1].stack==0    ) push(x,y-1);
  511.                 if (game[x+1][y-1].cover==' '    &&
  512.                     game[x+1][y-1].stack==0    ) push(x+1,y-1);
  513.                 if (game[x-1][y].cover==' '    &&
  514.                     game[x-1][y].stack==0    ) push(x-1,y);
  515.                 if (game[x+1][y].cover==' '    &&
  516.                     game[x+1][y].stack==0    ) push(x+1,y);
  517.                 }
  518.             if (x==XSIZE-1 && y==YSIZE-1)
  519.                 {
  520.                 if (game[x-1][y-1].cover==' '    &&
  521.                     game[x-1][y-1].stack==0    ) push(x-1,y-1);
  522.                 if (game[x][y-1].cover==' '    &&
  523.                     game[x][y-1].stack==0    ) push(x,y-1);
  524.                 if (game[x-1][y].cover==' '    &&
  525.                     game[x-1][y].stack==0    ) push(x-1,y);
  526.                 }
  527.         
  528.             }
  529.         }
  530.     }
  531. }
  532.         
  533. /*Run when a square is flagged (the user believes it to be a mine).*/
  534.  
  535. flag(x,y)
  536. int    x,y;
  537. {
  538.  
  539. if (game[x][y].cover != 'X')
  540.     {
  541.     locate(x,y);
  542.     game[x][y].cover = 'F';
  543.     if (view_flag == 0)
  544.         {
  545.         reverse();
  546.         view_flag = 2;
  547.         }
  548.     else    if (view_flag != 2)
  549.         {
  550.         normal();
  551.         reverse();
  552.         view_flag = 2;
  553.         }
  554.     printf ("F");
  555.     if (game[x][y].board==9) real_flag_counter++; 
  556.     flag_counter++;
  557.  
  558.     locate(72,length);
  559.     if (view_flag != 0)
  560.         {
  561.         normal();
  562.         view_flag = 0;
  563.         }
  564.     printf("%4d",mine_total-flag_counter);
  565.     }
  566. }
  567.  
  568. /*Run when a square is unflagged (the user has changed his/her mind).*/
  569.  
  570. unflag(x,y)
  571. int    x,y;
  572. {
  573.  
  574. locate(x,y);
  575. game[x][y].cover = ' ';
  576. if (view_flag != 0)
  577.     {
  578.     normal();
  579.     view_flag = 0;
  580.     }
  581. printf ("+");
  582. if (game[x][y].board==9) real_flag_counter--; 
  583. flag_counter--;
  584.  
  585. locate(72,length);
  586. if (view_flag != 0)
  587.     {
  588.     normal();
  589.     view_flag = 0;
  590.     }
  591. printf("%4d",mine_total-flag_counter);
  592. }
  593.  
  594. /*Create an empty highscore file in the current directory*/
  595.  
  596. highscorefile()
  597. {
  598. char    name[150];
  599. int    context;
  600. int    i;
  601. FILE    *fileptr;
  602.  
  603. context=0;
  604. find_file("highscore.ms",name,&context);
  605. if (context == 0)
  606.     {
  607.     fileptr=fopen("highscore.ms","w");
  608.     fprintf(fileptr,"0\n");
  609.     fprintf(fileptr,"0\n");
  610.     fclose(fileptr);
  611.     }
  612. }
  613.  
  614. /*
  615.  * For a given file specification (spec) returns one file matching this
  616.  * specification upon each call in the order they appear in the directory.
  617.  * If (context) is equal to zero before the call, the file search will
  618.  * start from the beginning.  If context returns a value of zero, no more
  619.  * files were found.
  620.  */
  621.  
  622. find_file(spec,name,context)
  623.     char *spec;
  624.     char *name;
  625.     int *context;
  626.     {
  627.     int status;
  628.     char *c_ptr;
  629.     struct dsc$descriptor file_spec = {
  630.         149,
  631.         DSC$K_DTYPE_T,
  632.         DSC$K_CLASS_S,
  633.         spec };
  634.     struct dsc$descriptor file_name = {
  635.         149,
  636.         DSC$K_DTYPE_T,
  637.         DSC$K_CLASS_S,
  638.         name };
  639.  
  640.     file_spec.dsc$w_length=strlen(spec);
  641.     status=lib$find_file(&file_spec,&file_name,context);
  642.     if(status!=RMS$_NORMAL) *context=0;
  643.     name[file_name.dsc$w_length]='\0';
  644.     c_ptr=strchr(name,' ');
  645.     *c_ptr='\0';
  646.     }
  647.  
  648. /*
  649. gets a string (replacing scanf) returning when a return is pressed
  650. no matter whether is has only whitespace or what.  The flag allows
  651. or disallows spaces and certain control chars used elsewhere to create
  652. bold, reverse, flashing, or underlined text.
  653. */
  654.  
  655. getstring(char str[],int amount,int type)
  656. {
  657. int    i=0,chflag=0,loop,maxi=0;
  658.  
  659. /*The following is needed for the DEC system service that gets a key.  Will
  660.   have to be modified to work on non-VAX equipment*/
  661.  
  662. /*===================================*/
  663. char    keyname[20];
  664. int    keyid,key;
  665. struct    dsc$descriptor name = {
  666.     19,
  667.     DSC$K_DTYPE_T,
  668.     DSC$K_CLASS_S,
  669.     keyname };
  670.  
  671. SMG$CREATE_VIRTUAL_KEYBOARD(&keyid);
  672. /*===================================*/
  673.  
  674. i=0;maxi=0;
  675. for (loop=0;loop<amount;loop++)
  676.     str[loop]='\0';
  677. str[strlen(str)]='\0';
  678.  
  679. /*The following is needed for the DEC system service that gets a key.  Will
  680.   have to be modified to work on non-VAX equipment*/
  681.  
  682. /*===================================*/
  683.     SMG$READ_KEYSTROKE(&keyid,&key);
  684.     SMG$KEYCODE_TO_NAME(&key,&name);
  685.     keyname[strlen(keyname)-strlen(strchr(keyname,' '))] = '\0';
  686.     if (strcmp(keyname,"")==0) strcpy(keyname," ");
  687. /*===================================*/
  688.  
  689. while (strcmp(keyname,"CTRLM")!=0)
  690.     {
  691.  
  692.     if (    strcmp(keyname,"LEFT") == 0)
  693.         {
  694.         if (i>0)
  695.             {
  696.             i--;
  697.             printf("\033[D");
  698.             }
  699.         chflag=1;
  700.         }
  701.  
  702.     if (    strcmp(keyname,"RIGHT") == 0)
  703.         {
  704.         if (i<maxi)
  705.             {
  706.             i++;
  707.             printf("\033[C");
  708.             }
  709.         chflag=1;
  710.         }
  711.  
  712.     if (    keyname[0] == 127)
  713.         {
  714.         if (i>0)
  715.             {
  716.             i--;
  717.             printf("\033[D");
  718.  
  719.             for (loop=i;loop<maxi;loop++)
  720.                 {
  721.                 str[loop]=str[loop+1];
  722.             if (    str[loop] == '\002')
  723.                 {
  724.                 reverse();
  725.                 printf("B");
  726.                 normal();
  727.                 }
  728.             else    
  729.                 {if (    str[loop] == '\006')
  730.                     {
  731.                     reverse();
  732.                     printf("F");
  733.                     normal();
  734.                     }
  735.             else    
  736.                 {if (    str[loop] == '\016')
  737.                     {
  738.                     reverse();
  739.                     printf("N");
  740.                     normal();
  741.                     }
  742.             else    
  743.                 {if (    str[loop] == '\022')
  744.                     {
  745.                     reverse();
  746.                     printf("R");
  747.                     normal();
  748.                     }
  749.             else
  750.                 {if (    str[loop] == '\025')
  751.                     {
  752.                     reverse();
  753.                     printf("U");
  754.                     normal();
  755.                     }
  756.             else    
  757.                 {if (    str[loop] == '\001')
  758.                     {
  759.                     reverse();
  760.                     printf(" ");
  761.                     normal();
  762.                     }
  763.             else    printf("%c",str[loop]);
  764.                 }}}}}}
  765.             
  766.             str[maxi]='\0';
  767.             printf(" ");
  768.  
  769.             for (loop=maxi;loop>i;loop--)
  770.                 printf("\033[D");
  771.  
  772.             maxi--;
  773.             }
  774.         chflag=1;
  775.         }
  776.  
  777.     if (    strcmp(keyname,"CTRLE") == 0)
  778.         {
  779.         if (i<maxi)
  780.             {
  781.             for (loop=i;loop<maxi;loop++)
  782.                 printf("\033[C");
  783.             i=maxi;
  784.             }
  785.         chflag=1;
  786.         }
  787.  
  788.     if (    strcmp(keyname,"CTRLH") == 0)
  789.         {
  790.         if (i>0)
  791.             {
  792.             for (loop=i;loop>0;loop--)
  793.                 printf("\033[D");
  794.             i=0;
  795.             }
  796.         chflag=1;
  797.         }
  798.  
  799.     if (    strcmp(keyname,"CTRLB") == 0    &&    type == 0)
  800.         {
  801.         str[i++]='\002';
  802.         reverse();
  803.         printf("B");
  804.         normal();
  805.         chflag=1;
  806.         }
  807.     if (    strcmp(keyname,"CTRLF") == 0    &&    type == 0)
  808.         {
  809.         str[i++]='\006';
  810.         reverse();
  811.         printf("F");
  812.         normal();
  813.         chflag=1;
  814.         }
  815.     if (    strcmp(keyname,"CTRLN") == 0    &&    type == 0)
  816.         {
  817.         str[i++]='\016';
  818.         reverse();
  819.         printf("N");
  820.         normal();
  821.         chflag=1;
  822.         }
  823.     if (    strcmp(keyname,"CTRLR") == 0    &&    type == 0)
  824.         {
  825.         str[i++]='\022';
  826.         reverse();
  827.         printf("R");
  828.         normal();
  829.         chflag=1;
  830.         }
  831.     if (    strcmp(keyname,"CTRLU") == 0    &&    type == 0)
  832.         {
  833.         str[i++]='\025';
  834.         reverse();
  835.         printf("U");
  836.         normal();
  837.         chflag=1;
  838.         }
  839.     if (    strcmp(keyname," ") == 0)
  840.         {
  841.         if (type == 0)
  842.             str[i++]='\001';
  843.         else
  844.             {
  845.             if (type == 1)
  846.                 str[i++]='_';
  847.             else
  848.                 str[i++]=' ';
  849.             }
  850.         printf(" ");
  851.         chflag=1;
  852.         }
  853.  
  854.     if (chflag==1)
  855.         chflag=0;
  856.     else
  857.         {
  858.         for (loop=0;loop<strlen(keyname);loop++)
  859.             {
  860.             if (i<amount)
  861.                 {
  862.                 str[i++]=keyname[loop];
  863.                 printf("%c",keyname[loop]);
  864.                 }
  865.             }
  866.         chflag=0;
  867.         }
  868.  
  869.     if (i>maxi) maxi=i;
  870.  
  871. /*The following is needed for the DEC system service that gets a key.  Will
  872.   have to be modified to work on non-VAX equipment*/
  873.  
  874. /*===================================*/
  875.     SMG$READ_KEYSTROKE(&keyid,&key);
  876.     SMG$KEYCODE_TO_NAME(&key,&name);
  877.     keyname[strlen(keyname)-strlen(strchr(keyname,' '))] = '\0';
  878.     if (strcmp(keyname,"")==0) strcpy(keyname," ");
  879. /*===================================*/
  880.     }
  881. }
  882.  
  883. /*this adds to and from the highscore file and also displays it*/
  884.  
  885. high (int flag)
  886. {
  887.  
  888. typedef
  889.     struct    HIGHSCORE    {
  890.                  char            name[60];
  891.                  char            username[60];
  892.                 int            score;
  893.                 int            games;
  894.                 struct    HIGHSCORE    *next;
  895.                 }
  896.     HISCORE;
  897.  
  898. HISCORE    *hiscore,*deadscore,*list,*track,*temp,*current;
  899.  
  900. char    name[60],username[60],dumstr[60];
  901. int    score,games,dumint,chflag=0,
  902.     entry,i,count,add_entry,
  903.     entry_num,deadentry_num;
  904. FILE    *fileptr;
  905.  
  906. /*The following is needed for the DEC system service that gets a username.  Will
  907.   have to be modified to work on non-VAX equipment*/
  908.  
  909. /*===================================*/
  910. struct    dsc$descriptor u_name = {
  911.     19,
  912.     DSC$K_DTYPE_T,
  913.     DSC$K_CLASS_S,
  914.     name };
  915. struct    dsc$descriptor user_name = {
  916.     19,
  917.     DSC$K_DTYPE_T,
  918.     DSC$K_CLASS_S,
  919.     username };
  920. /*===================================*/
  921.  
  922. clear();
  923.  
  924. /* (flag==3) is a test for whether the username is in the highscore file*/
  925. /* (flag==2) shows the highscore file*/
  926. /* (flag==1) is if you win*/
  927. /* (flag==0) is if you lose*/
  928.  
  929. if (flag!=3)
  930.     {
  931.     score    =
  932.     ( ( real_flag_counter + counter )
  933.     * ( mine_total%( XSIZE * YSIZE - 4 ) )
  934.     / ( XSIZE * YSIZE * 147 / 10000 * 10 + 10 )
  935.     / ( hint + 1 )
  936.     + 1 )
  937.     * (-2 * quit_flag + 1);
  938.     }
  939.     games = 1;
  940.  
  941. if (flag==2)
  942.     printf("You have %d points!!!\n",score * (-2 * quit_flag + 1));
  943. if (flag==1)
  944.     printf("You won with %d points!!!\n\n",score);
  945. if (flag==0)
  946.     {
  947.     if (quit_flag==1)
  948.         printf("You quit after accumulating %d points!!!\n\n",
  949.             score * (-2 * quit_flag + 1));
  950.     else
  951.         printf("You died after accumulating %d points!!!\n\n",score);
  952.     }
  953.  
  954. if (score==0) flag=2;
  955.  
  956. /*The following is needed for the DEC system service that gets a username.  Will
  957.   have to be modified to work on non-VAX equipment*/
  958.  
  959. /*===================================*/
  960.     lib$getjpi(&(JPI$_USERNAME),0,0,0,&user_name,0);
  961.     username[strlen(username)-strlen(strchr(username,' '))] = '\0';
  962. /*===================================*/
  963.  
  964. if (flag!=2 && flag!=3)
  965.     {
  966.     printf("Enter a name for the high score file: ");
  967.     getstring(name,40,0);
  968.     printf("\n");
  969.  
  970.     if (strlen(name)==0)
  971.         {
  972. /*Another system service used to replace a blank string with the username*/
  973. /*The following is needed for the DEC system service that gets a username.  Will
  974.   have to be modified to work on non-VAX equipment*/
  975.  
  976. /*===================================*/
  977.         lib$getjpi(&(JPI$_USERNAME),0,0,0,&u_name,0);
  978.         name[strlen(name)-strlen(strchr(name,' '))] = '\0';
  979. /*===================================*/
  980.         }
  981.  
  982.     if ((current = (HISCORE *) malloc(sizeof(HISCORE))) == NULL)
  983.         {
  984.         printf ("Cannot open space.");
  985.         exit (1);
  986.         }
  987.  
  988.     strcpy(current->name,name);
  989.     strcpy(current->username,username);
  990.     current->score=score;
  991.     current->games=games;
  992.     current->next=NULL;
  993.     }
  994.  
  995. if ((hiscore = (HISCORE *) malloc(sizeof(HISCORE))) == NULL)
  996.     {
  997.     printf ("Cannot open space.");
  998.     exit (1);
  999.     }
  1000.  
  1001. strcpy(hiscore->name," ");
  1002. strcpy(hiscore->username,"MineSweeper");
  1003. hiscore->score=0;
  1004. hiscore->games=0;
  1005. hiscore->next=NULL;
  1006.  
  1007. if ((deadscore = (HISCORE *) malloc(sizeof(HISCORE))) == NULL)
  1008.     {
  1009.     printf ("Cannot open space.");
  1010.     exit (1);
  1011.     }
  1012.  
  1013. strcpy(deadscore->name," ");
  1014. strcpy(deadscore->username,"MineSweeper");
  1015. deadscore->score=0;
  1016. deadscore->games=0;
  1017. deadscore->next=NULL;
  1018.  
  1019. fileptr=fopen("highscore.ms","r");
  1020. if (fileptr == NULL)
  1021.     {
  1022.     highscorefile();
  1023.     fileptr = fopen ("highscore.ms","r");
  1024.     }
  1025.  
  1026. fscanf(fileptr,"%d",&entry_num);
  1027.  
  1028. list = hiscore;
  1029. for(i=0;i<entry_num;i++)
  1030.     {
  1031.     if ((temp = (HISCORE *) malloc(sizeof(HISCORE))) == NULL)
  1032.         {
  1033.         printf ("Cannot open space.  High score file is too big!");
  1034.         exit (1);
  1035.         }
  1036.  
  1037.     fscanf(fileptr,"%s",&dumstr);
  1038.     strcpy(temp->name,dumstr);
  1039.     fscanf(fileptr,"%s",&dumstr);
  1040.     strcpy(temp->username,dumstr);
  1041.     fscanf(fileptr,"%d",&dumint);
  1042.     temp->score=dumint;
  1043.     fscanf(fileptr,"%d",&dumint);
  1044.     temp->games=dumint;
  1045.     temp->next=NULL;
  1046.  
  1047.     list->next = temp;
  1048.     list = list->next;
  1049.     }
  1050.  
  1051. fscanf(fileptr,"%d",&deadentry_num);
  1052.  
  1053. list = deadscore;
  1054. for(i=0;i<deadentry_num;i++)
  1055.     {
  1056.     if ((temp = (HISCORE *) malloc(sizeof(HISCORE))) == NULL)
  1057.         {
  1058.         printf ("Cannot open space.  High score file is too big!");
  1059.         exit (1);
  1060.         }
  1061.  
  1062.     fscanf(fileptr,"%s",&dumstr);
  1063.     strcpy(temp->name,dumstr);
  1064.     fscanf(fileptr,"%s",&dumstr);
  1065.     strcpy(temp->username,dumstr);
  1066.     fscanf(fileptr,"%d",&dumint);
  1067.     temp->score=dumint;
  1068.     fscanf(fileptr,"%d",&dumint);
  1069.     temp->games=dumint;
  1070.     temp->next=NULL;
  1071.  
  1072.     list->next = temp;
  1073.     list = list->next;
  1074.     }
  1075.  
  1076. fclose(fileptr);
  1077.  
  1078. if (flag==3)
  1079.     {
  1080.     list=hiscore->next;
  1081.     track=hiscore;
  1082.     while(    list != NULL)
  1083.          {
  1084.         if (strcmp(list->username,username)==0)
  1085.             return(1);
  1086.         list=list->next;
  1087.         track=track->next;
  1088.         }
  1089.     list=deadscore->next;
  1090.     track=deadscore;
  1091.     while(    list != NULL)
  1092.         {
  1093.         if (strcmp(list->username,username)==0)
  1094.             return(1);
  1095.         list=list->next;
  1096.         track=track->next;
  1097.         }
  1098.     return(0);
  1099.     }
  1100.  
  1101. if (flag==1)
  1102.     {
  1103.     list=hiscore->next;
  1104.     track=hiscore;
  1105.     add_entry=0;
  1106.     while(list != NULL)
  1107.         {
  1108.         if (strcmp(list->name,current->name)==0)
  1109.             {
  1110.             add_entry=1;
  1111.             list->score = list->score + current->score; 
  1112.             list->games++;
  1113.             free(current);
  1114.             current=list;
  1115.             }
  1116.         list=list->next;
  1117.         track=track->next;
  1118.         }
  1119.     if (add_entry==0)
  1120.         {
  1121.         list=hiscore->next;
  1122.         track=hiscore;
  1123.         while(    list != NULL    &&
  1124.             list->score > current->score)
  1125.             {
  1126.             list=list->next;
  1127.             track=track->next;
  1128.             }
  1129.         current->next=list;
  1130.         track->next=current;
  1131.         }
  1132.     }
  1133. if (flag==0)
  1134.     {
  1135.     list=hiscore->next;
  1136.     track=hiscore;
  1137.     while(    list != NULL)
  1138.         {
  1139.         if (strcmp(list->name,current->name)==0)
  1140.             {
  1141.             current->score = current->score + list->score;
  1142.             current->games++;
  1143.             temp=list;
  1144.             list=temp->next;
  1145.             track->next=list;
  1146.             free(temp);
  1147.             }
  1148.         else
  1149.             {
  1150.             list=list->next;
  1151.             track=track->next;
  1152.             }
  1153.         }
  1154.  
  1155.     list=deadscore->next;
  1156.     track=deadscore;
  1157.     add_entry=0;
  1158.     while(    list != NULL    &&
  1159.         add_entry==0)
  1160.         {
  1161.         if (list->score>current->score)
  1162.             {
  1163.             list=list->next;
  1164.             track=track->next;
  1165.             }
  1166.         else
  1167.             add_entry=1;
  1168.         }
  1169.     current->next=list;
  1170.     track->next=current;
  1171.     }
  1172.  
  1173. if (flag!=2)
  1174.     {
  1175.     fileptr=fopen("highscore.ms","w");
  1176.  
  1177.     count=0;
  1178.     list = hiscore->next;
  1179.     while (list != NULL)
  1180.         {
  1181.         count++;
  1182.         list = list->next;
  1183.         }
  1184.     fprintf(fileptr,"%d\n",count);
  1185.  
  1186.     list = hiscore->next;
  1187.     while (list != NULL)
  1188.         {
  1189.         fprintf(fileptr," %s",list->name);
  1190.         fprintf(fileptr," %s",list->username);
  1191.         fprintf(fileptr," %d",list->score);
  1192.         fprintf(fileptr," %d",list->games);
  1193.         fprintf(fileptr,"\n");
  1194.         list = list->next;
  1195.         }
  1196.  
  1197.     count=0;
  1198.     list = deadscore->next;
  1199.     while (list != NULL)
  1200.         {
  1201.         count++;
  1202.         list = list->next;
  1203.         }
  1204.     fprintf(fileptr,"%d\n",count);
  1205.  
  1206.     list = deadscore->next;
  1207.     while (list != NULL)
  1208.         {
  1209.         fprintf(fileptr," %s",list->name);
  1210.         fprintf(fileptr," %s",list->username);
  1211.         fprintf(fileptr," %d",list->score);
  1212.         fprintf(fileptr," %d",list->games);
  1213.         fprintf(fileptr,"\n");
  1214.         list = list->next;
  1215.         }
  1216.  
  1217.     fclose(fileptr);
  1218.     }
  1219.  
  1220. printf("\n");
  1221. printf("        High Scores:\nStatus  Games      Score  Rank  Name\n");
  1222.  
  1223. count=0;
  1224. list = hiscore->next;
  1225. while (list != NULL)
  1226.     {
  1227.     count++;
  1228.     if (count<4 || strcmp(list->name,current->name)==0 || flag==2)
  1229.         {
  1230.         normal();
  1231.         if (list==current) bold();
  1232.         printf("Won:    ");
  1233.         printf("%5d ",list->games);
  1234.         printf("%10d ",list->score);
  1235.         printf("%5d  ",count);
  1236.         if (list==current) normal();
  1237.     
  1238.         chflag=0;
  1239.         i=0;
  1240.         while ( (list->name)[i] != '\0')
  1241.             {
  1242.             if ((list->name)[i] == '\001')
  1243.                 {
  1244.                 printf(" ");
  1245.                 chflag=1;
  1246.                 }
  1247.             if ((list->name)[i] == '\002')
  1248.                 {
  1249.                 bold();
  1250.                 chflag=1;
  1251.                 }
  1252.             if ((list->name)[i] == '\006')
  1253.                 {
  1254.                 flash();
  1255.                 chflag=1;
  1256.                 }
  1257.             if ((list->name)[i] == '\016')
  1258.                 {
  1259.                 normal();
  1260.                 chflag=1;
  1261.                 }
  1262.             if ((list->name)[i] == '\022')
  1263.                 {
  1264.                 reverse();
  1265.                 chflag=1;
  1266.                 }
  1267.             if ((list->name)[i] == '\025')
  1268.                 {
  1269.                 underline();
  1270.                 chflag=1;
  1271.                 }
  1272.             if (chflag != 1)
  1273.                 {
  1274.                 printf("%c",(list->name)[i]);
  1275.                 }
  1276.             chflag=0;
  1277.             i++;
  1278.             }
  1279.             printf("\n");
  1280.         }
  1281.     list = list->next;
  1282.     }
  1283.  
  1284. count=0;
  1285. list = deadscore->next;
  1286. while (list != NULL)
  1287.     {
  1288.     count++;
  1289.     if (count<4 || strcmp(list->name,current->name)==0 || flag==2)
  1290.         {
  1291.         normal();
  1292.         if (list==current) bold();
  1293.         if (list->score<0)
  1294.             printf("Quit:   ");
  1295.         else
  1296.             printf("Died:   ");
  1297.         printf("%5d ",list->games);
  1298.         printf("%10d ",list->score * (-2 * (list->score<0) + 1));
  1299.         printf("%5d  ",count);
  1300.         if (list==current) normal();
  1301.     
  1302.         chflag=0;
  1303.         i=0;
  1304.         while ( (list->name)[i] != '\0')
  1305.             {
  1306.             if ((list->name)[i] == '\001')
  1307.                 {
  1308.                 printf(" ");
  1309.                 chflag=1;
  1310.                 }
  1311.             if ((list->name)[i] == '\002')
  1312.                 {
  1313.                 printf(BOLD);
  1314.                 chflag=1;
  1315.                 }
  1316.             if ((list->name)[i] == '\006')
  1317.                 {
  1318.                 printf(FLASH);
  1319.                 chflag=1;
  1320.                 }
  1321.             if ((list->name)[i] == '\016')
  1322.                 {
  1323.                 printf(NORMAL);
  1324.                 chflag=1;
  1325.                 }
  1326.             if ((list->name)[i] == '\022')
  1327.                 {
  1328.                 printf(REVERSE);
  1329.                 chflag=1;
  1330.                 }
  1331.             if ((list->name)[i] == '\025')
  1332.                 {
  1333.                 printf(UNDERLINE);
  1334.                 chflag=1;
  1335.                 }
  1336.             if (chflag != 1)
  1337.                 {
  1338.                 printf("%c",(list->name)[i]);
  1339.                 }
  1340.             chflag=0;
  1341.             i++;
  1342.             }
  1343.             printf("\n");
  1344.         }
  1345.     list = list->next;
  1346.     }
  1347.  
  1348. if (flag!=2) exit(0);
  1349. }
  1350.  
  1351. /*
  1352. the following two routines clear the rest of the board if you have obviously
  1353. won the game so that you don't have to clear every spoty yourself
  1354. */
  1355.  
  1356. autoclear()
  1357. {
  1358. int x,y;
  1359.  
  1360. for(x=0;x<XSIZE;x++)
  1361. for(y=0;y<YSIZE;y++)
  1362.     if (game[x][y].cover==' ' && game[x][y].board!=9) expose(x,y);
  1363. }
  1364.  
  1365. autoflag()
  1366. {
  1367. int x,y;
  1368.  
  1369. for(x=0;x<XSIZE;x++)
  1370. for(y=0;y<YSIZE;y++)
  1371.     if (game[x][y].cover==' ' && game[x][y].board==9) flag(x,y);
  1372. }
  1373.  
  1374. /*Redraws the screen, counting for a win.*/
  1375.  
  1376. draw()
  1377. {
  1378. int    x,y;
  1379. int    no_win=0;
  1380.  
  1381. view_flag=0;
  1382. clear();
  1383. printf (" ");
  1384. for (x=0;x<XSIZE;x++)
  1385.     printf ("_");
  1386. printf ("\n");
  1387. for (y=0;y<YSIZE;y++)
  1388.     {
  1389.     printf ("|");
  1390.     for (x=0;x<XSIZE;x++)
  1391.         {
  1392.         if (game[x][y].board != 9    &&
  1393.             game[x][y].cover == 'F') no_win = 1;
  1394.         if (game[x][y].board == 9    &&
  1395.             game[x][y].cover != 'F') no_win = 1;
  1396.  
  1397.         if (game[x][y].cover == ' ')
  1398.             {
  1399.             if (view_flag != 0)
  1400.                 {
  1401.                 normal();
  1402.                 view_flag = 0;
  1403.                 }
  1404.             printf ("+");
  1405.             }
  1406.         if (game[x][y].cover == 'X')
  1407.             if (game[x][y].board != 0)
  1408.                 {
  1409.                 if (view_flag == 0)
  1410.                     {
  1411.                     bold();
  1412.                     view_flag = 1;
  1413.                     }
  1414.                 else    if (view_flag != 1)
  1415.                     {
  1416.                     normal();
  1417.                     bold();
  1418.                     view_flag = 1;
  1419.                     }
  1420.                 printf ("%d",game[x][y].board);
  1421.                 }
  1422.             else
  1423.                 {
  1424.                 if (view_flag != 0)
  1425.                     {
  1426.                     normal();
  1427.                     view_flag = 0;
  1428.                     }
  1429.                 printf(" ");
  1430.                 }
  1431.         if (game[x][y].cover == 'F')
  1432.             {
  1433.             if (view_flag == 0)
  1434.                 {
  1435.                 reverse();
  1436.                 view_flag = 2;
  1437.                 }
  1438.             else    if (view_flag != 2)
  1439.                 {
  1440.                 normal();
  1441.                 reverse();
  1442.                 view_flag = 2;
  1443.                 }
  1444.             printf ("F");
  1445.             }
  1446.         if (game[x][y].cover != ' '    &&
  1447.             game[x][y].cover != 'X'    &&
  1448.             game[x][y].cover != 'F')
  1449.             {
  1450.             if (view_flag == 0)
  1451.                 {
  1452.                 reverse();
  1453.                 flash();
  1454.                 view_flag = 3;
  1455.                 }
  1456.             else    if (view_flag != 3)
  1457.                 {
  1458.                 normal();
  1459.                 reverse();
  1460.                 flash();
  1461.                 view_flag = 3;
  1462.                 }
  1463.             printf("%c",game[x][y].cover);
  1464.             }
  1465.         }
  1466.     if (view_flag != 0)
  1467.         {
  1468.         normal();
  1469.         view_flag = 0;
  1470.         }
  1471.     printf ("|");
  1472.     printf ("\n");
  1473.     }
  1474. printf (" ");
  1475. for (x=0;x<XSIZE;x++)
  1476.     printf ("~");
  1477.  
  1478. locate(1,length);
  1479. if (view_flag != 0)
  1480.     {
  1481.     normal();
  1482.     view_flag = 0;
  1483.     }
  1484. printf("Press HELP for keypad diagram or FIND for help.  ");
  1485. printf("Number of mines left: %4d",mine_total-flag_counter);
  1486.  
  1487. if (no_win != 1)
  1488.     {
  1489.         high(1);
  1490.     }
  1491. }
  1492.  
  1493. /*Displays the minefield when the user quits or dies.  Gives percent done.*/
  1494.  
  1495. show(a,b)
  1496. int    a,b;
  1497. {       
  1498. int    x,y,i;
  1499. char    answer[80];
  1500.  
  1501. /*The following is needed for the DEC system service that gets a key.  Will
  1502.   have to be modified to work on non-VAX equipment*/
  1503.  
  1504. /*===================================*/
  1505. int    keyid,key;
  1506. struct    dsc$descriptor ans = {
  1507.     19,
  1508.     DSC$K_DTYPE_T,
  1509.     DSC$K_CLASS_S,
  1510.     answer };
  1511.  
  1512. SMG$CREATE_VIRTUAL_KEYBOARD(&keyid);
  1513. /*===================================*/
  1514.  
  1515. normal();
  1516. locate (1,length);
  1517. for (i=0;i<75;i++)
  1518.     printf(" ");
  1519. locate (1,length);
  1520. printf("Do you want to see the minefield? (Return = No) ");
  1521.  
  1522. /*The following is needed for the DEC system service that gets a key.  Will
  1523.   have to be modified to work on non-VAX equipment*/
  1524.  
  1525. /*===================================*/
  1526. SMG$READ_KEYSTROKE(&keyid,&key);
  1527. SMG$KEYCODE_TO_NAME(&key,&ans);
  1528. answer[strlen(answer)-strlen(strchr(answer,' '))] = '\0';
  1529. if (strcmp(answer,"")==0) strcpy(answer," ");
  1530. /*===================================*/
  1531.  
  1532. if (answer[0]=='Y'    ||
  1533.     answer[0]=='y'    ||
  1534.     answer[0]==""    )
  1535.     {
  1536.     clear();
  1537.     view_flag = 0;
  1538.     printf (" ");
  1539.     for (x=0;x<XSIZE;x++)
  1540.         printf ("_");
  1541.     printf ("\n");
  1542.     for (y=0;y<YSIZE;y++)
  1543.         {
  1544.         printf ("|");
  1545.         for (x=0;x<XSIZE;x++)
  1546.             {
  1547.             if (a == x && b == y && a != -1 && b != -1)
  1548.                 {
  1549.                 if (view_flag == 0)
  1550.                     {
  1551.                     reverse();
  1552.                     view_flag = 2;
  1553.                     }
  1554.                 else    if (view_flag != 2)
  1555.                     {
  1556.                     normal();
  1557.                     reverse();
  1558.                     view_flag = 2;
  1559.                     }
  1560.                 if (game[x][y].board == 9)
  1561.                     printf (" ");
  1562.                 else
  1563.                     printf ("%d",game[x][y].board);
  1564.                 }
  1565.             else    if (game[x][y].board == 9)
  1566.                 {
  1567.                 if (view_flag == 0)
  1568.                     {
  1569.                     reverse();
  1570.                     view_flag = 2;
  1571.                     }
  1572.                 else    if (view_flag != 2)
  1573.                     {
  1574.                     normal();
  1575.                     reverse();
  1576.                     view_flag = 2;
  1577.                     }
  1578.                 if (game[x][y].cover == 'F')
  1579.                     printf ("F");
  1580.                 else
  1581.                     printf ("#");
  1582.                 }
  1583.             else    if (game[x][y].board == 0)
  1584.                 {
  1585.                 if (game[x][y].cover == 'F')
  1586.                     {
  1587.                     if (view_flag != 3)
  1588.                         {
  1589.                         if (view_flag == 0)
  1590.                             {
  1591.                             flash();
  1592.                             view_flag = 3;
  1593.                             }
  1594.                                                 else
  1595.                             {
  1596.                             normal();
  1597.                             flash();
  1598.                             view_flag = 3;
  1599.                             }
  1600.                         }
  1601.                     }
  1602.                 else    if (view_flag != 0)
  1603.                     {
  1604.                     normal();
  1605.                     view_flag = 0;
  1606.                     }
  1607.                 printf (" ");
  1608.                 }
  1609.             else
  1610.                 {
  1611.                 if (game[x][y].cover == 'F')
  1612.                     {
  1613.                     if (view_flag != 4)
  1614.                         {
  1615.                         if (view_flag == 0)
  1616.                             {
  1617.                             flash();
  1618.                             bold();
  1619.                             view_flag = 4;
  1620.                             }
  1621.                                                 else
  1622.                             {
  1623.                             normal();
  1624.                             flash();
  1625.                             bold();
  1626.                             view_flag = 4;
  1627.                             }
  1628.                         }
  1629.                     }
  1630.                 else
  1631.                     {
  1632.                     if (view_flag != 1)
  1633.                         {
  1634.                         if (view_flag == 0)
  1635.                             {
  1636.                             bold();
  1637.                             view_flag = 1;
  1638.                             }
  1639.                                                 else
  1640.                             {
  1641.                             normal();
  1642.                             bold();
  1643.                             view_flag = 1;
  1644.                             }
  1645.                         }
  1646.                     }
  1647.                     printf ("%d",game[x][y].board);
  1648.                 }
  1649.             }
  1650.         if (view_flag != 0)
  1651.             {
  1652.             normal();
  1653.             view_flag = 0;
  1654.             }
  1655.         printf ("|");
  1656.         printf ("\n");
  1657.         }
  1658.     printf (" ");
  1659.     for (x=0;x<XSIZE;x++)
  1660.         printf ("~");
  1661.     sleep(5);
  1662.     }
  1663.  
  1664. high(0);
  1665. exit(0);
  1666. }
  1667.  
  1668. /*Clears the arrays at the beginning of the game.*/
  1669. empty()
  1670. {
  1671. int    x,y;
  1672.  
  1673. for (y=0;y<YSIZE;y++)
  1674.     for (x=0;x<XSIZE;x++)
  1675.         {
  1676.         game[x][y].cover = ' ';
  1677.         game[x][y].board = 0;
  1678.         game[x][y].stack = 0;
  1679.         }
  1680. }
  1681.  
  1682. /*Places the mines randomly (using the system time as the seed).  Will have to
  1683.   be modified for non-VAX equipment.*/
  1684.  
  1685. fill()
  1686. {
  1687. int    x,y,n,m;
  1688. char    date_time[24];
  1689. int    bin_d_t;
  1690. struct    dsc$descriptor d_t = {
  1691.     23,
  1692.     DSC$K_DTYPE_T,
  1693.     DSC$K_CLASS_S,
  1694.     date_time };
  1695.  
  1696. /*The following is needed for the DEC system service that gets the time.  Will
  1697.   have to be modified to work on non-VAX equipment*/
  1698.  
  1699. /*===================================*/
  1700. LIB$DATE_TIME(&d_t);
  1701. date_time[24]='\0';
  1702. printf ("%s\n",date_time);
  1703. SYS$BINTIM(&d_t,&bin_d_t);
  1704. /*===================================*/
  1705.  
  1706. sleep(1);
  1707.  
  1708. n = 0;
  1709. m = 0;
  1710.  
  1711. if (bin_d_t == 0) bin_d_t++;
  1712. if (bin_d_t  < 0) bin_d_t = bin_d_t * -1;
  1713. srand(bin_d_t);
  1714.  
  1715. if (DEBUG == 1) clear();
  1716. while    (n<MINES && m<100000)
  1717.     {
  1718.     x=rand()%(XSIZE*10)/10;
  1719.     y=rand()%(YSIZE*10)/10;
  1720.     if (game[x][y].board    != 9    &&
  1721.        !    ((x==0 || x==XSIZE-1)    &&
  1722.          (y==0 || y==YSIZE-1))    )
  1723.         {
  1724.         n++;
  1725.         game[x][y].board = 9;
  1726.         if (DEBUG == 1)
  1727.             {
  1728.             locate(x,y);
  1729.             printf("+");
  1730.             }
  1731.         }
  1732.     m++;
  1733.     }
  1734. mine_total = n;
  1735. sleep(3);
  1736. }
  1737.  
  1738. /*Calculates the numbers based on the locations of the mines in the field.*/
  1739. calc()
  1740. {
  1741. int    x,y;
  1742.  
  1743. for (y=0;y<YSIZE;y++)
  1744.     {
  1745.     for (x=0;x<XSIZE;x++)
  1746.         {
  1747.         if (game[x][y].board==0)
  1748.             {
  1749.                         if (x==0 && y==0)
  1750.             game[x][y].board=
  1751.               (game[x+1][y].board == 9)+
  1752.               (game[x][y+1].board == 9)+
  1753.               (game[x+1][y+1].board == 9);
  1754.                         if (x>0 && x<XSIZE-1 && y==0)
  1755.             game[x][y].board=
  1756.               (game[x-1][y].board == 9)+
  1757.               (game[x+1][y].board == 9)+
  1758.               (game[x-1][y+1].board == 9)+
  1759.               (game[x][y+1].board == 9)+
  1760.               (game[x+1][y+1].board == 9);
  1761.                         if (x==XSIZE-1 && y==0)
  1762.             game[x][y].board=
  1763.               (game[x-1][y].board == 9)+
  1764.               (game[x-1][y+1].board == 9)+
  1765.               (game[x][y+1].board == 9);
  1766.                         if (x==0 && y>0 && y<YSIZE-1)
  1767.             game[x][y].board=
  1768.               (game[x][y-1].board == 9)+
  1769.               (game[x+1][y-1].board == 9)+
  1770.               (game[x+1][y].board == 9)+
  1771.               (game[x][y+1].board == 9)+
  1772.               (game[x+1][y+1].board == 9);
  1773.             if (x>0 && x<XSIZE-1 && y>0 && y<YSIZE-1)
  1774.             game[x][y].board=
  1775.               (game[x-1][y-1].board == 9)+
  1776.               (game[x][y-1].board == 9)+
  1777.               (game[x+1][y-1].board == 9)+
  1778.               (game[x-1][y].board == 9)+
  1779.               (game[x+1][y].board == 9)+
  1780.               (game[x-1][y+1].board == 9)+
  1781.               (game[x][y+1].board == 9)+
  1782.               (game[x+1][y+1].board == 9);
  1783.             if (x==XSIZE-1 && y>0 && y<YSIZE-1)
  1784.             game[x][y].board=
  1785.               (game[x-1][y-1].board == 9)+
  1786.               (game[x][y-1].board == 9)+
  1787.               (game[x-1][y].board == 9)+
  1788.               (game[x-1][y+1].board == 9)+
  1789.               (game[x][y+1].board == 9);
  1790.             if (x==0 && y==YSIZE-1)
  1791.             game[x][y].board=
  1792.               (game[x][y-1].board == 9)+
  1793.               (game[x+1][y-1].board == 9)+
  1794.               (game[x+1][y].board == 9);
  1795.             if (x>0 && x<XSIZE-1 && y==YSIZE-1)
  1796.             game[x][y].board=
  1797.               (game[x-1][y-1].board == 9)+
  1798.               (game[x][y-1].board == 9)+
  1799.               (game[x+1][y-1].board == 9)+
  1800.               (game[x-1][y].board == 9)+
  1801.               (game[x+1][y].board == 9);
  1802.             if (x==XSIZE-1 && y==YSIZE-1)
  1803.             game[x][y].board=
  1804.               (game[x-1][y-1].board == 9)+
  1805.               (game[x][y-1].board == 9)+
  1806.               (game[x-1][y].board == 9);
  1807.             }
  1808.         }
  1809.     }
  1810. }
  1811.  
  1812. /*Help routine.*/
  1813. command_line()
  1814. {
  1815. reverse();
  1816. printf("Command Line Parameters.");
  1817. normal();
  1818. bold();
  1819. printf("    <key>=<number>\n");
  1820. normal();
  1821. printf("\n");
  1822. bold();
  1823. printf("x or c or w    ");
  1824. normal();
  1825. printf("The number of Columns or the Width of the field\n");
  1826. bold();
  1827. printf("y or r or l    ");
  1828. normal();
  1829. printf("The number of Rows or the Length of the field\n");
  1830. bold();
  1831. printf("s              ");
  1832. normal();
  1833. printf("The filename of a saved game\n");
  1834. bold();
  1835. printf("b or m        ");
  1836. normal();
  1837. printf("The number of Mines\n");
  1838. bold();
  1839. printf("h        ");
  1840. normal();
  1841. printf("The number of Hints\n");
  1842. bold();
  1843. printf("d        ");
  1844. normal();
  1845. printf("If D=1 then display the mines as they are being buried\n");
  1846. bold();
  1847. printf("?        ");
  1848. normal();
  1849. printf("list of keys and brief description of game\n");
  1850. bold();
  1851. printf("/        ");
  1852. normal();
  1853. printf("shows the entire high score file and your current score\n");
  1854. }
  1855.  
  1856. /*Help routine.*/
  1857. keys()
  1858. {
  1859. reverse();
  1860. printf("Keys.\n");
  1861. normal();
  1862. printf("\n");
  1863. bold();
  1864. printf("Control-W    ");
  1865. normal();
  1866. printf("redraw the screen\n");
  1867. bold();
  1868. printf("q or DO        ");
  1869. normal();
  1870. printf("quit\n");
  1871. bold();
  1872. printf("p or INSERTHERE ");
  1873. normal();
  1874. printf("preserve (save) the game at the current spot\n");
  1875. bold();
  1876. printf("s or SELECT    ");
  1877. normal();
  1878. printf("clear the space the cursor is on\n");
  1879. bold();
  1880. printf("d or PREVSCREEN    ");
  1881. normal();
  1882. printf("will NOT clear the space the cursor is on, but\n");
  1883. printf("        if it is already clear and the right number of\n");
  1884. printf("        flags surround it, all the surrounding unflaged\n");
  1885. printf("        spots will be cleared\n");
  1886. bold();
  1887. printf("f or NEXTSCREEN    ");
  1888. normal();
  1889. printf("flag (or if flagged then unflag) the space the cursor is on\n");
  1890. bold();
  1891. printf("h or Return    ");
  1892. normal();
  1893. printf("hint key: may only be used three times.  Will clear or\n");
  1894. printf("        flag the space the cursor is on, whichever is appropriate\n");
  1895. bold();
  1896. printf("i, j, k, and l    ");
  1897. normal();
  1898. printf("cursor keys\n");
  1899. bold();
  1900. printf("HELP        ");
  1901. normal();
  1902. printf("keypad drawing\n");
  1903. bold();
  1904. printf("? or FIND    ");
  1905. normal();
  1906. printf("list of keys and brief description of game\n");
  1907. bold();
  1908. printf("/ or REMOVE    ");
  1909. normal();
  1910. printf("shows the entire high score file and your current score\n");
  1911. }
  1912.  
  1913. /*Help routine.*/
  1914. keypad()
  1915. {
  1916. reverse();
  1917. printf("Keypad.\n");
  1918. normal();
  1919. printf("\n");
  1920. printf("                       .-------------.---------------------------.\n");
  1921. printf("                       |     HELP    |            DO             |\n");
  1922. printf("                       | keypad help |         quit game         |\n");
  1923. printf("                       `-------------'---------------------------'\n");
  1924. printf("                       .-------------.-------------.-------------.\n");
  1925. printf("                       |     FIND    | INSERT HERE |   REMOVE    |\n");
  1926. printf("                       | help screen |  save game  | high scores |\n");
  1927. printf(".-------------.        |-------------|-------------|-------------|\n");
  1928. printf("|    RETURN   |        |    SELECT   | PREV SCREEN | NEXT SCREEN |\n");
  1929. printf("|     hint    |        |    clear    | safetyclear |    flag     |\n");
  1930. printf("`-----.       |        `-------------|-------------|-------------'\n");
  1931. printf("      |       |                      |      UP     |              \n");
  1932. printf("      |       |                      |             |              \n");
  1933. printf("      `-------'        .-------------|-------------|-------------.\n");
  1934. printf("                       |     LEFT    |     DOWN    |    RIGHT    |\n");
  1935. printf("                       |             |             |             |\n");
  1936. printf("                       `-------------`-------------'-------------'\n");
  1937. printf("\n");
  1938. printf("        Press ? or FIND to get nore detailed help\n");
  1939. }
  1940.  
  1941. /*Help routine.*/
  1942. info()
  1943. {
  1944. reverse();
  1945. printf("MineSweeper.\n");
  1946. normal();
  1947. printf("\n");
  1948. printf("The goal is to find and flag all the mines in the minefield.\n");
  1949. printf("You win when the field is entirely cleared except for the flagged\n");
  1950. printf("mines.  You have exactly the right number of flags.\n");
  1951. printf("\n");
  1952. printf("The number that shows up when you clear a spot tells how many mines\n");
  1953. printf("are on one of the eight neighbouring spots.  These are the clues you\n");
  1954. printf("have to where the mines are.\n");
  1955. printf("\n");
  1956. printf("The score calculated is approximately:\n");
  1957. printf("\n");
  1958. printf("        Number_of_squares_cleared_or_flagged * Number_of_mines\n");
  1959. printf("score = ------------------------------------------------------\n");
  1960. printf("              14%_of_size_of_Board * Number_of_hints_used\n");
  1961. }
  1962.  
  1963. /*Help routine.*/
  1964. other_info()
  1965. {
  1966. reverse();
  1967. printf("Other Information.\n");
  1968. normal();
  1969. printf("\n");
  1970. printf("When you die and see the minefield:\n");
  1971. flash();
  1972. printf("n");
  1973. normal();
  1974. printf(" are spots that have been flagged and are not mines\n");
  1975. reverse();
  1976. printf("#");
  1977. normal();
  1978. printf(" are spots that have not been flagged and are mines\n");
  1979. reverse();
  1980. printf("F");
  1981. normal();
  1982. printf(" are spots that have been flagged and are mines\n");
  1983. reverse();
  1984. printf(" ");
  1985. normal();
  1986. printf(" is the mine you cleared that killed you.\n");
  1987. printf("\n");
  1988. printf("When you enter your name for the highscore file these keys work:\n");
  1989. printf("(If you do not enter a name your username is used)\n");
  1990. printf("Control-N    Normal:    turns off all other codes\n");
  1991. printf("Control-B    Bold:      bolds all following text until Normal\n");
  1992. printf("Control-F    Flash:     flashs all following text until Normal\n");
  1993. printf("Control-R    Reverse:   reverses all following text until Normal\n");
  1994. printf("Control-U    Underline: underlines all following text until Normal\n");
  1995. printf("\n");
  1996. printf("When you put your name in the high score file, the file showed to you\n");
  1997. printf("has only the top three people who won and the top three people who died,\n");
  1998. printf("as well as all of the entries with the entered name.\n");
  1999. }
  2000.  
  2001. help(int flag)
  2002. {
  2003. if (flag==1) 
  2004.     {
  2005.     clear();
  2006.     info();
  2007.     printf("\n");
  2008.     sleep(5);
  2009.     clear();
  2010.     keypad();
  2011.     printf("\n");
  2012.     sleep(5);
  2013.     clear();
  2014.     keys();
  2015.     printf("\n");
  2016.     sleep(5);
  2017.     clear();
  2018.     command_line();
  2019.     printf("\n");
  2020.     sleep(5);
  2021.     clear();
  2022.     other_info();
  2023.     printf("\n");
  2024.     sleep(5);
  2025.     }
  2026. if (flag==0) 
  2027.     {
  2028.     clear();
  2029.     command_line();
  2030.     }
  2031. }
  2032.  
  2033. /*The following is needed for the DEC system service that gets the terminal
  2034.   size.  Will have to be modified to work on non-VAX equipment*/
  2035.  
  2036. /*===================================*/
  2037. #define size 8
  2038.  
  2039. termsize()
  2040. {
  2041. char buffer[size],param[20];
  2042. unsigned long chan;
  2043. char i;
  2044. char devnam[20];
  2045. struct dsc$descriptor device_name = {
  2046.     19,
  2047.     DSC$K_DTYPE_T,
  2048.     DSC$K_CLASS_S,
  2049.     devnam };
  2050.  
  2051. strcpy(devnam,"SYS$INPUT:");
  2052. device_name.dsc$w_length=strlen(devnam);
  2053.  
  2054. i=SYS$ASSIGN(&device_name,&chan,NULL,NULL,NULL);
  2055. LIB$SIGNAL(i);
  2056.  
  2057. i=SYS$QIOW(NULL,chan,IO$_SENSEMODE,
  2058.        NULL,NULL,NULL,&buffer,size,NULL,NULL,NULL,NULL);
  2059.  
  2060. swidth = buffer[2];
  2061. slength = buffer[7];
  2062.  
  2063. if (swidth<1)
  2064.     swidth = 256 + swidth;
  2065. if (slength<1)
  2066.     slength = 256 + slength;
  2067.  
  2068. if (slength<24)
  2069.     length=24;
  2070. else
  2071.     length=slength;
  2072.  
  2073. if (swidth<80)
  2074.     width=80;
  2075. else
  2076.     width=swidth;
  2077.  
  2078. buffer[2] = width-256*(width>127);
  2079. buffer[7] = length-256*(length>127);
  2080.  
  2081.     i=SYS$QIOW(NULL,chan,IO$_SETMODE,
  2082.            NULL,NULL,NULL,&buffer,size,NULL,NULL,NULL,NULL);
  2083.  
  2084. }
  2085.  
  2086. /*===================================*/
  2087.  
  2088. /*This is the \main loop.*/
  2089.  
  2090. main (argc,argv)
  2091. int     argc;
  2092. char    *argv[];
  2093. {
  2094. FILE    *fileptr;
  2095. char    savename[60];
  2096. int    save_flag=0,skip=0;
  2097. int    x=0,y=0,n=0;
  2098. int    ix,iy,i;
  2099. int    hint_flag,mine_flag;
  2100. int    count;
  2101. int    getone,num;
  2102. char    param[20];
  2103.  
  2104. /*The following is needed for the DEC system service that gets a key.  Will
  2105.   have to be modified to work on non-VAX equipment*/
  2106.  
  2107. /*===================================*/
  2108. char    keyname[20];
  2109. int    keyid,key;
  2110. struct    dsc$descriptor name = {
  2111.     19,
  2112.     DSC$K_DTYPE_T,
  2113.     DSC$K_CLASS_S,
  2114.     keyname };
  2115.  
  2116. SMG$CREATE_VIRTUAL_KEYBOARD(&keyid);
  2117. /*===================================*/
  2118.  
  2119. termsize();
  2120. XSIZE=swidth-3;
  2121. if (XSIZE<3)
  2122.     {
  2123.     printf("The terminal width is too small.");
  2124.     exit(1);
  2125.     }
  2126. YSIZE=slength-2;
  2127. if (YSIZE<1)
  2128.     {
  2129.     printf("The terminal height is too small.");
  2130.     exit(1);
  2131.     }
  2132. printf("Terminal size: %d x %d\n\n",width,length);
  2133.  
  2134. /*Parse the command line arguements.*/
  2135. if (argc>1)
  2136.     {
  2137.     for (getone=1;getone<argc;getone++)
  2138.         {
  2139.         sscanf (argv[getone],"%s",¶m);
  2140.         printf ("Working on parameter: %s\n",param);
  2141.  
  2142.         if (param[0] == '/')
  2143.             {
  2144.             high(2);
  2145.             exit(0);
  2146.             }
  2147.         if (param[0] == '?')
  2148.             {
  2149.             help(1);
  2150.             exit(0);
  2151.             }
  2152.         if (strpbrk(param,"=")==NULL)
  2153.             {
  2154.             help(0);
  2155.             exit(1);
  2156.             }
  2157.         if (param[1] != '=')
  2158.             {
  2159.             help(0);
  2160.             exit(1);
  2161.             }
  2162.         if (param[0] != 'L'    &&
  2163.             param[0] != 'l'    &&
  2164.             param[0] != 'Y'    &&
  2165.             param[0] != 'y'    &&
  2166.             param[0] != 'R'    &&
  2167.             param[0] != 'r'    &&
  2168.             param[0] != 'W'    &&
  2169.             param[0] != 'w'    &&
  2170.             param[0] != 'X'    &&
  2171.             param[0] != 'x'    &&
  2172.             param[0] != 'C'    &&
  2173.             param[0] != 'c'    &&
  2174.             param[0] != 'M'    &&
  2175.             param[0] != 'm'    &&
  2176.             param[0] != 'B'    &&
  2177.             param[0] != 'b'    &&
  2178.             param[0] != 'S'    &&
  2179.             param[0] != 's'    &&
  2180.             param[0] != 'H'    &&
  2181.             param[0] != 'h'    &&
  2182.             param[0] != 'D'    &&
  2183.             param[0] != 'd')
  2184.             {
  2185.             help(0);
  2186.             exit(1);
  2187.             }
  2188.         if (param[0] == 'L'    ||
  2189.             param[0] == 'l'    ||
  2190.             param[0] == 'R'    ||
  2191.             param[0] == 'r'    ||
  2192.             param[0] == 'Y'    ||
  2193.             param[0] == 'y')
  2194.             {
  2195.             if (atoi(strchr(param,'=')+sizeof(char))<YSIZE)
  2196.                 {
  2197.                 YSIZE = atoi(strchr(param,'=')+sizeof(char));
  2198.                 if (YSIZE<1) YSIZE = 1;
  2199.                 }
  2200.             printf("%d rows\n",YSIZE);
  2201.             }
  2202.         if (param[0] == 'W'    ||
  2203.             param[0] == 'w'    ||
  2204.             param[0] == 'C'    ||
  2205.             param[0] == 'c'    ||
  2206.             param[0] == 'X'    ||
  2207.             param[0] == 'x')
  2208.             {
  2209.             if (atoi(strchr(param,'=')+sizeof(char))<XSIZE)
  2210.                 {
  2211.                 XSIZE = atoi(strchr(param,'=')+sizeof(char));
  2212.                 if (XSIZE<3) XSIZE = 3;
  2213.                 }
  2214.             printf("%d columns\n",XSIZE);
  2215.             }
  2216.         if (param[0] == 'H'    ||
  2217.             param[0] == 'h')
  2218.             {
  2219.             HINTS = atoi(strchr(param,'=')+sizeof(char));
  2220.             if (HINTS<0) HINTS = 0;
  2221.             printf("%d hints\n",HINTS);
  2222.             hint_flag = 1;
  2223.             }
  2224.         if (param[0] == 'S'    ||
  2225.             param[0] == 's')
  2226.             {
  2227.             strcpy(savename, strchr(param,'=')+sizeof(char));
  2228.             printf("Restoring %s\n",savename);
  2229.             save_flag = 1;
  2230.             }
  2231.         if (param[0] == 'M'    ||
  2232.             param[0] == 'm'    ||
  2233.             param[0] == 'B'    ||
  2234.             param[0] == 'b')
  2235.             {
  2236.             MINES = atoi(strchr(param,'=')+sizeof(char));
  2237.             if (MINES<1) MINES = 1;
  2238.             printf("%d mines\n",MINES);
  2239.             mine_flag = 1;
  2240.             }
  2241.         if (param[0] == 'D'    ||
  2242.             param[0] == 'd')
  2243.             {
  2244.             DEBUG = atoi(strchr(param,'=')+sizeof(char));
  2245.             }
  2246.         }
  2247.     }
  2248.  
  2249. if (high(3) != 1)
  2250.     {
  2251.     help(1);
  2252.     clear();
  2253.     }
  2254. if (mine_flag != 1)
  2255.     {
  2256.     MINES=XSIZE*YSIZE*147/10000*10+10;
  2257.     printf ("\nThe number of mines for this game is projected to be %d.\n",MINES);
  2258.     }
  2259. if (hint_flag != 1)
  2260.     printf ("\nThe number of hints for this game will be %d.\n\n",HINTS);
  2261. if (save_flag == 1)
  2262.     {
  2263.     fileptr = fopen (savename,"r");
  2264.     skip=0;
  2265.     while (fileptr == NULL    &&    skip == 0)
  2266.         {
  2267.         printf("Enter the name of a game to restore:  (Return to go skip) ");
  2268.         getstring(savename,60,1);
  2269.         skip=0;    if (strlen(savename)==0) skip=1;
  2270.         if (skip==0) fileptr = fopen (savename,"r");
  2271.         printf("\n");
  2272.         }
  2273.     if (skip==0)
  2274.         {
  2275.         fscanf (fileptr,"%d",&real_flag_counter);
  2276.         fscanf (fileptr,"%d",&flag_counter);
  2277.         fscanf (fileptr,"%d",&counter);
  2278.         fscanf (fileptr,"%d",&XSIZE);
  2279.         fscanf (fileptr,"%d",&YSIZE);
  2280.         fscanf (fileptr,"%d",&hint);
  2281.         fscanf (fileptr,"%d",&HINTS);
  2282.         fscanf (fileptr,"%d",&mine_total);
  2283.         }
  2284.     }
  2285.  
  2286. /*Build the game board array.*/
  2287. if ((game = (TABLE **) malloc(XSIZE*sizeof(TABLE *))) != NULL)
  2288.     {
  2289.     for(i = 0; i<XSIZE; i++)
  2290.         {
  2291.         if ((game1 = (TABLE *) malloc(YSIZE*sizeof(TABLE))) != NULL)
  2292.             game[i] = game1;
  2293.         else
  2294.             {
  2295.             printf ("Cannot open space.  Choose a smaller size.");
  2296.             exit (1);
  2297.             }
  2298.         }
  2299.     }
  2300. else
  2301.     {
  2302.     printf ("Cannot open space.  Chose a smaller size.");
  2303.     exit (1);
  2304.     }
  2305.  
  2306. if (save_flag == 1    &&    skip == 0)
  2307.     {
  2308.         for(ix=0;ix<XSIZE;ix++)
  2309.         for(iy=0;iy<YSIZE;iy++)
  2310.         {
  2311.         fscanf (fileptr,"%d",&i);
  2312.         game[ix][iy].cover=i;
  2313.         fscanf (fileptr,"%d",&i);
  2314.         game[ix][iy].board=i;
  2315.         }
  2316.     fscanf (fileptr,"%d",&x);
  2317.     fscanf (fileptr,"%d",&y);
  2318.     fclose(fileptr);
  2319.     if (XSIZE>width-3 || YSIZE>length-2)
  2320.         {
  2321.         printf("This saved game needs a %d x %d terminal to load.\n",
  2322.             XSIZE+3,YSIZE+2);
  2323.         printf("Since I am not sure if your terminal can handle\n");
  2324.         printf("this large size, you will have to set it manually.\n");
  2325.         exit(1);
  2326.         }
  2327.     }
  2328. else
  2329.     {
  2330.     create();
  2331.     empty();
  2332.     fill();
  2333.     calc();
  2334.     }
  2335. draw();
  2336.  
  2337. locate (x,y);
  2338.  
  2339. while ( 1)
  2340.     {
  2341.  
  2342.     if (    strcmp(keyname,"E2")     == 0    ||
  2343.         strcmp(keyname,"P")     == 0    ||
  2344.         strcmp(keyname,"p")     == 0    )
  2345.         {
  2346.         locate(1,length);
  2347.         if (view_flag != 0)
  2348.             {
  2349.             normal();
  2350.             view_flag = 0;
  2351.             }
  2352.         for (i=0;i<75;i++)
  2353.         printf(" ");
  2354.         locate (1,length);
  2355.         printf("Please enter a filename: (Return to go back) ");
  2356.         getstring(savename,30,1);
  2357.         locate (1,length);
  2358.         printf("Press HELP for keypad diagram or FIND for help.  ");
  2359.         printf("Number of mines left: %4d",mine_total-flag_counter);
  2360.  
  2361.         skip=0;    if (strlen(savename)==0) skip=1;
  2362.         if (skip == 0) fileptr = fopen (savename,"w");
  2363.         if (fileptr != NULL    &&    skip == 0)
  2364.             {
  2365.             fprintf (fileptr,"%d\n",real_flag_counter);
  2366.             fprintf (fileptr,"%d\n",flag_counter);
  2367.             fprintf (fileptr,"%d\n",counter);
  2368.             fprintf (fileptr,"%d\n",XSIZE);
  2369.             fprintf (fileptr,"%d\n",YSIZE);
  2370.             fprintf (fileptr,"%d\n",hint);
  2371.             fprintf (fileptr,"%d\n",HINTS);
  2372.             fprintf (fileptr,"%d\n",mine_total);
  2373.                  for(ix=0;ix<XSIZE;ix++)
  2374.                 {
  2375.                 for(iy=0;iy<YSIZE;iy++)
  2376.                 {
  2377.                 fprintf (fileptr,"%d ",game[ix][iy].cover);
  2378.                 fprintf (fileptr,"%d ",game[ix][iy].board);
  2379.                 }
  2380.                 fprintf (fileptr,"\n");
  2381.                 }
  2382.             fprintf (fileptr,"%d\n",x);
  2383.             fprintf (fileptr,"%d\n",y);
  2384.             fclose (fileptr);
  2385.             }
  2386.         }
  2387.  
  2388.     if (    strcmp(keyname,"HELP")     == 0    )
  2389.         {
  2390.         keypad();
  2391.         draw();
  2392.         }
  2393.  
  2394.     if (    strcmp(keyname,"?")     == 0    ||
  2395.         strcmp(keyname,"E1")     == 0    )
  2396.         {
  2397.         help(1);
  2398.         draw();
  2399.         }
  2400.  
  2401.     if (    strcmp(keyname,"/")     == 0    ||
  2402.         strcmp(keyname,"E3")     == 0    )
  2403.         {
  2404.         high(2);
  2405.         printf("\n");
  2406.         sleep(5);
  2407.         draw();
  2408.         }
  2409.  
  2410.     if (    strcmp(keyname,"q")      == 0    ||
  2411.         strcmp(keyname,"Q")      == 0    ||
  2412.         strcmp(keyname,"DO")     == 0)
  2413.             {
  2414.             quit_flag = 1;
  2415.             show(-1,-1);
  2416.             }
  2417.  
  2418.     if (    strcmp(keyname,"s")      == 0    ||
  2419.         strcmp(keyname,"S")      == 0    ||
  2420.             strcmp(keyname,"E4")     == 0)
  2421.         if (game[x][y].board     != 9)
  2422.             expose(x,y);
  2423.         else    if (game[x][y].cover    != 'F')
  2424.             show(x,y);
  2425.  
  2426.     if (   (strcmp(keyname,"h")      == 0    ||
  2427.         strcmp(keyname,"H")      == 0    ||
  2428.             strcmp(keyname,"CTRLM")   == 0)    &&
  2429.         hint<HINTS)
  2430.         if (game[x][y].board     != 9)
  2431.             {
  2432.             expose(x,y);
  2433.             hint++;
  2434.             }
  2435.         else    if (game[x][y].cover    != 'F')
  2436.             {
  2437.             flag(x,y);
  2438.             hint++;
  2439.             }
  2440.  
  2441.     if (    strcmp(keyname,"d")      == 0    ||
  2442.         strcmp(keyname,"D")     == 0    ||
  2443.             strcmp(keyname,"E5")     == 0)
  2444.         {
  2445.         if (game[x][y].cover     != ' ')
  2446.             {
  2447.                     if (x==0 && y==0)
  2448.             count=
  2449.               (game[x+1][y].cover == 'F')+
  2450.               (game[x][y+1].cover == 'F')+
  2451.               (game[x+1][y+1].cover == 'F');
  2452.                     if (x>0 && x<XSIZE-1 && y==0)
  2453.             count=
  2454.               (game[x-1][y].cover == 'F')+
  2455.               (game[x+1][y].cover == 'F')+
  2456.               (game[x-1][y+1].cover == 'F')+
  2457.               (game[x][y+1].cover == 'F')+
  2458.               (game[x+1][y+1].cover == 'F');
  2459.                     if (x==XSIZE-1 && y==0)
  2460.             count=
  2461.               (game[x-1][y].cover == 'F')+
  2462.               (game[x-1][y+1].cover == 'F')+
  2463.               (game[x][y+1].cover == 'F');
  2464.                     if (x==0 && y>0 && y<YSIZE-1)
  2465.             count=
  2466.               (game[x][y-1].cover == 'F')+
  2467.               (game[x+1][y-1].cover == 'F')+
  2468.               (game[x+1][y].cover == 'F')+
  2469.               (game[x][y+1].cover == 'F')+
  2470.               (game[x+1][y+1].cover == 'F');
  2471.             if (x>0 && x<XSIZE-1 && y>0 && y<YSIZE-1)
  2472.             count=
  2473.               (game[x-1][y-1].cover == 'F')+
  2474.               (game[x][y-1].cover == 'F')+
  2475.               (game[x+1][y-1].cover == 'F')+
  2476.               (game[x-1][y].cover == 'F')+
  2477.               (game[x+1][y].cover == 'F')+
  2478.               (game[x-1][y+1].cover == 'F')+
  2479.               (game[x][y+1].cover == 'F')+
  2480.               (game[x+1][y+1].cover == 'F');
  2481.             if (x==XSIZE-1 && y>0 && y<YSIZE-1)
  2482.             count=
  2483.               (game[x-1][y-1].cover == 'F')+
  2484.               (game[x][y-1].cover == 'F')+
  2485.               (game[x-1][y].cover == 'F')+
  2486.               (game[x-1][y+1].cover == 'F')+
  2487.               (game[x][y+1].cover == 'F');
  2488.             if (x==0 && y==YSIZE-1)
  2489.             count=
  2490.               (game[x][y-1].cover == 'F')+
  2491.               (game[x+1][y-1].cover == 'F')+
  2492.               (game[x+1][y].cover == 'F');
  2493.             if (x>0 && x<XSIZE-1 && y==YSIZE-1)
  2494.             count=
  2495.               (game[x-1][y-1].cover == 'F')+
  2496.               (game[x][y-1].cover == 'F')+
  2497.               (game[x+1][y-1].cover == 'F')+
  2498.               (game[x-1][y].cover == 'F')+
  2499.               (game[x+1][y].cover == 'F');
  2500.             if (x==XSIZE-1 && y==YSIZE-1)
  2501.             count=
  2502.               (game[x-1][y-1].cover == 'F')+
  2503.               (game[x][y-1].cover == 'F')+
  2504.               (game[x-1][y].cover == 'F');
  2505.             if (game[x][y].board == count)
  2506.                 {
  2507.                 if (x>0 && y>0)
  2508.                     if (game[x-1][y-1].cover == ' ')
  2509.                         if (game[x-1][y-1].board != 9)
  2510.                             expose(x-1,y-1);
  2511.                         else
  2512.                             show(x,y);
  2513.                 if (y>0)
  2514.                     if (game[x][y-1].cover   == ' ')
  2515.                         if (game[x][y-1].board     != 9)
  2516.                             expose(x,y-1);
  2517.                         else
  2518.                              show(x,y);
  2519.                 if (x<XSIZE-1 && y>0)
  2520.                     if (game[x+1][y-1].cover == ' ')
  2521.                         if (game[x+1][y-1].board != 9)
  2522.                             expose(x+1,y-1);
  2523.                         else
  2524.                             show(x,y);
  2525.                 if (x>0)
  2526.                     if (game[x-1][y].cover   == ' ')
  2527.                         if (game[x-1][y].board   != 9)
  2528.                             expose(x-1,y);
  2529.                         else
  2530.                             show(x,y);
  2531.                 if (x<XSIZE-1)
  2532.                     if (game[x+1][y].cover   == ' ')
  2533.                         if (game[x+1][y].board   != 9)
  2534.                             expose(x+1,y);
  2535.                         else
  2536.                             show(x,y);
  2537.                 if (x>0 && y<YSIZE-1)
  2538.                     if (game[x-1][y+1].cover == ' ')
  2539.                         if (game[x-1][y+1].board != 9)
  2540.                             expose(x-1,y+1);
  2541.                         else
  2542.                             show(x,y);
  2543.                 if (y<YSIZE-1)
  2544.                     if (game[x][y+1].cover   == ' ')
  2545.                         if (game[x][y+1].board   != 9)
  2546.                             expose(x,y+1);
  2547.                         else
  2548.                             show(x,y);
  2549.                 if (x<XSIZE-1 && y<YSIZE-1)
  2550.                     if (game[x+1][y+1].cover == ' ')
  2551.                         if (game[x+1][y+1].board != 9)
  2552.                             expose(x+1,y+1);
  2553.                         else
  2554.                             show(x,y);
  2555.                 }
  2556.             }
  2557.         }
  2558.     
  2559.     if (    strcmp(keyname,"f")     == 0    ||
  2560.         strcmp(keyname,"F")     == 0    ||
  2561.         strcmp(keyname,"E6")    == 0)
  2562.         if (game[x][y].cover    == 'F')
  2563.             unflag(x,y);
  2564.         else
  2565.             flag(x,y);
  2566.  
  2567.     if (    (strcmp(keyname,"i")     == 0    ||
  2568.          strcmp(keyname,"I")     == 0    ||
  2569.          strcmp(keyname,"UP")    == 0)    && y > 0)    y = y - 1;
  2570.  
  2571.     if (    (strcmp(keyname,"j")     == 0    ||
  2572.          strcmp(keyname,"J")     == 0    ||
  2573.          strcmp(keyname,"LEFT")  == 0)    && x > 0)    x = x - 1;
  2574.  
  2575.     if (    (strcmp(keyname,"k")     == 0    ||
  2576.          strcmp(keyname,"K")     == 0    ||
  2577.          strcmp(keyname,"DOWN")  == 0)    && y < YSIZE-1)    y = y + 1;
  2578.  
  2579.     if (    (strcmp(keyname,"l")     == 0    ||
  2580.          strcmp(keyname,"L")     == 0    ||
  2581.          strcmp(keyname,"RIGHT") == 0)    && x < XSIZE-1)    x = x + 1;
  2582.  
  2583.     if (     strcmp(keyname,"CTRLW") == 0)
  2584.         {
  2585.         draw();
  2586.         }
  2587.  
  2588.     if (counter == XSIZE*YSIZE - mine_total)
  2589.         {
  2590.         autoflag();
  2591.         }
  2592.  
  2593.     if (real_flag_counter == mine_total)
  2594.         {
  2595.         autoclear();
  2596.         }
  2597.  
  2598.     if (counter + real_flag_counter == XSIZE*YSIZE)
  2599.         {
  2600.         high(1);
  2601.         }
  2602.  
  2603. /*The following is needed for the DEC system service that gets a key.  Will
  2604.   have to be modified to work on non-VAX equipment*/
  2605.  
  2606. /*===================================*/
  2607.     locate (x,y);
  2608.     SMG$READ_KEYSTROKE(&keyid,&key);
  2609.     SMG$KEYCODE_TO_NAME(&key,&name);
  2610.     keyname[strlen(keyname)-strlen(strchr(keyname,' '))] = '\0';
  2611.     if (strcmp(keyname,"")==0) strcpy(keyname," ");
  2612. /*===================================*/
  2613.  
  2614.     }
  2615. }
  2616.  
  2617.