static int sgetc(const char *s) { const char *s1; int ch; refresh(); for(;;) { ch = getch(); if (islower(ch)) ch = toupper(ch); if (ch == CTRLC) uninitgame(); for (s1=s; *s1 && ch != *s1; ++s1) continue; if (*s1) { addch((chtype)ch); refresh(); return(ch); } } }
int main(int argc, char *argv[]) { if (pledge("stdio rpath tty", NULL) == -1) err(1, "pledge"); do_options(argc, argv); intro(); do { initgame(); while(awinna() == -1) { if (!blitz) { if (!salvo) { if(turn) (void) cputurn(); else (void) plyturn(); } else /* salvo */ { int i; i = scount(turn); while (i--) { if (turn) { if (cputurn() && awinna() != -1) i = 0; } else { if (plyturn() && awinna() != -1) i = 0; } } } } else /* blitz */ while(turn ? cputurn() : plyturn()) { if (turn) /* Pause between successive computer shots */ { (void)refresh(); (void)sleep(1); } if (awinna() != -1) break; } turn = OTHER; } } while (playagain()); uninitgame(0); return 0; }
int main(int argc, char *argv[]) { setlocale(LC_ALL, ""); do_options(argc, argv); intro(); do { initgame(); while (awinna() == -1) { if (!blitz) { if (!salvo) { if (turn) (void) cputurn(); else (void) plyturn(); } else { register int i; i = scount(turn); while (i--) { if (turn) { if (cputurn() && awinna() != -1) i = 0; } else { if (plyturn() && awinna() != -1) i = 0; } } } } else while ((turn ? cputurn() : plyturn()) && awinna() == -1) continue; turn = OTHER; } } while (playagain()); uninitgame(0); /*NOTREACHED */ }
int main(int argc, char **argv) { do_options(argc, argv); intro(); do { initgame(); while(awinna() == -1) { if (!blitz) { if (!salvo) { if (turn) cputurn(); else plyturn(); } else { register int i; i = scount(turn); while (i--) { if (turn) if (cputurn()) if (awinna() != -1) i = 0; else if(plyturn()) if (awinna() != -1) i = 0; } } } else { while((turn) ? cputurn() : plyturn()); } turn = OTHER; } } while(playagain()); uninitgame(); exit(0); }
static void sighandler(__unused int sig) { uninitgame(); }
int main(int argc, char **argv) { int ch; /* revoke */ setgid(getgid()); while ((ch = getopt(argc, argv, "bsc")) != -1) { switch (ch) { case 'b': blitz = 1; break; case 's': salvo = 1; break; case 'c': closepack = 1; break; case '?': default: usage(); } } argc -= optind; argv += optind; if (blitz && salvo) usage(); intro(); do { initgame(); while(awinna() == -1) { if (blitz) { while(turn ? cputurn() : plyturn()) continue; } else if (salvo) { int i; i = scount(turn); while (i--) { if (turn) { if (cputurn() && awinna() != -1) i = 0; } else { if (plyturn() && awinna() != -1) i = 0; } } } else { /* Normal game */ if(turn) cputurn(); else plyturn(); } turn = OTHER; } } while (playagain()); uninitgame(); exit(0); }
static int getcoord(int atcpu) { int ny, nx, c; if (atcpu) cgoto(cury,curx); else pgoto(cury, curx); (void)refresh(); for (;;) { if (atcpu) { (void) mvprintw(CYBASE + BDEPTH+1, CXBASE+11, "(%d, %c)", curx, 'A'+cury); cgoto(cury, curx); } else { (void) mvprintw(PYBASE + BDEPTH+1, PXBASE+11, "(%d, %c)", curx, 'A'+cury); pgoto(cury, curx); } switch(c = getch()) { case 'k': case '8': case KEY_UP: ny = cury+BDEPTH-1; nx = curx; break; case 'j': case '2': case KEY_DOWN: ny = cury+1; nx = curx; break; case 'h': case '4': case KEY_LEFT: ny = cury; nx = curx+BWIDTH-1; break; case 'l': case '6': case KEY_RIGHT: ny = cury; nx = curx+1; break; case 'y': case '7': case KEY_A1: ny = cury+BDEPTH-1; nx = curx+BWIDTH-1; break; case 'b': case '1': case KEY_C1: ny = cury+1; nx = curx+BWIDTH-1; break; case 'u': case '9': case KEY_A3: ny = cury+BDEPTH-1; nx = curx+1; break; case 'n': case '3': case KEY_C3: ny = cury+1; nx = curx+1; break; case FF: nx = curx; ny = cury; (void)clearok(stdscr, TRUE); (void)refresh(); break; case KEY_MOUSE: { MEVENT myevent; getmouse(&myevent); if (atcpu && myevent.y >= CY(0) && myevent.y < CY(BDEPTH) && myevent.x >= CX(0) && myevent.x < CX(BWIDTH)) { curx = CXINV(myevent.x); cury = CYINV(myevent.y); return(' '); } else beep(); } break; case ERR: uninitgame(1); break; default: if (atcpu) (void) mvaddstr(CYBASE + BDEPTH + 1, CXBASE + 11, " "); else (void) mvaddstr(PYBASE + BDEPTH + 1, PXBASE + 11, " "); return(c); } curx = nx % BWIDTH; cury = ny % BDEPTH; } }