home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / games / volume14 / mineswpr / part01 < prev    next >
Encoding:
Internet Message Format  |  1992-08-30  |  59.6 KB

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