X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=test%2Fbs.c;h=ebcabc42d3bfabd7f4b75d747e30e53e60c1bc83;hp=f8784853c7620cf233452089adf655d779685b30;hb=a1e63be290fce9e589bc57c9f753be09e8ac0cc7;hpb=64f44b13d30e0a7bc2921a9d43755423f81564fd diff --git a/test/bs.c b/test/bs.c index f8784853..ebcabc42 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.56 2012/12/08 23:35:58 tom Exp $ + * $Id: bs.c,v 1.59 2012/12/16 00:20:49 tom Exp $ */ #include @@ -110,7 +110,7 @@ static char sub[] = "Submarine"; static char destroy[] = "Destroyer"; static char ptboat[] = "PT Boat"; -static char name[40]; +static char *your_name; static char dftname[] = "stranger"; /* direction constants */ @@ -220,11 +220,12 @@ intro(void) CATCHALL(uninitgame); - if ((tmpname = getlogin()) != 0) { - (void) strcpy(name, tmpname); - name[0] = (char) toupper(UChar(name[0])); - } else - (void) strcpy(name, dftname); + if ((tmpname = getlogin()) != 0 && + (your_name = strdup(tmpname)) != 0) { + your_name[0] = (char) toupper(UChar(your_name[0])); + } else { + your_name = dftname; + } (void) initscr(); keypad(stdscr, TRUE); @@ -955,8 +956,8 @@ cpufire(int x, int y) bool hit, sunk; ship_t *ss = NULL; - hit = board[PLAYER][x][y] ? MARK_HIT : MARK_MISS; - hits[COMPUTER][x][y] = (char) hit; + hit = board[PLAYER][x][y]; + hits[COMPUTER][x][y] = (hit ? MARK_HIT : MARK_MISS); MvPrintw(PROMPTLINE, 0, "I shoot at %c%d. I %s!", y + 'A', x, hit ? "hit" : "miss"); @@ -1133,16 +1134,16 @@ playagain(void) ++cpuwon; else ++plywon; - j = 18 + (int) strlen(name); + j = 18 + (int) strlen(your_name); if (plywon >= 10) ++j; if (cpuwon >= 10) ++j; MvPrintw(1, (COLWIDTH - j) / 2, - "%s: %d Computer: %d", name, plywon, cpuwon); + "%s: %d Computer: %d", your_name, plywon, cpuwon); prompt(2, (awinna())? "Want to be humiliated again, %s [yn]? " - : "Going to give me a chance for revenge, %s [yn]? ", name); + : "Going to give me a chance for revenge, %s [yn]? ", your_name); return (sgetc("YN") == 'Y'); }