* Copyright (c) 1985 Conrad C. Huang, Gregory S. Couch, Kenneth C.R.C. Arnold
* San Francisco, California
* Copyright (c) 1985 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
# define CTRL(x) ('x' & 037)
char screen
[24][80], blanks
[80];
static int otto_y
, otto_x
;
* ibuf is the input buffer used for the stream from the driver.
* It is small because we do not check for user input when there
* are characters in the input buffer.
#define GETCHR(fd) (--(fd)->_cnt >= 0 ? *(fd)->_ptr++&0377 : getchr(fd))
* Play a given game, handling all the curses commands from
register unsigned int y
, x
;
while ((inf
= fdopen(Socket
, "r")) == NULL
)
perror("fdopen of socket");
setbuffer(inf
, ibuf
, sizeof ibuf
);
if (Master_pid
== 0 || Master_pid
== EOF
) {
while ((ch
= GETCHR(inf
)) != EOF
) {
mvcur(cur_row
, cur_col
, y
, x
);
getyx(stdscr
, otto_y
, otto_x
);
if ((ch
= GETCHR(inf
)) == LAST_PLAYER
)
(void) ioctl(fileno(stdin
), TIOCFLUSH
, &in
);
Otto_count
-= (GETCHR(inf
) & 255);
fputc('0' + Otto_count
, stderr
);
if (Otto_count
== 0 && Otto_mode
)
otto(otto_y
, otto_x
, otto_face
);
getyx(stdscr
, otto_y
, otto_x
);
* Grab input and pass it along to the driver
* Return any characters from the driver
* When this routine is called by GETCHR, we already know there are
* no characters in the input buffer.
int driver_mask
, stdin_mask
;
driver_mask
= 1L << fileno(fd
);
stdin_mask
= 1L << fileno(stdin
);
s_readfds
= driver_mask
| stdin_mask
;
s_nfds
= (driver_mask
> stdin_mask
) ? driver_mask
: stdin_mask
;
nfds
= select(nfds
, &readfds
, NULL
, NULL
, NULL
);
nfds
= select(nfds
, &readfds
, (int *) NULL
, 32767);
} while (nfds
<= 0 && errno
== EINTR
);
if (readfds
& stdin_mask
)
if ((readfds
& driver_mask
) == 0)
* Send standard input characters to the driver
static char inp
[sizeof Buf
];
extern char map_key
[256];
count
= read(fileno(stdin
), Buf
, sizeof Buf
);
(void) write(1, "\7", 1);
* look for 'q'uit commands; if we find one,
* confirm it. If it is not confirmed, strip
for (sp
= Buf
; *sp
!= '\0'; sp
++)
if ((*nsp
= map_key
[*sp
]) == 'q')
else if (*nsp
== CTRL(O
))
(void) write(Socket
, inp
, count
);
* Handle the end of the game when the player dies
register int explain
, ch
;
mvcur(cur_row
, cur_col
, HEIGHT
, 0);
put_str("Re-enter game? ");
if (isupper(ch
= getchar()))
fprintf(stderr
, "r,c,ch: %d,%d,%d", cur_row
, cur_col
, ch
);
screen
[cur_row
][cur_col
] = ch
;
tputs(CL
, LINES
, _putchar
);
bcopy(blanks
, screen
[i
], 80);
for (i
= 0; i
< 24; i
++) {
mvcur(cur_row
, cur_col
, i
, 0);
mvcur(cur_row
, cur_col
, 0, 0);
fwrite(blanks
, sizeof (char), 80 - cur_col
, stdout
);
mvcur(cur_row
, 80, cur_row
, cur_col
);
mvcur(cur_row
+ 1, 0, cur_row
, cur_col
);
mvcur(cur_row
, 79, cur_row
, cur_col
);
bcopy(blanks
, &screen
[cur_row
][cur_col
], 80 - cur_col
);
if ((curscr
= newwin(24, 80, 0, 0)) == NULL
) {
fprintf(stderr
, "Can't create curscr\n");
curscr
->_y
[i
] = screen
[i
];
mvcur(cur_row
, cur_col
, 0, 0);
for (i
= 0; i
< 23; i
++) {
fwrite(screen
[i
], sizeof (char), 80, stdout
);
if (COLS
> 80 || (COLS
== 80 && !AM
))
fwrite(screen
[23], sizeof (char), 79, stdout
);
mvcur(23, 79, cur_row
, cur_col
);