]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - test/bs.c
ncurses 6.3 - patch 20220521
[ncurses.git] / test / bs.c
index b8893e6243beba33acf724d4ba33f78b3d3ec91d..0a074bb0b480959c438b6fde141d10c7ccf61874 100644 (file)
--- a/test/bs.c
+++ b/test/bs.c
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 1998-2017,2018 Free Software Foundation, Inc.              *
+ * Copyright 2018-2020,2021 Thomas E. Dickey                                *
+ * Copyright 1998-2016,2017 Free Software Foundation, Inc.                  *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -25,7 +26,7 @@
  * sale, use or other dealings in this Software without prior written       *
  * authorization.                                                           *
  ****************************************************************************/
-/* 
+/*
  * bs.c - original author: Bruce Holloway
  *             salvo option by: Chuck A DeGaul
  * with improved user interface, autoconfiguration and code cleanup
@@ -34,7 +35,7 @@
  * v2.0 featuring strict ANSI/POSIX conformance, November 1993.
  * v2.1 with ncurses mouse support, September 1995
  *
- * $Id: bs.c,v 1.73 2018/05/12 15:07:51 tom Exp $
+ * $Id: bs.c,v 1.77 2021/06/17 21:11:08 tom Exp $
  */
 
 #include <test.priv.h>
@@ -180,7 +181,7 @@ static int salvo, blitz, closepack;
 
 #define        PR      (void)addstr
 
-static void uninitgame(int sig) GCC_NORETURN;
+static GCC_NORETURN void uninitgame(int sig);
 
 static void
 uninitgame(int sig GCC_UNUSED)
@@ -548,14 +549,15 @@ initgame(void)
 static int
 getcoord(int atcpu)
 {
-    int ny, nx, c;
-
     if (atcpu)
        cgoto(cury, curx);
     else
        pgoto(cury, curx);
     (void) refresh();
+
     for (;;) {
+       int ny, nx, c;
+
        if (atcpu) {
            MvPrintw(CYBASE + BDEPTH + 1, CXBASE + 11, "(%d, %c)",
                     curx, 'A' + cury);
@@ -731,10 +733,9 @@ static int
 awinna(void)
 {
     int i, j;
-    ship_t *ss;
 
     for (i = 0; i < 2; ++i) {
-       ss = (i) ? cpuship : plyship;
+       ship_t *ss = (i) ? cpuship : plyship;
        for (j = 0; j < SHIPTYPES; ++j, ++ss)
            if (ss->length > ss->hits)
                break;
@@ -761,9 +762,11 @@ hitship(int x, int y)
            if (++ss->hits < ss->length)        /* still afloat? */
                return ((ship_t *) NULL);
            else {              /* sunk! */
-               int i, j;
+               int i;
+
+               if (!closepack) {
+                   int j;
 
-               if (!closepack)
                    for (j = -1; j <= 1; j++) {
                        int bx = ss->x + j * xincr[(ss->dir + 2) % dir_MAX];
                        int by = ss->y + j * yincr[(ss->dir + 2) % dir_MAX];
@@ -792,6 +795,7 @@ hitship(int x, int y)
                            }
                        }
                    }
+               }
 
                for (i = 0; i < ss->length; ++i) {
                    int x1 = ss->x + i * xincr[ss->dir];
@@ -884,12 +888,12 @@ plyturn(void)
 static int
 sgetc(const char *s)
 {
-    const char *s1;
-    int ch;
-
     (void) refresh();
+
     for (;;) {
-       ch = getch();
+       int ch = getch();
+       const char *s1;
+
        if (islower(ch))
            ch = toupper(ch);
        if (is_QUIT(ch))
@@ -1161,9 +1165,9 @@ playagain(void)
 static void
 do_options(int c, char *op[])
 {
-    register int i;
-
     if (c > 1) {
+       int i;
+
        for (i = 1; i < c; i++) {
            switch (op[i][0]) {
            default: