fxejo@acad3.alaska.edu (05/27/91)
I'm sorry if anyone has seen this before; my news reader is behaving strangely. Bomb is a simple game in which you deduce where bombs are hidden in a grid, and move around them. This is a unix-style shar file, but it does compile easily on vms, as well. (At least, it did for me.) #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh <file", e.g.. If this archive is complete, you # will see the following message at the end: # "End of shell archive." # Contents: Readme.bomb bomb.c build_vms.com makefile # Wrapped by ejo@hayes on Sun May 26 12:21:34 1991 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f 'Readme.bomb' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'Readme.bomb'\" else echo shar: Extracting \"'Readme.bomb'\" \(1249 characters\) sed "s/^X//" >'Readme.bomb' <<'END_OF_FILE' XBomb is a simple game of deduction. There is a 16x16 grid containing Xsome number of bombs (the default is 30) which you must move through. XEach sector is denoted by a number from 1 to 8 representing the number Xof bombs immediately adjacent to it, a space (if there are no bombs Xadjacent to it), or a period (if you haven't been there yet). You may Xplace a guess as to what a given sector is by positioning the cursor Xon it (with the number keys) and pressing the space bar; this will Xtoggle the sector's classification between unknown (.), bomb (*), and Xokay (o). You start in the upper left hand corner and the object is Xto work your way into the lower right hand corner. If you believe a Xsector to be safe, you can move into it by pressing return. Control-l Xwill redraw the screen. If you move into a sector which does not Xborder on any bombs, the computer will automatically move into each Xsector around it. You may only move into sectors adjacent to sectors Xyou have already visited. There are never any bombs bordering on your Xstarting square. X XBomb compiles and runs successfully for the following operating systems: X XSunOS 4.1, Ultrix 4.1, and VAX/VMS. X XIf you compile bomb successfully on another machine, please add it to Xthe list. END_OF_FILE if test 1249 -ne `wc -c <'Readme.bomb'`; then echo shar: \"'Readme.bomb'\" unpacked with wrong size! fi # end of 'Readme.bomb' fi if test -f 'bomb.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'bomb.c'\" else echo shar: Extracting \"'bomb.c'\" \(4575 characters\) sed "s/^X//" >'bomb.c' <<'END_OF_FILE' X/* bomb.c, by Eric Olson. */ X/* version 1.0 */ X/* This program is copyright 1991 by Eric Olson. You are welcome to X distribute it, but this notice should remain intact and you should X include all the files that were distributed with it. This program is X not to be sold, although a fee may be charged to cover distribution X expenses (if there are any). If you wish to modify the code and X distribute it, please feel free to do so, but label the code as X modified here and change the version accordingly. */ X X#include <stdio.h> X#include <curses.h> X X#ifdef VMS Xunsigned char _getch() /* kent d ramier 20 feb 88 */ /* eo ruined spacing */ X { struct { unsigned short length; unsigned char dtype; unsigned char X class; char *pointer; } device = { 9, 14, 1, "SYS$INPUT"}; static X unsigned short a_channel = 0; unsigned char the_key; if (!(a_channel)) X SYS$ASSIGN(&device,&a_channel,0,0); SYS$QIOW X (0,a_channel,625,0,0,0,&the_key,1,1,0,0,0); return(the_key); } X# define GETCH (_getch()) X#else X /* if you're not on VAX/VMS, you may need to refit this. */ X /* it does occasionally leave numbers on my screen. */ X# define GETCH (getch()) X#endif VMS X X#define MAX 16 /* boardsize */ X X/* this is a terrible random generator. Make a better one. */ X#include <math.h> X#include <time.h> X#define RANDOM ((int)((float)rand()/((float)((unsigned)(-1)))*2.0*(float)(MAX))) X#define RANDOM_SEED srand(time((time_t *)0)) X Xshort think[MAX][MAX],grid[MAX][MAX],boom; Xint xx=0,yy=0; X X#define NOTYET 9 X#define BOMB 10 X#define OKAY 11 Xstatic char icon[]=" 12345678.*o"; X Xdrawscr() X{ Xint i,j; X Xfor (i=0;i<MAX;i++) X for (j=0;j<MAX;j++) X { X move(j,i*2); X/* printw("(%c)",icon[think[i][j]]); */ X printw(" %c",icon[think[i][j]]); X } X/* mvaddch(yy,xx*2+1,'#'); Xmvaddch(yy,xx*2,'['); mvaddch(yy,xx*2+2,']'); Xmvaddch(yy,xx*2,'>'); */ X} X Xshort invalid(i,j) Xint i,j; X{ X if ((i==j) && ((i==0) || (i==MAX-1))) return (1); X if ((i<2) && (j<2)) return (1); X if ((i==MAX) || (j==MAX)) return (1); X if (grid[i][j]) return (1); X return (0); X} X Xanalyze(x,y) Xint x,y; X{ Xint i,j,t=0; X Xfor (i= -1;i<2;i++) X for (j= -1;j<2;j++) X if ((i+x>=0) && (j+y>=0) && (i+x<MAX) && (j+y<MAX)) X if (grid[i+x][j+y]) t++; Xthink[x][y]=t; Xif (!t) X for (i= -1;i<2;i++) X for (j= -1;j<2;j++) X if ((i+x>=0) && (j+y>=0) && (i+x<MAX) && (j+y<MAX)) X if (think[i+x][j+y]==NOTYET) analyze(i+x,j+y); X} X Xtoggle(x,y) Xint x,y; X{ Xswitch (think[x][y]) X { X case NOTYET: think[x][y]=BOMB; break; X case BOMB: think[x][y]=OKAY; break; X case OKAY: think[x][y]=NOTYET; break; X } X} X Xmoveto(x,y) X{ Xint i,j,q=0; X Xfor (i= -1;i<2;i++) X for (j= -1;j<2;j++) X if ((i+x>=0) && (i+x<MAX) && (j+y<MAX) && (j+y>=0)) X if (think[i+x][j+y]<NOTYET) q=1; Xif (!q) return(0); X Xxx=x; yy=y; analyze(x,y); X Xif (grid[x][y]) boom=2; Xif ((y==MAX-1) && (x==MAX-1)) boom=1; X} X Xmain(argc,argv) Xint argc; char **argv; X{ Xint i,j,k,nb=30; Xchar c; X Xif (argc>1) X { X sscanf(argv[1],"%d",&nb); X if ((nb<1) || (nb>(MAX*(MAX-2)))) X { X printf ("Invalid number of bombs."); exit(0); X } X } X Xinitscr(); XRANDOM_SEED; X Xfor (i=0;i<MAX;i++) X for (j=0;j<MAX;j++) X think[i][j]=NOTYET,grid[i][j]=0; Xfor (k=0;k<nb;k++) X { X for (i=j=0;invalid(i,j);) X i=RANDOM,j=RANDOM; X grid[i][j]=1; X } X Xanalyze(0,0); Xprintf("%c>",27); X Xfor (i=j=boom=0;!boom;) X { X drawscr(); X move(j,i*2+1); refresh(); X c=GETCH; X switch (c) X { X case '1': i--; X case '2': j++; break; X case '7': j--; X case '4': i--; break; X case '9': i++; X case '8': j--; break; X case '3': j++; X case '6': i++; break; X case ' ': toggle(i,j); break; X case 12: clear(); refresh(); break; X /* case '\n': */ case 13: case 10: moveto(i,j); X default: break; X } X if (i<0) i=0; if (i>=MAX) i=MAX-1; if (j<0) j=0; if (j>=MAX) j=MAX-1; X } X Xendwin(); Xif (boom==1) printf ("Good job!\n"); Xelse printf ("***BOOM***\n"); Xfor (j=0;j<MAX;j++,printf("\n")) X for (i=0;i<MAX;i++) X { X if (think[i][j]<NOTYET) X if (grid[i][j]) printf ("* "); X else printf ("o "); X else X if (think[i][j]==NOTYET) X if (grid[i][j]) X printf ("*. "); X else printf ("o. "); X else X if (think[i][j]==BOMB) X if (grid[i][j]) X printf ("*! "); X else printf ("o? "); X else X if (grid[i][j]) X printf ("*? "); X else printf ("o! "); X } Xprintf ("\n*=bomb, o=okay .=no guess, !=right, ?=wrong\n\n"); X} END_OF_FILE if test 4575 -ne `wc -c <'bomb.c'`; then echo shar: \"'bomb.c'\" unpacked with wrong size! fi # end of 'bomb.c' fi if test -f 'build_vms.com' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'build_vms.com'\" else echo shar: Extracting \"'build_vms.com'\" \(93 characters\) sed "s/^X//" >'build_vms.com' <<'END_OF_FILE' X$ cc bomb X$ link bomb+sys$input/opt Xsys$share:vaxctrl/share X$ delete bomb.obj; X$ pu bomb.exe END_OF_FILE if test 93 -ne `wc -c <'build_vms.com'`; then echo shar: \"'build_vms.com'\" unpacked with wrong size! fi # end of 'build_vms.com' fi if test -f 'makefile' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'makefile'\" else echo shar: Extracting \"'makefile'\" \(237 characters\) sed "s/^X//" >'makefile' <<'END_OF_FILE' X# makefile for bomb X# XCC= cc X X# your system may not require termlib to be loaded XLIBRARIES= -lm -lcurses -ltermlib X X# use -g for debugging, if necessary XFLAGS= -O X Xdefault: bomb X Xbomb: bomb.c X $(CC) $(FLAGS) -o bomb bomb.c $(LIBRARIES) X END_OF_FILE if test 237 -ne `wc -c <'makefile'`; then echo shar: \"'makefile'\" unpacked with wrong size! fi # end of 'makefile' fi echo shar: End of shell archive. exit 0