/* * Funcion de entrada de datos * Se controla que las notas esten en el rango definido 0 y 10 */ int input_data(char *nombre[ALUMNOS], int *notas[ALUMNOS][PRUEBAS]) { int a, b,c, n; cls(); initscreen(); //Introduccion de datos for(a=0;a<ALUMNOS;a++) { printf("\nIntroduzca el nombre del alumno: "); scanf("%ms", &nombre[a]); pause(); for(b=0;b<PRUEBAS ;b++) { printf("\n Alumno: [ %s ] introduzca la calificacion de la Prueba %d: ", nombre[a], b+1); scanf("%d", ¬as[a][b]); n=notas[a][b]; if(n<0 ||n>10) { printf("Error en la nota, los valores tiene que estar comprendidos entre 0 y 10"); b--; } } } return 1; }
void checktermsize(void) { int notok; struct winsize win; updatecontext(); notok = 0; if (gdata.background == 2) return; if ((ioctl(0, TIOCGWINSZ, &win) == 0) && win.ws_col && win.ws_row) { if (gdata.termcols != win.ws_col) notok++; if (gdata.termlines != win.ws_row) notok++; if (notok) { gdata.termcols = win.ws_col; gdata.termlines = win.ws_row; initscreen(0, 0); if (!gdata.attop) gototop(); tostdout("** Window Size Changed To: %ux%u\n", gdata.termcols, gdata.termlines); gotobot(); } } }
int main(int argc, char **argv) { fd_set rfds; struct timeval tv; int retval; int fd; unsigned long mode; lirc_t data; lirc_t x1,y1,x2,y2; int result; char textbuffer[80]; int div=5; int dmode=0; struct stat s; char *device=LIRC_DRIVER_DEVICE; char *progname; progname="xmode2"; while(1) { int c; static struct option long_options[] = { {"help",no_argument,NULL,'h'}, {"version",no_argument,NULL,'v'}, {"device",required_argument,NULL,'d'}, {"timediv",required_argument,NULL,'t'}, {"mode",required_argument,NULL,'m'}, {0, 0, 0, 0} }; c = getopt_long(argc,argv,"hvd:t:m",long_options,NULL); if(c==-1) break; switch (c) { case 'h': printf("Usage: %s [options]\n",progname); printf("\t -h --help\t\tdisplay usage summary\n"); printf("\t -v --version\t\tdisplay version\n"); printf("\t -d --device=device\tread from given device\n"); printf("\t -t --timediv=value\tms per unit\n"); printf("\t -m --mode\t\tenable alternative display mode\n"); return(EXIT_SUCCESS); case 'v': printf("%s %s\n",progname, VERSION); return(EXIT_SUCCESS); case 'd': device=optarg; break; case 't': /* timediv */ div = strtol(optarg,NULL,10); break; case 'm': dmode=1; break; default: printf("Usage: %s [options]\n",progname); return(EXIT_FAILURE); } } if (optind < argc-1) { fprintf(stderr,"%s: too many arguments\n",progname); return(EXIT_FAILURE); } fd=open(device,O_RDONLY); if(fd==-1) { perror(progname); fprintf(stderr,"%s: error opening %s\n",progname,device); exit(EXIT_FAILURE); }; if ( (fstat(fd,&s)!=-1) && (S_ISFIFO(s.st_mode)) ) { /* can't do ioctls on a pipe */ } else if(ioctl(fd,LIRC_GET_REC_MODE,&mode)==-1 || mode!=LIRC_MODE_MODE2) { printf("This program is only intended for receivers " "supporting the pulse/space layer.\n"); printf("Note that this is no error, but this program simply " "makes no sense for your\nreceiver.\n"); close(fd); exit(EXIT_FAILURE); } initscreen(); y1=20; x1=x2=0; sprintf(textbuffer,"%d ms/unit",div); for (y2=0;y2<w1_w;y2+=10) XDrawLine(d1,w1,gc1,y2,0,y2,w1_h); XDrawString(d1,w1,gc2,w1_w-100,10,textbuffer,strlen(textbuffer)); XFlush(d1); while(1) { if (XCheckWindowEvent(d1, w1, KeyPressMask|StructureNotifyMask, &event_return1)) { switch(event_return1.type) { case KeyPress: if (event_return1.xkey.keycode==XKeysymToKeycode(d1,XStringToKeysym("q"))) { closescreen(); exit(1); } break; case ConfigureNotify: w1_w=event_return1.xconfigure.width; w1_h=event_return1.xconfigure.height; for (y2=0;y2<w1_w;y2+=10) XDrawLine(d1,w1,gc1,y2,0,y2,w1_h); XDrawString(d1,w1,gc2,w1_w-100,10,textbuffer,strlen(textbuffer)); // printf("resize \n"); break; default: ; } } /* Watch stdin (fd 0) to see when it has input. */ FD_ZERO(&rfds); FD_SET(fd, &rfds); /* Wait up to one second. */ tv.tv_sec = 1; tv.tv_usec = 0; retval = select(fd+1, &rfds, NULL, NULL, &tv); if (FD_ISSET(fd,&rfds)) { result=read(fd,&data,sizeof(data)); if (result!=0) { // printf("%.8x\t",data); x2=(data&PULSE_MASK)/(div*50); if(x2>400) { if(!dmode) { y1+=15; } else { y1++; } x1=0; } else { if (x1==0) { if(!dmode) XDrawLine(d1,w1,gc2,x1, y1+10, x1+10, y1+10); x1+=10; if(!dmode) XDrawLine(d1,w1,gc2,x1, y1+10, x1, y1); } if (x1<w1_w) { if(dmode) { if(data&PULSE_BIT) XDrawLine(d1,w1,gc2,x1,y1,x1+x2,y1); x1+=x2; } else { XDrawLine(d1,w1,gc2,x1, ((data&PULSE_BIT) ? y1:y1+10),x1+x2, ((data&PULSE_BIT) ? y1:y1+10)); x1+=x2; XDrawLine(d1,w1,gc2,x1, ((data&PULSE_BIT) ? y1:y1+10),x1, ((data&PULSE_BIT) ? y1+10:y1)); } } } if (y1>w1_h) { y1=20; XClearWindow(d1,w1); for (y2=0;y2<w1_w;y2+=10) XDrawLine(d1,w1,gc1,y2,0,y2,w1_h); XDrawString(d1,w1,gc2,w1_w-100,10,textbuffer,strlen(textbuffer)); } } } // gl_copyscreen(physicalscreen); // XFlush(d1); }; exit(EXIT_SUCCESS); }
initialize() { register struct File *fp; register struct ship *sp; char captain[80]; char message[60]; int load; register int n; char *nameptr; int nat[NNATION]; if (game < 0) { (void) puts("Choose a scenario:\n"); (void) puts("\n\tNUMBER\tSHIPS\tIN PLAY\tTITLE"); for (n = 0; n < NSCENE; n++) { /* ( */ printf("\t%d):\t%d\t%s\t%s\n", n, scene[n].vessels, sync_exists(n) ? "YES" : "no", scene[n].name); } reprint: printf("\nScenario number? "); (void) fflush(stdout); (void) scanf("%d", &game); while (getchar() != '\n') ; } if (game < 0 || game >= NSCENE) { (void) puts("Very funny."); exit(1); } cc = &scene[game]; ls = SHIP(cc->vessels); for (n = 0; n < NNATION; n++) nat[n] = 0; foreachship(sp) { if (sp->file == NULL && (sp->file = (struct File *)calloc(1, sizeof (struct File))) == NULL) { (void) puts("OUT OF MEMORY"); exit(1); } sp->file->index = sp - SHIP(0); sp->file->stern = nat[sp->nationality]++; sp->file->dir = sp->shipdir; sp->file->row = sp->shiprow; sp->file->col = sp->shipcol; } windspeed = cc->windspeed; winddir = cc->winddir; (void) signal(SIGHUP, choke); (void) signal(SIGINT, choke); hasdriver = sync_exists(game); if (sync_open() < 0) { perror("sail: syncfile"); exit(1); } if (hasdriver) { (void) puts("Synchronizing with the other players..."); (void) fflush(stdout); if (Sync() < 0) leave(LEAVE_SYNC); } for (;;) { foreachship(sp) if (sp->file->captain[0] == 0 && !sp->file->struck && sp->file->captured == 0) break; if (sp >= ls) { (void) puts("All ships taken in that scenario."); foreachship(sp) free((char *)sp->file); sync_close(0); people = 0; goto reprint; } if (randomize) { player = sp - SHIP(0); } else { printf("%s\n\n", cc->name); foreachship(sp) printf(" %2d: %-10s %-15s (%-2d pts) %s\n", sp->file->index, countryname[sp->nationality], sp->shipname, sp->specs->pts, saywhat(sp, 1)); printf("\nWhich ship (0-%d)? ", cc->vessels-1); (void) fflush(stdout); if (scanf("%d", &player) != 1 || player < 0 || player >= cc->vessels) { while (getchar() != '\n') ; (void) puts("Say what?"); player = -1; } else while (getchar() != '\n') ; } if (player < 0) continue; if (Sync() < 0) leave(LEAVE_SYNC); fp = SHIP(player)->file; if (fp->captain[0] || fp->struck || fp->captured != 0) (void) puts("That ship is taken."); else break; } ms = SHIP(player); mf = ms->file; mc = ms->specs; Write(W_BEGIN, ms, 0, 0, 0, 0, 0); if (Sync() < 0) leave(LEAVE_SYNC); (void) signal(SIGCHLD, child); if (!hasdriver) switch (fork()) { case 0: longjmp(restart, MODE_DRIVER); /*NOTREACHED*/ case -1: perror("fork"); leave(LEAVE_FORK); break; default: hasdriver++; } printf("Your ship is the %s, a %d gun %s (%s crew).\n", ms->shipname, mc->guns, classname[mc->class], qualname[mc->qual]); if ((nameptr = (char *) getenv("SAILNAME")) && *nameptr) (void) strncpy(captain, nameptr, sizeof captain); else { (void) printf("Your name, Captain? "); (void) fflush(stdout); (void) gets(captain); if (!*captain) (void) strcpy(captain, "no name"); } captain[sizeof captain - 1] = '\0'; Write(W_CAPTAIN, ms, 1, (int)captain, 0, 0, 0); for (n = 0; n < 2; n++) { char buf[10]; printf("\nInitial broadside %s (grape, chain, round, double): ", n ? "right" : "left"); (void) fflush(stdout); (void) scanf("%s", buf); switch (*buf) { case 'g': load = L_GRAPE; break; case 'c': load = L_CHAIN; break; case 'r': load = L_ROUND; break; case 'd': load = L_DOUBLE; break; default: load = L_ROUND; } if (n) { mf->loadR = load; mf->readyR = R_LOADED|R_INITIAL; } else { mf->loadL = load; mf->readyL = R_LOADED|R_INITIAL; } } initscreen(); draw_board(); (void) sprintf(message, "Captain %s assuming command", captain); Write(W_SIGNAL, ms, 1, (int)message, 0, 0, 0); newturn(); }
int main(int argc, char **argv) { int fd; __u32 mode; lirc_t data; lirc_t x1, y1, x2, y2; int result; int c = 10; char textbuffer[80]; int div = 5; char *device = LIRC_DRIVER_DEVICE; char *progname; struct stat s; progname = "smode2"; while (1) { int c; static struct option long_options[] = { {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'v'}, {"device", required_argument, NULL, 'd'}, {"timediv", required_argument, NULL, 't'}, {0, 0, 0, 0} }; c = getopt_long(argc, argv, "hvd:t:", long_options, NULL); if (c == -1) break; switch (c) { case 'h': printf("Usage: %s [options]\n", progname); printf("\t -h --help\t\tdisplay usage summary\n"); printf("\t -v --version\t\tdisplay version\n"); printf("\t -d --device=device\tread from given device\n"); printf("\t -t --timediv=value\tms per unit\n"); return (EXIT_SUCCESS); case 'v': printf("%s %s\n", progname, VERSION); return (EXIT_SUCCESS); case 'd': device = optarg; break; case 't': /* timediv */ div = strtol(optarg, NULL, 10); break; default: printf("Usage: %s [options]\n", progname); return (EXIT_FAILURE); } } if (optind < argc - 1) { fprintf(stderr, "%s: too many arguments\n", progname); return (EXIT_FAILURE); } fd = open(device, O_RDONLY); if (fd == -1) { perror(progname); fprintf(stderr, "%s: error opening %s\n", progname, device); exit(EXIT_FAILURE); }; if ((fstat(fd, &s) != -1) && (S_ISFIFO(s.st_mode))) { /* can't do ioctls on a pipe */ } else if (ioctl(fd, LIRC_GET_REC_MODE, &mode) == -1 || mode != LIRC_MODE_MODE2) { printf("This program is only intended for receivers supporting the pulse/space layer.\n"); printf("Note that this is no error, but this program simply makes no sense for your\nreceiver.\n"); printf("In order to test your setup run lircd with the " "--nodaemon option and \n" "then check if the remote works with the irw tool.\n"); close(fd); exit(EXIT_FAILURE); } initscreen(); y1 = 20; x1 = x2 = 0; for (y2 = 0; y2 < 640; y2 += 20) gl_line(y2, 0, y2, 480, 1); sprintf(textbuffer, "%d ms/unit", div); gl_write(500, 10, textbuffer); gl_copyscreen(physicalscreen); while (1) { result = read(fd, &data, sizeof(data)); if (result == sizeof(data)) { // printf("%.8lx\t",(unsigned long) data); x2 = (data & PULSE_MASK) / (div * 50); if (x2 > 400) { y1 += 15; x1 = 0; gl_copyscreen(physicalscreen); } else { if (x1 < 640) { gl_line(x1, ((data & PULSE_BIT) ? y1 : y1 + 10), x1 + x2, ((data & PULSE_BIT) ? y1 : y1 + 10), c); x1 += x2; gl_line(x1, ((data & PULSE_BIT) ? y1 : y1 + 10), x1, ((data & PULSE_BIT) ? y1 + 10 : y1), c); } } if (y1 > 480) { y1 = 20; gl_clearscreen(0); for (y2 = 0; y2 < 640; y2 += 10) gl_line(y2, 0, y2, 480, 1); gl_write(500, 10, textbuffer); } } // gl_copyscreen(physicalscreen); }; closescreen(); exit(EXIT_SUCCESS); }
int initsystem(void) { int r=0; int i,j; unsigned char m; int cfg[3]; srand(*(int *)0x0040006cL); clrscr(); m=*(unsigned char *)0xf000fffeL; if ((m==0xfe)||(m==0xfb)||(m==0xff)) for(i=0;i<256;i++) codekey[i]=codepcxt[i]; if ((m==0xfc)&&(!testce())) for(i=0;i<256;i++) codekey[i]=codeat[i]; initkbd(); if (bexist("speech.cfg")) { bload("speech.cfg",cfg,0L,6L); sndblast=cfg[0]; dacport=cfg[1]; speaker=cfg[2]; } else { printf("VGA 256Ko card required.\n\n"); printf(" SPEECH.CFG not found. Creating it...\n"); printf(" Erase it if you want to modify speech device.\n\n"); printf(" Please select your speech device:\n\n"); printf("0: no sound\n"); printf("1: internal speaker (only efficient on fast computers)\n"); printf("2: soundblaster card (22ch)\n"); printf("3: soundmaster+ card (22fh)\n"); printf("4: card using 'LPT1' (%xh)\n",*(int *)0x00400008L); printf("5: modify soundblaster base address\n"); printf("6: other DAC port\n"); do { r=getch(); if ((r>47)&&(r<55)) r-=48; else r=-1; } while(r==-1); if (r==1) { dacport=0x42; speaker=1; } if (r==2) { dacport=0x22c; sndblast=1; } if (r==3) dacport=0x22f; if (r==4) dacport=*(int *)0x00400008L; if (r==5) sndblast=1; if (r>4) { if (r==5) printf("soundblaster DAC port is base address + 00c\n"); else printf("Enter your EXACT DAC port (base address + correct offset)\n"); do { printf("Enter your DAC port:"); dacport=0; for(i=0;i<3;i++) { do { r=getch(); if ((r>47)&&(r<58)) r-=48; else if ((r>96)&&(r<103)) r-=87; else if ((r>64)&&(r<71)) r-=55; else r=-1; if (r!=-1) if (r<10) printf("%c",r+48); else printf("%c",r+55); } while(r==-1); dacport=dacport*16+r; } printf("\nIs %xh correct? (Yes/No)\n",dacport); r=getch(); } while((r!='y')&&(r!='Y')); } cfg[0]=sndblast; cfg[1]=dacport; cfg[2]=speaker; bmake("speech.cfg",cfg,6L); } if (initscreen()) { initmouse(); if (sndblast) sendinit(0xd1); if (speaker) inithp(); if (dacport) initspl(); r=1; for(i=0;i<16;i++) for(j=0;j<16;j++) { m=defaultmouse[i*16+j]; plot(j,i,(int)m); if (m==255) plot(j,i+16,0); else plot(j,i+16,255); } initbloc(&mousefond); initbloc(&mousebloc); getbloc(&mousebloc,0,0,16,16); getmask(&mousebloc,0,16); cls(); show(); } else { killkbd(); printf("\nVGA card not found.\n"); } return r; }
int main(int argc, char **argv) { fd_set rfds; int xfd, maxfd; int fd; __u32 mode; lirc_t data; lirc_t x1, y1, x2, y2; int result; char textbuffer[80]; int div = 5; int dmode = 0; struct stat s; int use_stdin = 0; int have_device = 0; int use_raw_access = 0; char *device = LIRC_DRIVER_DEVICE; char *geometry = NULL; progname = "xmode2"; hw_choose_driver(NULL); while (1) { int c; static struct option long_options[] = { {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'v'}, {"device", required_argument, NULL, 'd'}, {"driver", required_argument, NULL, 'H'}, {"geometry", required_argument, NULL, 'g'}, {"timediv", required_argument, NULL, 't'}, {"mode", no_argument, NULL, 'm'}, {"raw", no_argument, NULL, 'r'}, {0, 0, 0, 0} }; c = getopt_long(argc, argv, "hvd:H:g:t:mr", long_options, NULL); if (c == -1) break; switch (c) { case 'h': printf("Usage: %s [options]\n", progname); printf("\t -h --help\t\tdisplay usage summary\n"); printf("\t -v --version\t\tdisplay version\n"); printf("\t -d --device=device\tread from given device\n"); printf("\t -H --driver=driver\t\tuse given driver\n"); printf("\t -g --geometry=geometry\twindow geometry\n"); printf("\t -t --timediv=value\tms per unit\n"); printf("\t -m --mode\t\tenable alternative display mode\n"); printf("\t -r --raw\t\taccess device directly\n"); return (EXIT_SUCCESS); case 'H': if (hw_choose_driver(optarg) != 0) { fprintf(stderr, "Driver `%s' not supported.\n", optarg); hw_print_drivers(stderr); exit(EXIT_FAILURE); } break; case 'v': printf("%s %s\n", progname, VERSION); return (EXIT_SUCCESS); case 'd': device = optarg; have_device = 1; break; case 'g': geometry = optarg; break; case 't': /* timediv */ div = strtol(optarg, NULL, 10); break; case 'm': dmode = 1; break; case 'r': use_raw_access = 1; break; default: printf("Usage: %s [options]\n", progname); return (EXIT_FAILURE); } } if (optind < argc) { fprintf(stderr, "%s: too many arguments\n", progname); return (EXIT_FAILURE); } if (strcmp(device, LIRCD) == 0) { fprintf(stderr, "%s: refusing to connect to lircd socket\n", progname); return EXIT_FAILURE; } if (!isatty(STDIN_FILENO)) { use_stdin = 1; fd = STDIN_FILENO; } else if (use_raw_access) { fd = open(device, O_RDONLY); if (fd == -1) { fprintf(stderr, "%s: error opening %s\n", progname, device); perror(progname); exit(EXIT_FAILURE); }; if ((fstat(fd, &s) != -1) && (S_ISFIFO(s.st_mode))) { /* can't do ioctls on a pipe */ } else if ((fstat(fd, &s) != -1) && (!S_ISCHR(s.st_mode))) { fprintf(stderr, "%s: %s is not a character device\n", progname, device); fprintf(stderr, "%s: use the -d option to specify the correct device\n", progname); close(fd); exit(EXIT_FAILURE); } else if (ioctl(fd, LIRC_GET_REC_MODE, &mode) == -1) { printf("This program is only intended for receivers supporting the pulse/space layer.\n"); printf("Note that this is no error, but this program " "simply makes no sense for your\n" "receiver.\n"); printf("In order to test your setup run lircd with " "the --nodaemon option and \n" "then check if the remote works with the irw tool.\n"); close(fd); exit(EXIT_FAILURE); } } else { if (have_device) hw.device = device; if (!hw.init_func()) { return EXIT_FAILURE; } fd = hw.fd; /* please compiler */ mode = hw.rec_mode; if (mode != LIRC_MODE_MODE2) { if (strcmp(hw.name, "default") == 0) { printf("Please use the --raw option to access " "the device directly instead through\n" "the abstraction layer.\n"); } else { printf("This program does not work for this hardware yet\n"); } exit(EXIT_FAILURE); } } initscreen(geometry); xfd = XConnectionNumber(d1); maxfd = fd > xfd ? fd : xfd; y1 = 20; x1 = x2 = 0; sprintf(textbuffer, "%d ms/unit", div); for (y2 = 0; y2 < w1_w; y2 += 10) XDrawLine(d1, w1, gc1, y2, 0, y2, w1_h); XDrawString(d1, w1, gc2, w1_w - 100, 10, textbuffer, strlen(textbuffer)); XFlush(d1); while (1) { while (XPending(d1) > 0) { XNextEvent(d1, &event_return1); switch (event_return1.type) { case KeyPress: if (event_return1.xkey.keycode == XKeysymToKeycode(d1, XStringToKeysym("q"))) { closescreen(); exit(1); } break; case Expose: case ConfigureNotify: switch (event_return1.type) { case Expose: break; case ConfigureNotify: if (w1_w == event_return1.xconfigure.width && w1_h == event_return1.xconfigure.height) { continue; } w1_w = event_return1.xconfigure.width; w1_h = event_return1.xconfigure.height; break; } XClearWindow(d1, w1); for (y2 = 0; y2 < w1_w; y2 += 10) XDrawLine(d1, w1, gc1, y2, 0, y2, w1_h); XDrawString(d1, w1, gc2, w1_w - 100, 10, textbuffer, strlen(textbuffer)); XFlush(d1); // printf("resize \n"); break; default: ; } } FD_ZERO(&rfds); FD_SET(fd, &rfds); FD_SET(xfd, &rfds); select(maxfd + 1, &rfds, NULL, NULL, NULL); if (FD_ISSET(fd, &rfds)) { if (use_stdin) { static int space = 1; unsigned long scan; if (space) { result = fscanf(stdin, "space %ld\n", &scan); } else { result = fscanf(stdin, "pulse %ld\n", &scan); } if (result == 1) { data = (lirc_t) scan; if (!space) data |= PULSE_BIT; } else { fd = STDOUT_FILENO; } space = !space; } else { result = read(fd, &data, sizeof(data)); } if (result != 0) { // printf("%.8x\t",data); x2 = (data & PULSE_MASK) / (div * 50); if (x2 > 400) { if (!dmode) { y1 += 15; } else { y1++; } x1 = 0; } else { if (x1 == 0) { if (!dmode) XDrawLine(d1, w1, gc2, x1, y1 + 10, x1 + 10, y1 + 10); x1 += 10; if (!dmode) XDrawLine(d1, w1, gc2, x1, y1 + 10, x1, y1); } if (x1 < w1_w) { if (dmode) { if (data & PULSE_BIT) XDrawLine(d1, w1, gc2, x1, y1, x1 + x2, y1); x1 += x2; } else { XDrawLine(d1, w1, gc2, x1, ((data & PULSE_BIT) ? y1 : y1 + 10), x1 + x2, ((data & PULSE_BIT) ? y1 : y1 + 10)); x1 += x2; XDrawLine(d1, w1, gc2, x1, ((data & PULSE_BIT) ? y1 : y1 + 10), x1, ((data & PULSE_BIT) ? y1 + 10 : y1)); } } } if (y1 > w1_h) { y1 = 20; XClearWindow(d1, w1); for (y2 = 0; y2 < w1_w; y2 += 10) XDrawLine(d1, w1, gc1, y2, 0, y2, w1_h); XDrawString(d1, w1, gc2, w1_w - 100, 10, textbuffer, strlen(textbuffer)); } } XFlush(d1); } } exit(EXIT_SUCCESS); }
int main(int argc, char **argv) { struct timeval tv; gettimeofday(&tv, NULL); srand(tv.tv_sec*1000000ULL + tv.tv_usec); if (argc >= 2 && (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0)) { fprintf(stderr, "Usage: %s [width] [height] [nbombs]\n", argv[0]); return 1; } int width = DEF_WIDTH; int height = DEF_HEIGHT; int nbombs = -1; for (int i = 1; i < argc; i++) { int val = atoi(argv[i]); switch (i) { case 1: width = val; break; case 2: height = val; break; case 3: nbombs = val; break; } } if (nbombs == -1) { nbombs = .123 * width * height; } if (nbombs >= width*height) { fprintf(stderr, "nbombs (=%d) more than or equal to width * height (=%d)\n", nbombs, width*height); return 1; } initscreen(); atexit(endscreen); signal(SIGINT, signalend); Board *bd=board_make(width, height, nbombs); Key key; bool quit = false; int repeat = 1; bool have_repeat_num = false; while (!quit) { board_draw(bd); if (board_win(bd)) { char *timestamp; formatTime(×tamp, time(NULL) - bd->startTime); if (!prompt_playagain("You win!", timestamp, height + 2)) { break; } board_destroy(bd); bd = board_make(width, height, nbombs); continue; } getkey(&key); switch (key.type) { case KNUM: if (have_repeat_num) { if (repeat >= (INT_MAX - key.num) / 10) { // would overflow bel(); repeat = 1; have_repeat_num = false; } else { repeat = 10 * repeat + key.num; } } else if (key.num >= 1) { repeat = key.num; have_repeat_num = true; } break; case KARROW: board_shiftcursor(bd, key.dir, repeat); repeat = 1; have_repeat_num = false; break; case KCHAR: switch (key.ch) { case 'q': prompt_quit(height + 2); break; case 'f': board_flag(bd); break; case 'r': board_destroy(bd); bd=board_make(width, height, nbombs); break; case ' ': if (!board_open(bd)) break; board_revealbombs(bd); char *timestamp; formatTime(×tamp, time(NULL) - bd->startTime); if (!prompt_playagain("BOOM!", timestamp, height + 2)) { quit = true; break; } board_destroy(bd); bd = board_make(width, height, nbombs); break; } if (have_repeat_num) bel(); repeat = 1; have_repeat_num = false; break; default: bel(); if (have_repeat_num) bel(); repeat = 1; have_repeat_num = false; break; } } board_destroy(bd); }
void JudgeKey() { int key,a,b,n=0; long m; initscreen(); for(;;) { for(;!kbhit();) /*计时器*/ { gotoxy(56,2); if(t%500==0) m=t/500; cprintf("%ld",m); t++; if(m==MAXTIME) { littlewin(0); JudgeKey(); } delay(100); } /*计时器结束*/ ++n; a=x; b=y; key=bioskey(0); if(key==UP) /*判断按键*/ { if(y==5) continue; gotoxy(x,--y); WIN; } else if(key==DOWN) { if(y==20) continue; else if(y==5&&x!=60) continue; else if(y==7&&x!=50) continue; else if(y==9&&x!=40) continue; else if(y==11&&x!=30) continue; else if(y==13&&x!=20) continue; else if(y==15&&x!=25) continue; else if(y==17&&x!=55) continue; gotoxy(x,++y); WIN; } else if(key==LEFT) { if(x==20) continue; gotoxy(--x,y); WIN; } else if(key==RIGHT) { if(x==60) continue; gotoxy(++x,y); WIN; } else if(key==0x11b) quitgame(1); else continue; /*判断结束*/ cprintf("\1"); /*输出图形*/ gotoxy(a,b); printf(" "); gotoxy(x,y); sound(300); /*输出声音*/ delay(1000); nosound(); } /*输出结果*/ littlewin(1); quitgame(0); }