mirror of
https://github.com/vattam/BSDGames.git
synced 2025-12-20 19:04:49 +00:00
* Corrected snake's usage message, Closes: #84852
* Patch from Malcolm Parsons <malcolm@ivywell.screaming.net> to fix snake scoring problem, Closes: #80549 * Statoverride transition. git-svn-id: file:///srv/svn/joey/bsdgames-trunk@5140 a4a2c43b-8ac3-0310-8836-e0e880c912e2
This commit is contained in:
9
debian/changelog
vendored
9
debian/changelog
vendored
@@ -1,3 +1,12 @@
|
|||||||
|
bsdgames (2.12-3) unstable; urgency=low
|
||||||
|
|
||||||
|
* Corrected snake's usage message, Closes: #84852
|
||||||
|
* Patch from Malcolm Parsons <malcolm@ivywell.screaming.net> to fix
|
||||||
|
snake scoring problem, Closes: #80549
|
||||||
|
* Statoverride transition.
|
||||||
|
|
||||||
|
-- Joey Hess <joeyh@debian.org> Sun, 4 Feb 2001 14:06:28 -0800
|
||||||
|
|
||||||
bsdgames (2.12-2) unstable; urgency=low
|
bsdgames (2.12-2) unstable; urgency=low
|
||||||
|
|
||||||
* Depends on wordlist, Closes: #76331
|
* Depends on wordlist, Closes: #76331
|
||||||
|
|||||||
4
debian/control
vendored
4
debian/control
vendored
@@ -3,12 +3,12 @@ Section: games
|
|||||||
Priority: optional
|
Priority: optional
|
||||||
Build-Depends: debhelper (>= 2.1.0), libncurses5-dev, flex, bison, wenglish
|
Build-Depends: debhelper (>= 2.1.0), libncurses5-dev, flex, bison, wenglish
|
||||||
Maintainer: Joey Hess <joeyh@debian.org>
|
Maintainer: Joey Hess <joeyh@debian.org>
|
||||||
Standards-Version: 3.2.1.0
|
Standards-Version: 3.5.0.0
|
||||||
|
|
||||||
Package: bsdgames
|
Package: bsdgames
|
||||||
Architecture: any
|
Architecture: any
|
||||||
Depends: ${shlibs:Depends}, wordlist
|
Depends: ${shlibs:Depends}, wordlist
|
||||||
Conflicts: bsdgames-nonfree (<< 2.5)
|
Conflicts: bsdgames-nonfree (<< 2.5), suidmanager (<< 0.50)
|
||||||
Replaces: bsdgames-nonfree (<< 2.5)
|
Replaces: bsdgames-nonfree (<< 2.5)
|
||||||
Description: collection of text games from BSD systems
|
Description: collection of text games from BSD systems
|
||||||
This is a collection of some of the text-based games and amusements that have
|
This is a collection of some of the text-based games and amusements that have
|
||||||
|
|||||||
2
debian/rules
vendored
2
debian/rules
vendored
@@ -95,8 +95,6 @@ binary-arch: build
|
|||||||
debian/bsdgames/var/games/bsdgames/phantasia
|
debian/bsdgames/var/games/bsdgames/phantasia
|
||||||
find debian/bsdgames/var/games/bsdgames -size 0 -exec rm {} \;
|
find debian/bsdgames/var/games/bsdgames -size 0 -exec rm {} \;
|
||||||
|
|
||||||
dh_suidregister
|
|
||||||
|
|
||||||
dh_installdeb
|
dh_installdeb
|
||||||
dh_shlibdeps
|
dh_shlibdeps
|
||||||
dh_gencontrol
|
dh_gencontrol
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: snake.c,v 1.9 1997/10/12 01:49:28 lukem Exp $ */
|
/* $NetBSD: snake.c,v 1.16 2000/05/08 07:56:05 mycroft Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1980, 1993
|
* Copyright (c) 1980, 1993
|
||||||
@@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1993\n\
|
|||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)snake.c 8.2 (Berkeley) 1/7/94";
|
static char sccsid[] = "@(#)snake.c 8.2 (Berkeley) 1/7/94";
|
||||||
#else
|
#else
|
||||||
__RCSID("$NetBSD: snake.c,v 1.9 1997/10/12 01:49:28 lukem Exp $");
|
__RCSID("$NetBSD: snake.c,v 1.16 2000/05/08 07:56:05 mycroft Exp $");
|
||||||
#endif
|
#endif
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
@@ -60,16 +60,31 @@ __RCSID("$NetBSD: snake.c,v 1.9 1997/10/12 01:49:28 lukem Exp $");
|
|||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <curses.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <err.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <termios.h>
|
||||||
|
|
||||||
#include "snake.h"
|
|
||||||
#include "pathnames.h"
|
#include "pathnames.h"
|
||||||
|
|
||||||
|
#define cashvalue chunk*(loot-penalty)/25
|
||||||
|
|
||||||
|
struct point {
|
||||||
|
int col, line;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define same(s1, s2) ((s1)->line == (s2)->line && (s1)->col == (s2)->col)
|
||||||
|
|
||||||
#define PENALTY 10 /* % penalty for invoking spacewarp */
|
#define PENALTY 10 /* % penalty for invoking spacewarp */
|
||||||
|
|
||||||
#define EOT '\004'
|
#define EOT '\004'
|
||||||
@@ -82,49 +97,67 @@ __RCSID("$NetBSD: snake.c,v 1.9 1997/10/12 01:49:28 lukem Exp $");
|
|||||||
#define TREASURE '$'
|
#define TREASURE '$'
|
||||||
#define GOAL '#'
|
#define GOAL '#'
|
||||||
|
|
||||||
#define BSIZE 80
|
|
||||||
|
|
||||||
#ifndef MIN
|
#ifndef MIN
|
||||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define pchar(point, c) mvaddch((point)->line + 1, (point)->col + 1, (c))
|
||||||
|
#define delay(t) usleep(t * 50000);
|
||||||
|
|
||||||
struct point you;
|
struct point you;
|
||||||
struct point money;
|
struct point money;
|
||||||
struct point finish;
|
struct point finish;
|
||||||
struct point snake[6];
|
struct point snake[6];
|
||||||
|
|
||||||
int loot, penalty;
|
int loot, penalty;
|
||||||
int long tl, tm = 0L;
|
|
||||||
int moves;
|
int moves;
|
||||||
char stri[BSIZE];
|
|
||||||
char *p;
|
|
||||||
char ch, savec;
|
|
||||||
char *kl, *kr, *ku, *kd;
|
|
||||||
int fast = 1;
|
int fast = 1;
|
||||||
int repeat = 1;
|
|
||||||
time_t tv;
|
|
||||||
char *tn;
|
|
||||||
|
|
||||||
int rawscores;
|
int rawscores;
|
||||||
FILE *logfile;
|
FILE *logfile;
|
||||||
|
|
||||||
int main __P((int, char **));
|
int lcnt, ccnt; /* user's idea of screen size */
|
||||||
|
int chunk; /* amount of money given at a time */
|
||||||
|
|
||||||
|
void chase __P((struct point *, struct point *));
|
||||||
|
int chk __P((const struct point *));
|
||||||
|
void drawbox __P((void));
|
||||||
|
void flushi __P((void));
|
||||||
|
void home __P((void));
|
||||||
|
void length __P((int));
|
||||||
|
void logit __P((const char *));
|
||||||
|
int main __P((int, char **));
|
||||||
|
void mainloop __P((void)) __attribute__((__noreturn__));
|
||||||
|
struct point *point __P((struct point *, int, int));
|
||||||
|
int post __P((int, int));
|
||||||
|
int pushsnake __P((void));
|
||||||
|
void right __P((const struct point *));
|
||||||
|
void setup __P((void));
|
||||||
|
void snap __P((void));
|
||||||
|
void snrand __P((struct point *));
|
||||||
|
void spacewarp __P((int));
|
||||||
|
void stop __P((int)) __attribute__((__noreturn__));
|
||||||
|
int stretch __P((const struct point *));
|
||||||
|
void surround __P((struct point *));
|
||||||
|
void suspend __P((void));
|
||||||
|
void win __P((const struct point *));
|
||||||
|
void winnings __P((int));
|
||||||
|
|
||||||
int
|
int
|
||||||
main(argc, argv)
|
main(argc, argv)
|
||||||
int argc;
|
int argc;
|
||||||
char **argv;
|
char **argv;
|
||||||
{
|
{
|
||||||
extern char *optarg;
|
|
||||||
extern int optind;
|
|
||||||
int ch, i;
|
int ch, i;
|
||||||
|
time_t tv;
|
||||||
|
|
||||||
/* Open score files then revoke setgid privileges */
|
/* Open score files then revoke setgid privileges */
|
||||||
rawscores = open(_PATH_RAWSCORES, O_RDWR|O_CREAT, 0664);
|
rawscores = open(_PATH_RAWSCORES, O_RDWR|O_CREAT, 0664);
|
||||||
if (rawscores < 0) {
|
if (rawscores < 0) {
|
||||||
warn("open %s", _PATH_RAWSCORES);
|
warn("open %s", _PATH_RAWSCORES);
|
||||||
sleep(2);
|
sleep(2);
|
||||||
}
|
} else if (rawscores < 3)
|
||||||
|
exit(1);
|
||||||
logfile = fopen(_PATH_LOGFILE, "a");
|
logfile = fopen(_PATH_LOGFILE, "a");
|
||||||
if (logfile == NULL) {
|
if (logfile == NULL) {
|
||||||
warn("fopen %s", _PATH_LOGFILE);
|
warn("fopen %s", _PATH_LOGFILE);
|
||||||
@@ -133,11 +166,10 @@ main(argc, argv)
|
|||||||
setregid(getgid(), getgid());
|
setregid(getgid(), getgid());
|
||||||
|
|
||||||
(void) time(&tv);
|
(void) time(&tv);
|
||||||
srandom((int) tv);
|
|
||||||
|
|
||||||
while ((ch = getopt(argc, argv, "l:w:")) != -1)
|
while ((ch = getopt(argc, argv, "l:w:t")) != -1)
|
||||||
switch ((char) ch) {
|
switch ((char) ch) {
|
||||||
#ifdef notdef
|
#if 0
|
||||||
case 'd':
|
case 'd':
|
||||||
tv = atol(optarg);
|
tv = atol(optarg);
|
||||||
break;
|
break;
|
||||||
@@ -148,20 +180,33 @@ main(argc, argv)
|
|||||||
case 'l': /* length */
|
case 'l': /* length */
|
||||||
lcnt = atoi(optarg);
|
lcnt = atoi(optarg);
|
||||||
break;
|
break;
|
||||||
|
case 't':
|
||||||
|
fast = 0;
|
||||||
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
default:
|
default:
|
||||||
fputs("usage: snake [-d seed] [-w width] [-l length]\n", stderr);
|
fputs("usage: snake [-w width] [-l length] [-t]\n", stderr);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
srandom((int) tv);
|
||||||
|
|
||||||
penalty = loot = 0;
|
penalty = loot = 0;
|
||||||
getcap();
|
initscr();
|
||||||
|
cbreak();
|
||||||
|
noecho();
|
||||||
|
#ifdef KEY_LEFT
|
||||||
|
keypad(stdscr, TRUE);
|
||||||
|
#endif
|
||||||
|
if (!lcnt || lcnt > LINES - 2)
|
||||||
|
lcnt = LINES - 2;
|
||||||
|
if (!ccnt || ccnt > COLS - 2)
|
||||||
|
ccnt = COLS - 2;
|
||||||
|
|
||||||
i = MIN(lcnt, ccnt);
|
i = MIN(lcnt, ccnt);
|
||||||
if (i < 4) {
|
if (i < 4) {
|
||||||
cook();
|
endwin();
|
||||||
pr("snake: screen too small for a fair game.\n");
|
errx(1, "screen too small for a fair game.");
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* chunk is the amount of money the user gets for each $.
|
* chunk is the amount of money the user gets for each $.
|
||||||
@@ -188,16 +233,12 @@ main(argc, argv)
|
|||||||
chunk = (675.0 / (i + 6)) + 2.5; /* min screen edge */
|
chunk = (675.0 / (i + 6)) + 2.5; /* min screen edge */
|
||||||
|
|
||||||
signal(SIGINT, stop);
|
signal(SIGINT, stop);
|
||||||
putpad(TI); /* String to begin programs that use cm */
|
|
||||||
putpad(KS); /* Put terminal in keypad transmit mode */
|
|
||||||
|
|
||||||
snrand(&finish);
|
snrand(&finish);
|
||||||
snrand(&you);
|
snrand(&you);
|
||||||
snrand(&money);
|
snrand(&money);
|
||||||
snrand(&snake[0]);
|
snrand(&snake[0]);
|
||||||
|
|
||||||
if (ospeed < 9600 || ((!CM) && (!TA)))
|
|
||||||
fast = 0;
|
|
||||||
for (i = 1; i < 6; i++)
|
for (i = 1; i < 6; i++)
|
||||||
chase(&snake[i], &snake[i - 1]);
|
chase(&snake[i], &snake[i - 1]);
|
||||||
setup();
|
setup();
|
||||||
@@ -206,25 +247,34 @@ main(argc, argv)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct point *
|
||||||
|
point(ps, x, y)
|
||||||
|
struct point *ps;
|
||||||
|
int x, y;
|
||||||
|
{
|
||||||
|
ps->col = x;
|
||||||
|
ps->line = y;
|
||||||
|
return (ps);
|
||||||
|
}
|
||||||
|
|
||||||
/* Main command loop */
|
/* Main command loop */
|
||||||
void
|
void
|
||||||
mainloop()
|
mainloop()
|
||||||
{
|
{
|
||||||
int j, k;
|
int k;
|
||||||
|
int repeat = 1;
|
||||||
|
int lastc = 0;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
int c, lastc, match;
|
int c;
|
||||||
struct point tmp;
|
|
||||||
|
|
||||||
lastc = 0;
|
/* Highlight you, not left & above */
|
||||||
tmp.col = you.col + 1;
|
move(you.line + 1, you.col + 1);
|
||||||
tmp.line = you.line + 1; /* Highlight you, not left & above */
|
refresh();
|
||||||
move(&tmp);
|
if (((c = getch()) <= '9') && (c >= '0')) {
|
||||||
fflush(stdout);
|
repeat = c - '0';
|
||||||
if (((c = getchar() & 0177) <= '9') && (c >= '0')) {
|
while (((c = getch()) <= '9') && (c >= '0'))
|
||||||
ungetc(c, stdin);
|
repeat = 10 * repeat + (c - '0');
|
||||||
j = scanf("%d", &repeat);
|
|
||||||
c = getchar() & 0177;
|
|
||||||
} else {
|
} else {
|
||||||
if (c != '.')
|
if (c != '.')
|
||||||
repeat = 1;
|
repeat = 1;
|
||||||
@@ -232,48 +282,6 @@ mainloop()
|
|||||||
if (c == '.') {
|
if (c == '.') {
|
||||||
c = lastc;
|
c = lastc;
|
||||||
}
|
}
|
||||||
if ((Klength > 0) &&
|
|
||||||
(c == *KL || c == *KR || c == *KU || c == *KD)) {
|
|
||||||
savec = c;
|
|
||||||
match = 0;
|
|
||||||
kl = KL;
|
|
||||||
kr = KR;
|
|
||||||
ku = KU;
|
|
||||||
kd = KD;
|
|
||||||
for (j = Klength; j > 0; j--) {
|
|
||||||
if (match != 1) {
|
|
||||||
match = 0;
|
|
||||||
if (*kl++ == c) {
|
|
||||||
ch = 'h';
|
|
||||||
match++;
|
|
||||||
}
|
|
||||||
if (*kr++ == c) {
|
|
||||||
ch = 'l';
|
|
||||||
match++;
|
|
||||||
}
|
|
||||||
if (*ku++ == c) {
|
|
||||||
ch = 'k';
|
|
||||||
match++;
|
|
||||||
}
|
|
||||||
if (*kd++ == c) {
|
|
||||||
ch = 'j';
|
|
||||||
match++;
|
|
||||||
}
|
|
||||||
if (match == 0) {
|
|
||||||
ungetc(c, stdin);
|
|
||||||
ch = savec;
|
|
||||||
/* Oops! This works if we
|
|
||||||
* figure it out on second
|
|
||||||
* character. */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
savec = c;
|
|
||||||
if (j != 1)
|
|
||||||
c = getchar() & 0177;
|
|
||||||
}
|
|
||||||
c = ch;
|
|
||||||
}
|
|
||||||
if (!fast)
|
if (!fast)
|
||||||
flushi();
|
flushi();
|
||||||
lastc = c;
|
lastc = c;
|
||||||
@@ -284,10 +292,10 @@ mainloop()
|
|||||||
case EOT:
|
case EOT:
|
||||||
case 'x':
|
case 'x':
|
||||||
case 0177: /* del or end of file */
|
case 0177: /* del or end of file */
|
||||||
ll();
|
endwin();
|
||||||
length(moves);
|
length(moves);
|
||||||
logit("quit");
|
logit("quit");
|
||||||
done();
|
exit(0);
|
||||||
case CTRL('l'):
|
case CTRL('l'):
|
||||||
setup();
|
setup();
|
||||||
winnings(cashvalue);
|
winnings(cashvalue);
|
||||||
@@ -341,6 +349,9 @@ mainloop()
|
|||||||
switch (c) {
|
switch (c) {
|
||||||
case 's':
|
case 's':
|
||||||
case 'h':
|
case 'h':
|
||||||
|
#ifdef KEY_LEFT
|
||||||
|
case KEY_LEFT:
|
||||||
|
#endif
|
||||||
case '\b':
|
case '\b':
|
||||||
if (you.col > 0) {
|
if (you.col > 0) {
|
||||||
if ((fast) || (k == 1))
|
if ((fast) || (k == 1))
|
||||||
@@ -353,6 +364,9 @@ mainloop()
|
|||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
case 'l':
|
case 'l':
|
||||||
|
#ifdef KEY_RIGHT
|
||||||
|
case KEY_RIGHT:
|
||||||
|
#endif
|
||||||
case ' ':
|
case ' ':
|
||||||
if (you.col < ccnt - 1) {
|
if (you.col < ccnt - 1) {
|
||||||
if ((fast) || (k == 1))
|
if ((fast) || (k == 1))
|
||||||
@@ -366,6 +380,9 @@ mainloop()
|
|||||||
case CTRL('p'):
|
case CTRL('p'):
|
||||||
case 'e':
|
case 'e':
|
||||||
case 'k':
|
case 'k':
|
||||||
|
#ifdef KEY_UP
|
||||||
|
case KEY_UP:
|
||||||
|
#endif
|
||||||
case 'i':
|
case 'i':
|
||||||
if (you.line > 0) {
|
if (you.line > 0) {
|
||||||
if ((fast) || (k == 1))
|
if ((fast) || (k == 1))
|
||||||
@@ -379,6 +396,9 @@ mainloop()
|
|||||||
case CTRL('n'):
|
case CTRL('n'):
|
||||||
case 'c':
|
case 'c':
|
||||||
case 'j':
|
case 'j':
|
||||||
|
#ifdef KEY_DOWN
|
||||||
|
case KEY_DOWN:
|
||||||
|
#endif
|
||||||
case LF:
|
case LF:
|
||||||
case 'm':
|
case 'm':
|
||||||
if (you.line + 1 < lcnt) {
|
if (you.line + 1 < lcnt) {
|
||||||
@@ -409,19 +429,18 @@ mainloop()
|
|||||||
}
|
}
|
||||||
if (same(&you, &finish)) {
|
if (same(&you, &finish)) {
|
||||||
win(&finish);
|
win(&finish);
|
||||||
ll();
|
flushi();
|
||||||
cook();
|
endwin();
|
||||||
pr("You have won with $%d.\n", cashvalue);
|
printf("You have won with $%d.\n", cashvalue);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
logit("won");
|
logit("won");
|
||||||
post(cashvalue, 1);
|
post(cashvalue, 1);
|
||||||
length(moves);
|
length(moves);
|
||||||
done();
|
exit(0);
|
||||||
}
|
}
|
||||||
if (pushsnake())
|
if (pushsnake())
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
fflush(stdout);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -433,7 +452,7 @@ setup()
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
clear();
|
erase();
|
||||||
pchar(&you, ME);
|
pchar(&you, ME);
|
||||||
pchar(&finish, GOAL);
|
pchar(&finish, GOAL);
|
||||||
pchar(&money, TREASURE);
|
pchar(&money, TREASURE);
|
||||||
@@ -442,34 +461,21 @@ setup()
|
|||||||
}
|
}
|
||||||
pchar(&snake[0], SNAKEHEAD);
|
pchar(&snake[0], SNAKEHEAD);
|
||||||
drawbox();
|
drawbox();
|
||||||
fflush(stdout);
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
drawbox()
|
drawbox()
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct point p;
|
|
||||||
|
|
||||||
p.line = -1;
|
for (i = 1; i <= ccnt; i++) {
|
||||||
for (i = 0; i < ccnt; i++) {
|
mvaddch(0, i, '-');
|
||||||
p.col = i;
|
mvaddch(lcnt + 1, i, '-');
|
||||||
pchar(&p, '-');
|
|
||||||
}
|
}
|
||||||
p.col = ccnt;
|
for (i = 0; i <= lcnt + 1; i++) {
|
||||||
for (i = -1; i <= lcnt; i++) {
|
mvaddch(i, 0, '|');
|
||||||
p.line = i;
|
mvaddch(i, ccnt + 1, '|');
|
||||||
pchar(&p, '|');
|
|
||||||
}
|
|
||||||
p.col = -1;
|
|
||||||
for (i = -1; i <= lcnt; i++) {
|
|
||||||
p.line = i;
|
|
||||||
pchar(&p, '|');
|
|
||||||
}
|
|
||||||
p.line = lcnt;
|
|
||||||
for (i = 0; i < ccnt; i++) {
|
|
||||||
p.col = i;
|
|
||||||
pchar(&p, '-');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -493,10 +499,10 @@ snrand(sp)
|
|||||||
continue;
|
continue;
|
||||||
if (same(&p, &finish))
|
if (same(&p, &finish))
|
||||||
continue;
|
continue;
|
||||||
for (i = 0; i < 5; i++)
|
for (i = 0; i < 6; i++)
|
||||||
if (same(&p, &snake[i]))
|
if (same(&p, &snake[i]))
|
||||||
break;
|
break;
|
||||||
if (i < 5)
|
if (i < 6)
|
||||||
continue;
|
continue;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -513,11 +519,17 @@ post(iscore, flag)
|
|||||||
short allbwho = 0, allbscore = 0;
|
short allbwho = 0, allbscore = 0;
|
||||||
struct passwd *p;
|
struct passwd *p;
|
||||||
|
|
||||||
|
/* I want to printf() the scores for terms that clear on cook(),
|
||||||
|
* but this routine also gets called with flag == 0 to see if
|
||||||
|
* the snake should wink. If (flag) then we're at game end and
|
||||||
|
* can printf.
|
||||||
|
*/
|
||||||
/*
|
/*
|
||||||
* Neg uid, 0, and 1 cannot have scores recorded.
|
* Neg uid, 0, and 1 cannot have scores recorded.
|
||||||
*/
|
*/
|
||||||
if ((uid = getuid()) <= 1) {
|
if ((uid = getuid()) <= 1) {
|
||||||
pr("No saved scores for uid %d.\n", uid);
|
if (flag)
|
||||||
|
printf("No saved scores for uid %d.\n", uid);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
if (rawscores < 0) {
|
if (rawscores < 0) {
|
||||||
@@ -529,16 +541,18 @@ post(iscore, flag)
|
|||||||
read(rawscores, &allbwho, sizeof(short));
|
read(rawscores, &allbwho, sizeof(short));
|
||||||
lseek(rawscores, uid * sizeof(short), SEEK_SET);
|
lseek(rawscores, uid * sizeof(short), SEEK_SET);
|
||||||
read(rawscores, &oldbest, sizeof(short));
|
read(rawscores, &oldbest, sizeof(short));
|
||||||
if (!flag)
|
if (!flag) {
|
||||||
|
lseek(rawscores, 0, SEEK_SET);
|
||||||
return (score > oldbest ? 1 : 0);
|
return (score > oldbest ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
/* Update this jokers best */
|
/* Update this jokers best */
|
||||||
if (score > oldbest) {
|
if (score > oldbest) {
|
||||||
lseek(rawscores, uid * sizeof(short), SEEK_SET);
|
lseek(rawscores, uid * sizeof(short), SEEK_SET);
|
||||||
write(rawscores, &score, sizeof(short));
|
write(rawscores, &score, sizeof(short));
|
||||||
pr("You bettered your previous best of $%d\n", oldbest);
|
printf("You bettered your previous best of $%d\n", oldbest);
|
||||||
} else
|
} else
|
||||||
pr("Your best to date is $%d\n", oldbest);
|
printf("Your best to date is $%d\n", oldbest);
|
||||||
|
|
||||||
/* See if we have a new champ */
|
/* See if we have a new champ */
|
||||||
p = getpwuid(allbwho);
|
p = getpwuid(allbwho);
|
||||||
@@ -547,12 +561,12 @@ post(iscore, flag)
|
|||||||
write(rawscores, &score, sizeof(short));
|
write(rawscores, &score, sizeof(short));
|
||||||
write(rawscores, &uid, sizeof(short));
|
write(rawscores, &uid, sizeof(short));
|
||||||
if (allbwho)
|
if (allbwho)
|
||||||
pr("You beat %s's old record of $%d!\n",
|
printf("You beat %s's old record of $%d!\n",
|
||||||
p->pw_name, allbscore);
|
p->pw_name, allbscore);
|
||||||
else
|
else
|
||||||
pr("You set a new record!\n");
|
printf("You set a new record!\n");
|
||||||
} else
|
} else
|
||||||
pr("The highest is %s with $%d\n", p->pw_name, allbscore);
|
printf("The highest is %s with $%d\n", p->pw_name, allbscore);
|
||||||
lseek(rawscores, 0, SEEK_SET);
|
lseek(rawscores, 0, SEEK_SET);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
@@ -568,13 +582,13 @@ flushi()
|
|||||||
tcflush(0, TCIFLUSH);
|
tcflush(0, TCIFLUSH);
|
||||||
}
|
}
|
||||||
|
|
||||||
int mx[8] = {
|
const int mx[8] = {
|
||||||
0, 1, 1, 1, 0, -1, -1, -1
|
0, 1, 1, 1, 0, -1, -1, -1
|
||||||
};
|
};
|
||||||
int my[8] = {
|
const int my[8] = {
|
||||||
-1, -1, 0, 1, 1, 1, 0, -1
|
-1, -1, 0, 1, 1, 1, 0, -1
|
||||||
};
|
};
|
||||||
float absv[8] = {
|
const float absv[8] = {
|
||||||
1, 1.4, 1, 1.4, 1, 1.4, 1, 1.4
|
1, 1.4, 1, 1.4, 1, 1.4, 1, 1.4
|
||||||
};
|
};
|
||||||
int oldw = 0;
|
int oldw = 0;
|
||||||
@@ -625,14 +639,14 @@ chase(np, sp)
|
|||||||
}
|
}
|
||||||
for (w = i = 0; i < 8; i++)
|
for (w = i = 0; i < 8; i++)
|
||||||
w += wt[i];
|
w += wt[i];
|
||||||
vp = ((rand() >> 6) & 01777) % w;
|
vp = ((random() >> 6) & 01777) % w;
|
||||||
for (i = 0; i < 8; i++)
|
for (i = 0; i < 8; i++)
|
||||||
if (vp < wt[i])
|
if (vp < wt[i])
|
||||||
break;
|
break;
|
||||||
else
|
else
|
||||||
vp -= wt[i];
|
vp -= wt[i];
|
||||||
if (i == 8) {
|
if (i == 8) {
|
||||||
pr("failure\n");
|
printw("failure\n");
|
||||||
i = 0;
|
i = 0;
|
||||||
while (wt[i] == 0)
|
while (wt[i] == 0)
|
||||||
i++;
|
i++;
|
||||||
@@ -647,10 +661,10 @@ spacewarp(w)
|
|||||||
{
|
{
|
||||||
struct point p;
|
struct point p;
|
||||||
int j;
|
int j;
|
||||||
char *str;
|
const char *str;
|
||||||
|
|
||||||
snrand(&you);
|
snrand(&you);
|
||||||
point(&p, COLUMNS / 2 - 8, LINES / 2 - 1);
|
point(&p, COLS / 2 - 8, LINES / 2 - 1);
|
||||||
if (p.col < 0)
|
if (p.col < 0)
|
||||||
p.col = 0;
|
p.col = 0;
|
||||||
if (p.line < 0)
|
if (p.line < 0)
|
||||||
@@ -664,9 +678,11 @@ spacewarp(w)
|
|||||||
penalty += loot / PENALTY;
|
penalty += loot / PENALTY;
|
||||||
}
|
}
|
||||||
for (j = 0; j < 3; j++) {
|
for (j = 0; j < 3; j++) {
|
||||||
clear();
|
erase();
|
||||||
|
refresh();
|
||||||
delay(5);
|
delay(5);
|
||||||
apr(&p, str);
|
mvaddstr(p.line + 1, p.col + 1, str);
|
||||||
|
refresh();
|
||||||
delay(10);
|
delay(10);
|
||||||
}
|
}
|
||||||
setup();
|
setup();
|
||||||
@@ -676,23 +692,30 @@ spacewarp(w)
|
|||||||
void
|
void
|
||||||
snap()
|
snap()
|
||||||
{
|
{
|
||||||
|
#if 0 /* This code doesn't really make sense. */
|
||||||
struct point p;
|
struct point p;
|
||||||
|
|
||||||
if (you.line < 3) {
|
if (you.line < 3) {
|
||||||
pchar(point(&p, you.col, 0), '-');
|
mvaddch(1, you.col + 1, '-');
|
||||||
}
|
}
|
||||||
if (you.line > lcnt - 4) {
|
if (you.line > lcnt - 4) {
|
||||||
pchar(point(&p, you.col, lcnt - 1), '_');
|
mvaddch(lcnt, you.col + 1, '_');
|
||||||
}
|
}
|
||||||
if (you.col < 10) {
|
if (you.col < 10) {
|
||||||
pchar(point(&p, 0, you.line), '(');
|
mvaddch(you.line + 1, 1, '(');
|
||||||
}
|
}
|
||||||
if (you.col > ccnt - 10) {
|
if (you.col > ccnt - 10) {
|
||||||
pchar(point(&p, ccnt - 1, you.line), ')');
|
mvaddch(you.line + 1, ccnt, ')');
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
if (!stretch(&money))
|
if (!stretch(&money))
|
||||||
if (!stretch(&finish))
|
if (!stretch(&finish)) {
|
||||||
|
pchar(&you, '?');
|
||||||
|
refresh();
|
||||||
delay(10);
|
delay(10);
|
||||||
|
pchar(&you, ME);
|
||||||
|
}
|
||||||
|
#if 0
|
||||||
if (you.line < 3) {
|
if (you.line < 3) {
|
||||||
point(&p, you.col, 0);
|
point(&p, you.col, 0);
|
||||||
chk(&p);
|
chk(&p);
|
||||||
@@ -709,47 +732,49 @@ snap()
|
|||||||
point(&p, ccnt - 1, you.line);
|
point(&p, ccnt - 1, you.line);
|
||||||
chk(&p);
|
chk(&p);
|
||||||
}
|
}
|
||||||
fflush(stdout);
|
#endif
|
||||||
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
stretch(ps)
|
stretch(ps)
|
||||||
struct point *ps;
|
const struct point *ps;
|
||||||
{
|
{
|
||||||
struct point p;
|
struct point p;
|
||||||
|
|
||||||
point(&p, you.col, you.line);
|
point(&p, you.col, you.line);
|
||||||
if (abs(ps->col - you.col) < 6) {
|
if ((abs(ps->col - you.col) < (ccnt / 12)) && (you.line != ps->line)) {
|
||||||
if (you.line < ps->line) {
|
if (you.line < ps->line) {
|
||||||
for (p.line = you.line + 1; p.line <= ps->line;
|
for (p.line = you.line + 1; p.line <= ps->line; p.line++)
|
||||||
p.line++)
|
|
||||||
pchar(&p, 'v');
|
pchar(&p, 'v');
|
||||||
|
refresh();
|
||||||
delay(10);
|
delay(10);
|
||||||
for (; p.line > you.line; p.line--)
|
for (; p.line > you.line; p.line--)
|
||||||
chk(&p);
|
chk(&p);
|
||||||
} else {
|
} else {
|
||||||
for (p.line = you.line - 1; p.line >= ps->line;
|
for (p.line = you.line - 1; p.line >= ps->line; p.line--)
|
||||||
p.line--)
|
|
||||||
pchar(&p, '^');
|
pchar(&p, '^');
|
||||||
|
refresh();
|
||||||
delay(10);
|
delay(10);
|
||||||
for (; p.line < you.line; p.line++)
|
for (; p.line < you.line; p.line++)
|
||||||
chk(&p);
|
chk(&p);
|
||||||
}
|
}
|
||||||
return (1);
|
return (1);
|
||||||
} else
|
} else
|
||||||
if (abs(ps->line - you.line) < 3) {
|
if ((abs(ps->line - you.line) < (lcnt/7))
|
||||||
|
&& (you.col != ps->col)) {
|
||||||
p.line = you.line;
|
p.line = you.line;
|
||||||
if (you.col < ps->col) {
|
if (you.col < ps->col) {
|
||||||
for (p.col = you.col + 1; p.col <= ps->col;
|
for (p.col = you.col + 1; p.col <= ps->col; p.col++)
|
||||||
p.col++)
|
|
||||||
pchar(&p, '>');
|
pchar(&p, '>');
|
||||||
|
refresh();
|
||||||
delay(10);
|
delay(10);
|
||||||
for (; p.col > you.col; p.col--)
|
for (; p.col > you.col; p.col--)
|
||||||
chk(&p);
|
chk(&p);
|
||||||
} else {
|
} else {
|
||||||
for (p.col = you.col - 1; p.col >= ps->col;
|
for (p.col = you.col - 1; p.col >= ps->col; p.col--)
|
||||||
p.col--)
|
|
||||||
pchar(&p, '<');
|
pchar(&p, '<');
|
||||||
|
refresh();
|
||||||
delay(10);
|
delay(10);
|
||||||
for (; p.col < you.col; p.col++)
|
for (; p.col < you.col; p.col++)
|
||||||
chk(&p);
|
chk(&p);
|
||||||
@@ -763,7 +788,6 @@ void
|
|||||||
surround(ps)
|
surround(ps)
|
||||||
struct point *ps;
|
struct point *ps;
|
||||||
{
|
{
|
||||||
struct point x;
|
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
if (ps->col == 0)
|
if (ps->col == 0)
|
||||||
@@ -772,27 +796,41 @@ surround(ps)
|
|||||||
ps->line++;
|
ps->line++;
|
||||||
if (ps->line == LINES - 1)
|
if (ps->line == LINES - 1)
|
||||||
ps->line--;
|
ps->line--;
|
||||||
if (ps->col == COLUMNS - 1)
|
if (ps->col == COLS - 1)
|
||||||
ps->col--;
|
ps->col--;
|
||||||
apr(point(&x, ps->col - 1, ps->line - 1), "/*\\\r* *\r\\*/");
|
mvaddstr(ps->line, ps->col, "/*\\");
|
||||||
|
mvaddstr(ps->line + 1, ps->col, "* *");
|
||||||
|
mvaddstr(ps->line + 2, ps->col, "\\*/");
|
||||||
for (j = 0; j < 20; j++) {
|
for (j = 0; j < 20; j++) {
|
||||||
pchar(ps, '@');
|
pchar(ps, '@');
|
||||||
|
refresh();
|
||||||
delay(1);
|
delay(1);
|
||||||
pchar(ps, ' ');
|
pchar(ps, ' ');
|
||||||
|
refresh();
|
||||||
delay(1);
|
delay(1);
|
||||||
}
|
}
|
||||||
if (post(cashvalue, 0)) {
|
if (post(cashvalue, 0)) {
|
||||||
apr(point(&x, ps->col - 1, ps->line - 1), " \ro.o\r\\_/");
|
mvaddstr(ps->line, ps->col, " ");
|
||||||
|
mvaddstr(ps->line + 1, ps->col, "o.o");
|
||||||
|
mvaddstr(ps->line + 2, ps->col, "\\_/");
|
||||||
|
refresh();
|
||||||
delay(6);
|
delay(6);
|
||||||
apr(point(&x, ps->col - 1, ps->line - 1), " \ro.-\r\\_/");
|
mvaddstr(ps->line, ps->col, " ");
|
||||||
|
mvaddstr(ps->line + 1, ps->col, "o.-");
|
||||||
|
mvaddstr(ps->line + 2, ps->col, "\\_/");
|
||||||
|
refresh();
|
||||||
delay(6);
|
delay(6);
|
||||||
}
|
}
|
||||||
apr(point(&x, ps->col - 1, ps->line - 1), " \ro.o\r\\_/");
|
mvaddstr(ps->line, ps->col, " ");
|
||||||
|
mvaddstr(ps->line + 1, ps->col, "o.o");
|
||||||
|
mvaddstr(ps->line + 2, ps->col, "\\_/");
|
||||||
|
refresh();
|
||||||
|
delay(6);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
win(ps)
|
win(ps)
|
||||||
struct point *ps;
|
const struct point *ps;
|
||||||
{
|
{
|
||||||
struct point x;
|
struct point x;
|
||||||
int j, k;
|
int j, k;
|
||||||
@@ -818,8 +856,9 @@ win(ps)
|
|||||||
pchar(&x, '#');
|
pchar(&x, '#');
|
||||||
x.col--;
|
x.col--;
|
||||||
}
|
}
|
||||||
|
refresh();
|
||||||
|
delay(1);
|
||||||
}
|
}
|
||||||
fflush(stdout);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@@ -827,6 +866,7 @@ pushsnake()
|
|||||||
{
|
{
|
||||||
int i, bonus;
|
int i, bonus;
|
||||||
int issame = 0;
|
int issame = 0;
|
||||||
|
struct point tmp;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* My manual says times doesn't return a value. Furthermore, the
|
* My manual says times doesn't return a value. Furthermore, the
|
||||||
@@ -839,18 +879,21 @@ pushsnake()
|
|||||||
issame++;
|
issame++;
|
||||||
if (!issame)
|
if (!issame)
|
||||||
pchar(&snake[5], ' ');
|
pchar(&snake[5], ' ');
|
||||||
|
/* Need the following to catch you if you step on the snake's tail */
|
||||||
|
tmp.col = snake[5].col;
|
||||||
|
tmp.line = snake[5].line;
|
||||||
for (i = 4; i >= 0; i--)
|
for (i = 4; i >= 0; i--)
|
||||||
snake[i + 1] = snake[i];
|
snake[i + 1] = snake[i];
|
||||||
chase(&snake[0], &snake[1]);
|
chase(&snake[0], &snake[1]);
|
||||||
pchar(&snake[1], SNAKETAIL);
|
pchar(&snake[1], SNAKETAIL);
|
||||||
pchar(&snake[0], SNAKEHEAD);
|
pchar(&snake[0], SNAKEHEAD);
|
||||||
for (i = 0; i < 6; i++) {
|
for (i = 0; i < 6; i++) {
|
||||||
if (same(&snake[i], &you)) {
|
if (same(&snake[i], &you) || same(&tmp, &you)) {
|
||||||
surround(&you);
|
surround(&you);
|
||||||
i = (cashvalue) % 10;
|
i = (cashvalue) % 10;
|
||||||
bonus = ((rand() >> 8) & 0377) % 10;
|
bonus = ((random() >> 8) & 0377) % 10;
|
||||||
ll();
|
mvprintw(lcnt + 1, 0, "%d\n", bonus);
|
||||||
pr("%d\n", bonus);
|
refresh();
|
||||||
delay(30);
|
delay(30);
|
||||||
if (bonus == i) {
|
if (bonus == i) {
|
||||||
spacewarp(1);
|
spacewarp(1);
|
||||||
@@ -858,16 +901,18 @@ pushsnake()
|
|||||||
flushi();
|
flushi();
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
flushi();
|
||||||
|
endwin();
|
||||||
if (loot >= penalty) {
|
if (loot >= penalty) {
|
||||||
pr("You and your $%d have been eaten\n",
|
printf("\nYou and your $%d have been eaten\n",
|
||||||
cashvalue);
|
cashvalue);
|
||||||
} else {
|
} else {
|
||||||
pr("The snake ate you. You owe $%d.\n",
|
printf("\nThe snake ate you. You owe $%d.\n",
|
||||||
-cashvalue);
|
-cashvalue);
|
||||||
}
|
}
|
||||||
logit("eaten");
|
logit("eaten");
|
||||||
length(moves);
|
length(moves);
|
||||||
done();
|
exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
@@ -875,7 +920,7 @@ pushsnake()
|
|||||||
|
|
||||||
int
|
int
|
||||||
chk(sp)
|
chk(sp)
|
||||||
struct point *sp;
|
const struct point *sp;
|
||||||
{
|
{
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
@@ -915,33 +960,27 @@ void
|
|||||||
winnings(won)
|
winnings(won)
|
||||||
int won;
|
int won;
|
||||||
{
|
{
|
||||||
struct point p;
|
|
||||||
|
|
||||||
p.line = p.col = 1;
|
|
||||||
if (won > 0) {
|
if (won > 0) {
|
||||||
move(&p);
|
mvprintw(1, 1, "$%d", won);
|
||||||
pr("$%d", won);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
stop(dummy)
|
stop(dummy)
|
||||||
int dummy __attribute__((unused));
|
int dummy __attribute__((__unused__));
|
||||||
{
|
{
|
||||||
signal(SIGINT, SIG_IGN);
|
signal(SIGINT, SIG_IGN);
|
||||||
ll();
|
endwin();
|
||||||
length(moves);
|
length(moves);
|
||||||
done();
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
suspend()
|
suspend()
|
||||||
{
|
{
|
||||||
ll();
|
endwin();
|
||||||
cook();
|
|
||||||
kill(getpid(), SIGTSTP);
|
kill(getpid(), SIGTSTP);
|
||||||
my_raw();
|
refresh();
|
||||||
setup();
|
|
||||||
winnings(cashvalue);
|
winnings(cashvalue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -949,7 +988,7 @@ void
|
|||||||
length(num)
|
length(num)
|
||||||
int num;
|
int num;
|
||||||
{
|
{
|
||||||
pr("You made %d moves.\n", num);
|
printf("You made %d moves.\n", num);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
Reference in New Issue
Block a user