summaryrefslogtreecommitdiffstats
path: root/worm
diff options
context:
space:
mode:
authorjsm <jsm@NetBSD.org>2001-08-31 07:15:44 +0000
committerjsm <jsm@NetBSD.org>2001-08-31 07:15:44 +0000
commitdc5073e330c76cc92c679f0aa3aae6fe8218b1dd (patch)
tree6ece9418891d1c00ac37233ee1202bec800a02cb /worm
parent897cec3b3cb65e3e1fa957369f64c2b106708d5c (diff)
downloadbsdgames-darwin-dc5073e330c76cc92c679f0aa3aae6fe8218b1dd.tar.gz
bsdgames-darwin-dc5073e330c76cc92c679f0aa3aae6fe8218b1dd.tar.zst
bsdgames-darwin-dc5073e330c76cc92c679f0aa3aae6fe8218b1dd.zip
Keep track of visible worm length. If nowhere is available for the
new prize, have the player win rather than hanging. Bug reported by Malcolm Parsons <malcolm@ivywell.screaming.net>.
Diffstat (limited to 'worm')
-rw-r--r--worm/worm.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/worm/worm.c b/worm/worm.c
index 67dfc20f..19e697ec 100644
--- a/worm/worm.c
+++ b/worm/worm.c
@@ -1,4 +1,4 @@
-/* $NetBSD: worm.c,v 1.21 2001/08/30 10:49:50 jsm Exp $ */
+/* $NetBSD: worm.c,v 1.22 2001/08/31 07:15:44 jsm Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1993\n\
#if 0
static char sccsid[] = "@(#)worm.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: worm.c,v 1.21 2001/08/30 10:49:50 jsm Exp $");
+__RCSID("$NetBSD: worm.c,v 1.22 2001/08/31 07:15:44 jsm Exp $");
#endif
#endif /* not lint */
@@ -80,6 +80,7 @@ int running = 0;
int slow = 0;
int score = 0;
int start_len = LENGTH;
+int visible_len;
int lastch;
char outbuf[BUFSIZ];
@@ -189,6 +190,7 @@ life()
}
tail = np;
tail->prev = NULL;
+ visible_len = start_len + 1;
}
void
@@ -233,6 +235,13 @@ void
newpos(bp)
struct body * bp;
{
+ if (visible_len == (LINES-3) * (COLS-3) - 1) {
+ endwin();
+
+ printf("\nYou won!\n");
+ printf("Your final score was %d\n\n", score);
+ exit(0);
+ }
do {
bp->y = rnd(LINES-3)+ 1;
bp->x = rnd(COLS-3) + 1;
@@ -310,6 +319,7 @@ process(ch)
nh = tail->next;
free(tail);
tail = nh;
+ visible_len--;
}
else growing--;
display(head, BODY);
@@ -335,6 +345,7 @@ process(ch)
nh->x = x;
display(nh, HEAD);
head = nh;
+ visible_len++;
if (!(slow && running))
{
wmove(tv, head->y, head->x);