* Copyright (c) 1980 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
"@(#) Copyright (c) 1980 Regents of the University of California.\n\
static char sccsid
[] = "@(#)worm.c 5.5 (Berkeley) %G%";
* Worm. Written by Michael Toy
#define newlink() (struct body *) malloc(sizeof (struct body));
#define otherwise break;default
#define CNTRL(p) (p-'A'+1)
# define baudrate() _tty.sg_ospeed
int 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
) != ' ');
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);
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
);