summaryrefslogtreecommitdiffstats
path: root/worm
diff options
context:
space:
mode:
authorcgd <cgd@NetBSD.org>1993-03-21 09:45:37 +0000
committercgd <cgd@NetBSD.org>1993-03-21 09:45:37 +0000
commit77e3814f0c0e3dea4d0032e25666f77e6f83bfff (patch)
tree7eddfcbf3dd12089e71dc3fafb0a106c5c5766c7 /worm
parente81d63576b2e46ab90da7d75fa155ea57ee4d32e (diff)
downloadbsdgames-darwin-77e3814f0c0e3dea4d0032e25666f77e6f83bfff.tar.gz
bsdgames-darwin-77e3814f0c0e3dea4d0032e25666f77e6f83bfff.tar.zst
bsdgames-darwin-77e3814f0c0e3dea4d0032e25666f77e6f83bfff.zip
initial import of 386bsd-0.1 sources
Diffstat (limited to 'worm')
-rw-r--r--worm/Makefile9
-rw-r--r--worm/worm.666
-rw-r--r--worm/worm.c301
3 files changed, 376 insertions, 0 deletions
diff --git a/worm/Makefile b/worm/Makefile
new file mode 100644
index 00000000..e599f0e5
--- /dev/null
+++ b/worm/Makefile
@@ -0,0 +1,9 @@
+# @(#)Makefile 5.3 (Berkeley) 5/11/90
+
+PROG= worm
+MAN6= worm.0
+DPADD= ${LIBCURSES} ${LIBTERM} ${LIBCOMPAT}
+LDADD= -lcurses -ltermcap -lcompat
+HIDEGAME=hidegame
+
+.include <bsd.prog.mk>
diff --git a/worm/worm.6 b/worm/worm.6
new file mode 100644
index 00000000..a7de0782
--- /dev/null
+++ b/worm/worm.6
@@ -0,0 +1,66 @@
+.\" Copyright (c) 1989 The Regents of the University of California.
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" @(#)worm.6 6.3 (Berkeley) 6/23/90
+.\"
+.TH WORM 6 "June 23, 1990"
+.UC 4
+.SH NAME
+worm \- Play the growing worm game
+.SH SYNOPSIS
+.B worm
+[
+.I size
+]
+.SH DESCRIPTION
+.PP
+In
+.I worm,
+you are a little worm, your body is the "o"'s on the screen
+and your head is the "@". You move with the hjkl keys (as in the game
+snake). If you don't press any keys, you continue in the direction you
+last moved. The upper case HJKL keys move you as if you had pressed
+several (9 for HL and 5 for JK) of the corresponding lower case key
+(unless you run into a digit, then it stops).
+.PP
+On the screen you will see a digit, if your worm eats the digit is will
+grow longer, the actual amount longer depends on which digit it was
+that you ate. The object of the game is to see how long you can make
+the worm grow.
+.PP
+The game ends when the worm runs into either the sides of the screen,
+or itself. The current score (how much the worm has grown) is kept in
+the upper left corner of the screen.
+.PP
+The optional argument, if present, is the initial length of the worm.
+.SH BUGS
+If the initial length of the worm is set to less than one or more
+than 75, various strange things happen.
diff --git a/worm/worm.c b/worm/worm.c
new file mode 100644
index 00000000..65a7423b
--- /dev/null
+++ b/worm/worm.c
@@ -0,0 +1,301 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+char copyright[] =
+"@(#) Copyright (c) 1980 Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif /* not lint */
+
+#ifndef lint
+static char sccsid[] = "@(#)worm.c 5.8 (Berkeley) 2/28/91";
+#endif /* not lint */
+
+/*
+ * Worm. Written by Michael Toy
+ * UCSC
+ */
+
+#include <ctype.h>
+#include <curses.h>
+#include <signal.h>
+
+#define newlink() (struct body *) malloc(sizeof (struct body));
+#define HEAD '@'
+#define BODY 'o'
+#define LENGTH 7
+#define RUNLEN 8
+#define when break;case
+#define otherwise break;default
+#define CNTRL(p) (p-'A'+1)
+#ifndef baudrate
+# define baudrate() _tty.sg_ospeed
+#endif
+
+WINDOW *tv;
+WINDOW *stw;
+struct body {
+ int x;
+ int y;
+ struct body *prev;
+ struct body *next;
+} *head, *tail, goody;
+int growing = 0;
+int running = 0;
+int slow = 0;
+int score = 0;
+int start_len = LENGTH;
+char lastch;
+char outbuf[BUFSIZ];
+
+void leave(), wake(), suspend();
+
+main(argc, argv)
+ int argc;
+ char **argv;
+{
+ char ch;
+
+ if (argc == 2)
+ start_len = atoi(argv[1]);
+ if ((start_len <= 0) || (start_len > 500))
+ start_len = LENGTH;
+ setbuf(stdout, outbuf);
+ srand(getpid());
+ signal(SIGALRM, wake);
+ signal(SIGINT, leave);
+ signal(SIGQUIT, leave);
+ signal(SIGTSTP, suspend); /* process control signal */
+ initscr();
+ crmode();
+ noecho();
+ slow = (baudrate() <= B1200);
+ clear();
+ stw = newwin(1, COLS-1, 0, 0);
+ tv = newwin(LINES-1, COLS-1, 1, 0);
+ box(tv, '*', '*');
+ scrollok(tv, FALSE);
+ scrollok(stw, FALSE);
+ wmove(stw, 0, 0);
+ wprintw(stw, " Worm");
+ refresh();
+ wrefresh(stw);
+ wrefresh(tv);
+ life(); /* Create the worm */
+ prize(); /* Put up a goal */
+ while(1)
+ {
+ if (running)
+ {
+ running--;
+ process(lastch);
+ }
+ else
+ {
+ fflush(stdout);
+ if (read(0, &ch, 1) >= 0)
+ process(ch);
+ }
+ }
+}
+
+life()
+{
+ register struct body *bp, *np;
+ register int i;
+
+ head = newlink();
+ head->x = start_len+2;
+ head->y = 12;
+ head->next = NULL;
+ display(head, HEAD);
+ for (i = 0, bp = head; i < start_len; i++, bp = np) {
+ np = newlink();
+ np->next = bp;
+ bp->prev = np;
+ np->x = bp->x - 1;
+ np->y = bp->y;
+ display(np, BODY);
+ }
+ tail = np;
+ tail->prev = NULL;
+}
+
+display(pos, chr)
+struct body *pos;
+char chr;
+{
+ wmove(tv, pos->y, pos->x);
+ waddch(tv, chr);
+}
+
+void
+leave()
+{
+ endwin();
+ exit(0);
+}
+
+void
+wake()
+{
+ signal(SIGALRM, wake);
+ fflush(stdout);
+ process(lastch);
+}
+
+rnd(range)
+{
+ return abs((rand()>>5)+(rand()>>5)) % range;
+}
+
+newpos(bp)
+struct body * bp;
+{
+ do {
+ bp->y = rnd(LINES-3)+ 2;
+ bp->x = rnd(COLS-3) + 1;
+ wmove(tv, bp->y, bp->x);
+ } while(winch(tv) != ' ');
+}
+
+prize()
+{
+ int value;
+
+ value = rnd(9) + 1;
+ newpos(&goody);
+ waddch(tv, value+'0');
+ wrefresh(tv);
+}
+
+process(ch)
+char ch;
+{
+ register int x,y;
+ struct body *nh;
+
+ alarm(0);
+ x = head->x;
+ y = head->y;
+ switch(ch)
+ {
+ when 'h': x--;
+ when 'j': y++;
+ when 'k': y--;
+ when 'l': x++;
+ when 'H': x--; running = RUNLEN; ch = tolower(ch);
+ when 'J': y++; running = RUNLEN/2; ch = tolower(ch);
+ when 'K': y--; running = RUNLEN/2; ch = tolower(ch);
+ when 'L': x++; running = RUNLEN; ch = tolower(ch);
+ when '\f': setup(); return;
+ when CNTRL('Z'): suspend(); return;
+ when CNTRL('C'): crash(); return;
+ when CNTRL('D'): crash(); return;
+ otherwise: if (! running) alarm(1);
+ return;
+ }
+ lastch = ch;
+ if (growing == 0)
+ {
+ display(tail, ' ');
+ tail->next->prev = NULL;
+ nh = tail->next;
+ free(tail);
+ tail = nh;
+ }
+ else growing--;
+ display(head, BODY);
+ wmove(tv, y, x);
+ if (isdigit(ch = winch(tv)))
+ {
+ growing += ch-'0';
+ prize();
+ score += growing;
+ running = 0;
+ wmove(stw, 0, 68);
+ wprintw(stw, "Score: %3d", score);
+ wrefresh(stw);
+ }
+ else if(ch != ' ') crash();
+ nh = newlink();
+ nh->next = NULL;
+ nh->prev = head;
+ head->next = nh;
+ nh->y = y;
+ nh->x = x;
+ display(nh, HEAD);
+ head = nh;
+ if (!(slow && running))
+ wrefresh(tv);
+ if (!running)
+ alarm(1);
+}
+
+crash()
+{
+ sleep(2);
+ clear();
+ move(23, 0);
+ refresh();
+ printf("Well, you ran into something and the game is over.\n");
+ printf("Your final score was %d\n", score);
+ leave();
+}
+
+void
+suspend()
+{
+ char *sh;
+
+ move(LINES-1, 0);
+ refresh();
+ endwin();
+ fflush(stdout);
+ kill(getpid(), SIGTSTP);
+ signal(SIGTSTP, suspend);
+ crmode();
+ noecho();
+ setup();
+}
+
+setup()
+{
+ clear();
+ refresh();
+ touchwin(stw);
+ wrefresh(stw);
+ touchwin(tv);
+ wrefresh(tv);
+ alarm(1);
+}