]> thyrsus.com Git - bs.git/commitdiff
Bug fixes by Eric Sigra.
authorEric S. Raymond <esr@thyrsus.com>
Mon, 7 May 2001 20:27:59 +0000 (20:27 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Mon, 7 May 2001 20:27:59 +0000 (20:27 +0000)
Makefile
bs.c

index 743c626e840d324481888fa6f8df947afa4b8909..955ebd4ad279d828a55cd0ec3938f48ce1c5d3af 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@
 # Note: When the version changes, you also have to change
 #  * the name of the containing directory
 #  * the RPM spec file
-V=2.2
+V=2.3
 
 # Flags for use with the Linux ncurses package (recommended)
 TERMLIB = -lncurses
diff --git a/bs.c b/bs.c
index 1da99d54e6e4d9e66c4e19e346e04ea377f23099..c8a028711d20a6fc7458e5833052d0256cb5b741 100644 (file)
--- a/bs.c
+++ b/bs.c
@@ -7,8 +7,9 @@
  * v2.0 featuring strict ANSI/POSIX conformance, November 1993.
  * v2.1 with ncurses mouse support, September 1995
  * v2.2 code cleanup.
+ * v2.3 bug fixes by Erik Sigra.
  *
- * $Id: bs.c,v 1.22 1997/12/20 15:11:53 tom Exp $
+ * $Id: bs.c,v 1.8 1998/08/14 03:53:19 esr Exp esr $
  */
 
 #include <curses.h>
@@ -311,13 +312,11 @@ static int rnd(int n)
 static void randomplace(int b, ship_t *ss)
 /* generate a valid random ship placement into px,py */
 {
-    register int bwidth = BWIDTH - ss->length;
-    register int bdepth = BDEPTH - ss->length;
 
     do {
-       ss->y = rnd(bdepth);
-       ss->x = rnd(bwidth);
        ss->dir = rnd(2) ? E : S;
+       ss->x = rnd(BWIDTH - (ss->dir == E ? ss->length : 0));
+       ss->y = rnd(BDEPTH - (ss->dir == S ? ss->length : 0));
     } while
        (!checkplace(b, ss, FALSE));
 }
@@ -675,8 +674,8 @@ static bool checkplace(int b, ship_t *ss, int vis)
     int l, xend, yend;
 
     /* first, check for board edges */
-    xend = ss->x + ss->length * xincr[ss->dir];
-    yend = ss->y + ss->length * yincr[ss->dir];
+    xend = ss->x + (ss->length - 1) * xincr[ss->dir];
+    yend = ss->y + (ss->length - 1) * yincr[ss->dir];
     if (!ONBOARD(xend, yend))
     {
        if (vis)
@@ -782,6 +781,11 @@ static ship_t *hitship(int x, int y)
                                    attrset(0);
 #endif /* A_COLOR */
                                }
+                               else
+                               {
+                                 pgoto(y1, x1);
+                                 (void)addch(SHOWSPLASH);
+                               }
                            }
                        }
                    }
@@ -797,6 +801,18 @@ static ship_t *hitship(int x, int y)
                        cgoto(y1, x1);
                        (void) addch((chtype)(ss->symbol));
                    }
+                   else
+                   {
+                     pgoto(y1, x1);
+#ifdef A_COLOR
+                     if (has_colors())
+                       attron(COLOR_PAIR(COLOR_RED));
+#endif /* A_COLOR */
+                     (void)addch(SHOWHIT);
+#ifdef A_COLOR
+                     attrset(0);
+#endif /* A_COLOR */
+                   }
                }
 
                (void) move(oldy, oldx);