X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=test%2Fbs.c;h=31f98bb8684dc3754d8976a0bd26ff85c00411da;hp=5959758858e9c7b284806b12140e17a90c3e36e1;hb=d66080c21038ad4feb2e41a0c4e517d5b4a03ab2;hpb=af3d0ee323cbb22d2a7596d564bf68f7307f5076 diff --git a/test/bs.c b/test/bs.c index 59597588..31f98bb8 100644 --- a/test/bs.c +++ b/test/bs.c @@ -34,7 +34,7 @@ * v2.0 featuring strict ANSI/POSIX conformance, November 1993. * v2.1 with ncurses mouse support, September 1995 * - * $Id: bs.c,v 1.68 2017/06/17 18:45:40 tom Exp $ + * $Id: bs.c,v 1.71 2017/10/18 23:03:07 tom Exp $ */ #include @@ -64,6 +64,8 @@ static int getcoord(int); #define CTRLC '\003' /* used as terminate command */ #define FF '\014' /* used as redraw command */ +#define is_QUIT(c) ((c) == CTRLC || (c) == QUIT) + /* coordinate handling */ #define BWIDTH 10 #define BDEPTH 10 @@ -145,6 +147,7 @@ static bool checkplace(int b, ship_t * ss, int vis); #define SHIPIT(name, symbol, length) { name, 0, symbol, length, 0,0, 0, FALSE } +/* "ply=player", "cpu=computer" */ static ship_t plyship[SHIPTYPES] = { SHIPIT(carrier, 'A', 5), @@ -219,8 +222,7 @@ intro(void) srand((unsigned) (time(0L) + getpid())); /* Kick the random number generator */ - CATCHALL(uninitgame); - (void) initscr(); + InitAndCatch(initscr(), uninitgame); if ((tmpname = getlogin()) != 0 && (your_name = strdup(tmpname)) != 0) { @@ -462,9 +464,11 @@ initgame(void) do { c = (char) getch(); } while - (!(strchr("hjkl8462rR", c) || c == FF)); + (!(strchr("hjkl8462rR", c) || c == FF || is_QUIT(c))); - if (c == FF) { + if (is_QUIT(c)) { + uninitgame(0); + } else if (c == FF) { (void) clearok(stdscr, TRUE); (void) refresh(); } else if (ss == 0) { @@ -885,7 +889,7 @@ sgetc(const char *s) ch = getch(); if (islower(ch)) ch = toupper(ch); - if (ch == CTRLC) + if (is_QUIT(ch)) uninitgame(0); for (s1 = s; *s1 && ch != *s1; ++s1) continue; @@ -1158,7 +1162,7 @@ do_options(int c, char *op[]) switch (op[i][0]) { default: case '?': - (void) fprintf(stderr, "Usage: battle [-s | -b] [-c]\n"); + (void) fprintf(stderr, "Usage: bs [-s | -b] [-c]\n"); (void) fprintf(stderr, "\tWhere the options are:\n"); (void) fprintf(stderr, "\t-s : play a salvo game\n"); (void) fprintf(stderr, "\t-b : play a blitz game\n");