static void maineventloop (void) { EventRecord ev; while (!flexitmainloop) { WaitNextEvent (everyEvent, &ev, 2, nil); handleevent (&ev); } /*while*/ } /*maineventloop*/
int main(int argc,char **argv) { GR_COORD x; GR_COORD y; GR_SIZE width; GR_SIZE height; GR_COORD rightx; /* x coordinate for right half stuff */ GR_BOOL setsize; /* TRUE if size of board is set */ GR_BOOL setmines; /* TRUE if number of mines is set */ GR_SIZE newsize = 10; /* desired size of board */ GR_COUNT newmines = 25; /* desired number of mines */ GR_WM_PROPERTIES props; setmines = GR_FALSE; setsize = GR_FALSE; argc--; argv++; while ((argc > 0) && (**argv == '-')) { switch (argv[0][1]) { case 'm': if (argc <= 0) { fprintf(stderr, "Missing mine count\n"); exit(1); } argc--; argv++; newmines = atoi(*argv); setmines = GR_TRUE; break; case 's': if (argc <= 0) { fprintf(stderr, "Missing size\n"); exit(1); } argc--; argv++; newsize = atoi(*argv); setsize = GR_TRUE; break; default: fprintf(stderr, "Unknown option \"-%c\"\n", argv[0][1]); exit(1); } argc--; argv++; } if (argc > 0) savefile = *argv; srand(time(0)); readgame(savefile); if (setsize) { if ((newsize < MINSIZE) || (newsize > MAXSIZE)) { fprintf(stderr, "Illegal board size\n"); exit(1); } if (newsize != size) { if (steps && playing) { fprintf(stderr, "Cannot change size while game is in progress\n"); exit(1); } playing = GR_FALSE; size = newsize; if (!playing) mines = (size * size * MINEPERCENT) / 100; } } if (setmines) { if ((newmines <= 0) || ((newmines > (size * size) / 2))) { fprintf(stderr, "Illegal number of mines\n"); exit(1); } if (newmines != mines) { if (steps && playing) { fprintf(stderr, "Cannot change mines while game is in progress\n"); exit(1); } playing = GR_FALSE; mines = newmines; } } findindex(); /* * Parameters of the game have been verified. * Now open the graphics and play the game. */ if (GrOpen() < 0) { fprintf(stderr, "Cannot open graphics\n"); exit(1); } GrReqShmCmds(655360); /* Test by Morten Rolland for shm support */ GrGetScreenInfo(&si); GrGetFontInfo(0, &fi); charheight = fi.height; /* * Create the main window which will contain all the others. */ #if 0 COLS = si.cols - 40; #else COLS = si.cols; #endif ROWS = si.rows - 80; mainwid = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, COLS, ROWS, 0, BLACK, WHITE); /* set title */ props.flags = GR_WM_FLAGS_TITLE | GR_WM_FLAGS_PROPS; props.props = GR_WM_PROPS_APPFRAME | GR_WM_PROPS_CAPTION; props.title = "Land Mine"; GrSetWMProperties(mainwid, &props); /* * Create the board window which lies at the left side. * Make the board square, and as large as possible while still * leaving room to the right side for statistics and buttons. */ width = COLS - RIGHTSIDE - (si.xdpcm * RIGHTGAP / 10) - BOARDBORDER * 2; height = (((long) width) * si.ydpcm) / si.xdpcm; if (height > ROWS /* - y * 2*/) { height = ROWS - BOARDBORDER * 2; width = (((long) height) * si.xdpcm) / si.ydpcm; } xp = width / size; yp = height / size; width = xp * size - 1; height = yp * size - 1; x = BOARDBORDER; y = (ROWS - height) / 2; rightx = x + width + (si.xdpcm * RIGHTGAP / 10); boardwid = GrNewWindow(mainwid, x, y, width, height, BOARDBORDER, BLUE, WHITE); /* * Create the buttons. */ x = rightx; y = (si.ydpcm * BOARDGAP / 10); quitwid = GrNewWindow(mainwid, x, y, BUTTONWIDTH, BUTTONHEIGHT, 1, RED, WHITE); y += (si.ydpcm * BUTTONGAP / 10); savewid = GrNewWindow(mainwid, x, y, BUTTONWIDTH, BUTTONHEIGHT, 1, GREEN, WHITE); y += (si.ydpcm * BUTTONGAP / 10); newgamewid = GrNewWindow(mainwid, x, y, BUTTONWIDTH, BUTTONHEIGHT, 1, GREEN, WHITE); /* * Create the statistics window. */ x = rightx; y += (si.ydpcm * STATUSGAP / 10); width = COLS - x; height = ROWS - y; statwid = GrNewWindow(mainwid, x, y, width, height, 0, 0, 0); statwidth = width; statheight = height; /* * Create the GC for drawing the board. */ boardgc = GrNewGC(); cleargc = GrNewGC(); delaygc = GrNewGC(); redgc = GrNewGC(); greengc = GrNewGC(); statgc = GrNewGC(); blackgc = GrNewGC(); buttongc = GrNewGC(); xorgc = GrNewGC(); GrSetGCBackground(boardgc, BLUE); GrSetGCForeground(cleargc, BLUE); GrSetGCForeground(redgc, RED); GrSetGCForeground(greengc, GREEN); GrSetGCForeground(statgc, GRAY); GrSetGCForeground(delaygc, BLACK); GrSetGCForeground(blackgc, BLACK); GrSetGCMode(delaygc, GR_MODE_XOR); GrSetGCMode(xorgc, GR_MODE_XOR); GrSetGCUseBackground(boardgc, GR_FALSE); GrSetGCUseBackground(buttongc, GR_FALSE); GrSelectEvents(mainwid, GR_EVENT_MASK_CLOSE_REQ); GrSelectEvents(boardwid, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_KEY_DOWN); GrSelectEvents(statwid, GR_EVENT_MASK_EXPOSURE); GrSelectEvents(quitwid, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN); GrSelectEvents(newgamewid, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN); GrSelectEvents(savewid, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN); setcursor(); GrMapWindow(mainwid); GrMapWindow(boardwid); GrMapWindow(statwid); GrMapWindow(quitwid); GrMapWindow(savewid); GrMapWindow(newgamewid); if (!playing) newgame(); while (GR_TRUE) { GR_EVENT event; GrGetNextEvent(&event); handleevent(&event); } }