* Copyright (c) 1980, 1993
* The Regents of the University of California. All rights reserved.
* %sccs.include.redist.c%
static char copyright
[] =
"@(#) Copyright (c) 1980, 1993\n\
The Regents of the University of California. All rights reserved.\n";
static char sccsid
[] = "@(#)worm.c 8.1 (Berkeley) %G%";
* Worm. Written by Michael Toy
#define newlink() (struct body *) malloc(sizeof (struct body));
#define CNTRL(p) (p-'A'+1)
# define baudrate() _tty.sg_ospeed
void leave(), wake(), suspend();
start_len
= atoi(argv
[1]);
if ((start_len
<= 0) || (start_len
> 500))
signal(SIGTSTP
, suspend
); /* process control signal */
slow
= (baudrate() <= B1200
);
stw
= newwin(1, COLS
-1, 0, 0);
tv
= newwin(LINES
-1, COLS
-1, 1, 0);
life(); /* Create the worm */
prize(); /* Put up a goal */
if (read(0, &ch
, 1) >= 0)
register struct body
*bp
, *np
;
for (i
= 0, bp
= head
; i
< start_len
; i
++, bp
= np
) {
wmove(tv
, pos
->y
, pos
->x
);
return abs((rand()>>5)+(rand()>>5)) % range
;
} while(winch(tv
) != ' ');
case 'H': x
--; running
= RUNLEN
; ch
= tolower(ch
); break;
case 'J': y
++; running
= RUNLEN
/2; ch
= tolower(ch
); break;
case 'K': y
--; running
= RUNLEN
/2; ch
= tolower(ch
); break;
case 'L': x
++; running
= RUNLEN
; ch
= tolower(ch
); break;
case '\f': setup(); return;
case CNTRL('Z'): suspend(); return;
case CNTRL('C'): crash(); return;
case CNTRL('D'): crash(); return;
default: if (! running
) alarm(1);
if (isdigit(ch
= winch(tv
)))
wprintw(stw
, "Score: %3d", score
);
else if(ch
!= ' ') crash();
printf("Well, you ran into something and the game is over.\n");
printf("Your final score was %d\n", score
);
signal(SIGTSTP
, suspend
);