|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T m
Length: 6276 (0x1884)
Types: TextFile
Names: »misc.c«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987
└─⟦this⟧ »EUUGD18/General/Dots/misc.c«
/* MISC.C */
#include "dots.h"
/* has to be a function instead of define because signal calls this */
redraw()
{
clearok(curscr, TRUE), wrefresh(curscr);
}
/* returns the number of boxes closed, if any */
entermove()
{
Cursor(xposit, yposit);
addstr(iseven(yposit) ? "|\b" : "\b---\b\b");
board[xposit][yposit] = USED;
return he_got_some();
}
closure(BorG, x, y)
register int BorG, x, y;
{
if (!is_on_board(x, y))
return (-1);
if (BorG == GOOD)
return (board[x][y - 1]
+ board[x][y + 1]
+ board[x - 1][y]
+ board[x + 1][y]);
else
return (badboard[x][y - 1]
+ badboard[x][y + 1]
+ badboard[x - 1][y]
+ badboard[x + 1][y]);
}
he_got_some()
{
int total = 0, x1, y1, x2, y2;
find_adj_squares(xposit, yposit, &x1, &y1, &x2, &y2);
if (closure(GOOD, x1, y1) == 4) {
putinitial(x1, y1);
total++;
}
if (closure(GOOD, x2, y2) == 4) {
putinitial(x2, y2);
total++;
}
if (mover == THEM)
comptally += total;
else
persontally += total;
bottom_line();
return total;
}
set_redraw_signal_key_to(c)
char c;
{
static char oldquit = 0;
if (!oldquit)
if (ioctl(0, TIOCGETC, &tchars) == -1)
oops("ioctl get call");
else
oldquit = tchars.t_quitc;
tchars.t_quitc = (c) ? c : oldquit; /* redraw screen anytime by signal */
if (ioctl(0, TIOCSETC, &tchars) == -1)
oops("ioctl set call");
}
bottom_line()
{
char line[128], Opponent[12];
register char *p = line;
(void) sprintf(Opponent, "%s's", opponent);
if (mode != DEMO)
p += strlen(sprintf(p, "%8s turn. ",
(mover == US) ? "Your" : (mode == TWOPLAYER) ? Opponent : "My"));
p += strlen(sprintf(p, "%s: %3d %s: %3d ",
(mode == DEMO) ? "Player 1" : "You",
persontally, (mode == TWOPLAYER) ? opponent :
(mode == DEMO) ? "Player 2" : "Me", comptally));
if (mode != TWOPLAYER && mode != DEMO && strlen(line) + 13 < COLS - 1)
p += strlen(sprintf(p, "Level: %s ",
(level == DUMB) ? "EASY" : (level == HARD) ? "HARD" : "KILLER"));
if (p - line + 14 < COLS - 1 && mode != DEMO)
p += strlen(sprintf(p, " '?' for help."));
if (mode == DEMO)
p += strlen(sprintf(p, " Demo Game."));
if (mode == TWOPLAYER && p - line + 29 < COLS - 1)
(void) sprintf(p, " '^L' to redraw. ESC to talk.");
msg(line);
Cursor(xposit, yposit);
}
board_is_almost_full()
{
return (persontally + comptally >= (Length - 1) * (Width - 1) - 4);
}
board_is_full()
{
return (persontally + comptally == (Length - 1) * (Width - 1));
}
end_of_game()
{
char line[80], c;
register char *p = line;
move(LINES - 1, 0);
if (board_is_full()) {
p += strlen(sprintf(p, "Score: %d to %d. ", comptally, persontally));
if (comptally == persontally)
p += strlen(sprintf(p, "No one won. "));
else if (mode == DEMO)
p += strlen(sprintf(p, "%s won. ", (comptally > persontally)
? "Player 2" : "Player 1"));
else
p += strlen(sprintf(p, "%s won. ",
(comptally > persontally) ? (mode == TWOPLAYER) ?
"They" : "I" : "You"));
addstr(line);
if (mode != DEMO)
if (comptally - persontally < 0) {
printw("You get a %s. ", prize);
if (mode != TWOPLAYER)
high_score(0, 0);
} else if (comptally != persontally)
printw("You lose a %s. ", prize);
} else
addstr("No score, you quit.");
if (mode == TWOPLAYER)
goodbye(1);
addstr("--more--"), clrtoeol();
refresh();
getchar();
msg("RETURN for menu; 'Q' to exit. ");
if ((c = getchar()) == 'q' || c == 'Q')
goodbye(1);
disp_menu();
}
goodbye(When)
bool When;
{
if (When)
msg("");
if (When && mode != TWOPLAYER)
high_score(TRUE, FALSE);
printf("\nThanx, %s.\n", username);
die();
}
/*VARARGS1*/
msg(fmt, args)
char *fmt;
{
char string[BUFSIZ];
#ifdef VPRINTF
vsprintf(string, fmt, &args);
#else
FILE foo;
foo._cnt = BUFSIZ;
foo._base = foo._ptr = string; /* may have to be cast(unsigned char *) */
foo._flag = _IOWRT+_IOSTRG;
_doprnt(fmt, &args, &foo);
(void) fputc(0, &foo);
#endif VPRINTF
mvaddstr(LINES-1, 0, string), clrtoeol(), refresh();
}
/*VARARGS1*/
oops(fmt, args)
char *fmt;
{
#ifdef VPRINTF
vprintf(fmt, &args);
#else
_doprnt(fmt, &args, stdout);
#endif VPRINTF
perror("");
}
die()
{
set_redraw_signal_key_to(0); /* reset to original, whatever it was */
if (mode == TWOPLAYER)
destroysocket();
nocrmode(), echo(), endwin();
exit(0);
}
onintr(sig)
{
int x, y;
(void) signal(sig, onintr);
(void) alarm(0);
if (sig != SIGPIPE) {
getyx(stdscr, y, x);
msg("Really quit? ");
if (getchar() != 'y') {
move(y, x);
if (Length && Width)
bottom_line();
else
refresh();
return;
}
}
msg("");
if (sig != SIGINT && sig != SIGQUIT) {
if (sig == SIGPIPE)
destroysocket(), fprintf(stderr, "Your opponent terminated.\n");
else
printw("I got signal #%d: %s", sig, sys_siglist[sig]);
clrtoeol();
refresh();
}
if (jmpbuf_set && sig != SIGINT && sig != SIGQUIT)
longjmp(menu_jmp, 1);
die();
}
Cursor(a, b)
int a, b;
{
move(y_start + b - 1, x_start + a * 2 - 2), refresh();
}
is_on_board(x, y)
register int x, y;
{
return (x > 0 && y > 0 && x < 2 * Length && y < 2 * Width);
}
putinitial(x, y)
register int x, y;
{
Cursor(x, y);
addch(Initial[mover]);
refresh();
board[x][y] = mover;
}
shell()
{
register char *SHELL;
register int pid, w;
int status, (*oq)(), (*oi)();
clear(), refresh();
printf("Which Shell, (sh / csh (s/c))? ");
SHELL = (getchar() == 'c') ? "/bin/csh" : "/bin/sh";
echo(), nocrmode();
oi = signal(SIGINT, SIG_IGN); /* old interrupt (oi) and old quit (oq) */
oq = signal(SIGQUIT, SIG_IGN); /* signals saved on return of signal() */
if ((pid = fork()) == 0) {
setuid(getuid());
setgid(getgid());
execl(SHELL, SHELL, 0);
oops("Couldn't execl(%s)", SHELL);
_exit(127);
}
while ((w = wait(&status)) != pid && w != -1)
;
printf("[Hit return to continue]");
while (getchar() != '\n')
;
(void) signal(SIGINT, oi); /* reset old signals */
(void) signal(SIGQUIT, oq);
noecho(), crmode();
drawboard(), bottom_line();
return (status);
}