home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Devil's Doorknob BBS Capture (1996-2003)
/
devilsdoorknobbbscapture1996-2003.iso
/
W
/
BTIMPY.ZIP
/
TEST1.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-09-06
|
18KB
|
711 lines
#include <stdio.h>
#include <string.h>
#include <io.h>
#include <fcntl.h>
#define DATAF "quest.dat"
void nogo();
void help();
void ballroom();
void entrance();
void stairs();
void living();
void patio();
void quit();
void landing();
void dining();
void study();
void green();
void kitchen();
void drive();
void bath();
void pantry();
void backpat();
void command();
void pausescr();
int usernum, /* user number for the user */
age, /* age of the user */
screenchars, /* chars/line user has specified */
screenlines, /* lines/screen user has specified */
sl, /* sec lev for user (0-255) */
so, /* non-zero if user is sysop (sl=255) */
cs, /* non-zero if user is co-sysop */
okansi, /* non-zero if user can support ANSI */
incom, /* non-zero if user is calling remotely */
comport; /* com port user is on */
char name[81], /* name/alias of user */
realname[81], /* real name of user */
callsign[10], /* amateur radio callsign of user */
sex, /* sex of user, M or F */
laston[81], /* date user was last on */
gfiles[81], /* directory for text files, ends in \ */
data[81], /* directory for non-text files, ends in \ */
sysoplog[81], /* full path & filename for sysop log */
curspeed[81]; /* speed user is on at, "KB" if local */
double gold, /* gold user has */
timeallowed; /* number of seconds before user logged off */
int numdaters;
char works[21],
cho;
FILE *df,*qf; /* user data file */
struct{
char name[81],
sex,
phone[20],
answ[44], /* array of answers to 43 questions */
coin[2], /* 3 short answer strings */
match[2],
lamp[2];
int age; /* p is the current person. */
} p,x; /* x is someone being compared */
/* to the current user. */
int read_in_data(char *fn)
{
char buf[1024]; /* This is where the file will be put for fast access. */
char *ptr[30]; /* This will hold pointers to parts of the buf array,
acting as an index. */
int i,f,len,i1; /* i, i1 = loop control variables;
len = number of bytes read from file;
f = file descriptor number for the filename. */
float fl; /* This holds a temporary value of the user's gold. */
/* fn = the filename of the CHAIN.TXT file. */
f=open(fn,O_RDONLY | O_BINARY); /* Open the file for input as a binary file,
i.e. without character translations. */
if (f<0) { /* If the file descriptor (f) is less than
0 (i.e. it is -1) then abort the
function and return error (-1). */
return(-1);
}
i1=1; /* Initialize i1. */
ptr[0]=buf; /* Point the first index to the first character
of the buf array. */
len=read(f,(void *)buf,1024); /* Read in from the file f into buf up to
1024 characters (until the EOF is reached)
and return the actual number of characters
read in len. */
close(f); /* We're finished with the file so put it
away. */
for (i=0; i<len; i++) /* This for loop goes through the buf array
(which now contains the contents of the
chain info file) and assigns indices to
the ptr array of pointers. It causes all
returns to be mapped into null characters
(ASCII 0) for use as strings, and skips
over the following LF character. In this
way, ptr will end up pointing to a bunch
of character strings. */
if (buf[i]==13) {
buf[i]=0;
ptr[i1++]=&buf[i+2];
}
while (*ptr[6]==32) /* Remove leading spaces for the float
values by incrementing the pointer
by one character. */
++(ptr[6]);
while (*ptr[15]==32)
++(ptr[15]);
usernum=atoi(ptr[0]); /* From here on it is straight translation
from the ptr index array into the global
variables. */
/* Get the user number from index 0. */
strcpy(name,ptr[1]); /* Get the name, real name, and callsign. */
strcpy(realname,ptr[2]);
strcpy(callsign,ptr[3]);
age=atoi(ptr[4]); /* Get the user's age. */
sex=*ptr[5]; /* Get the user's sex. */
sscanf(ptr[6],"%f",&fl); /* These two lines read in the user's gold
and typecast it into a double float. */
gold=(double)fl;
strcpy(laston,ptr[7]); /* Get his date of last being on. */
screenchars=atoi(ptr[8]); /* Get the size of his screen. */
screenlines=atoi(ptr[9]);
sl=atoi(ptr[10]); /* Get his seclev. */
so=atoi(ptr[11]); /* Is he a sysop? (nonzero if true) */
cs=atoi(ptr[12]); /* How about a cosysop? */
okansi=atoi(ptr[13]); /* Does he use ANSI graphics? */
incom=atoi(ptr[14]); /* Is he calling remotely (1) or not? */
sscanf(ptr[15],"%f",&fl); /* These two lines read in the number of
seconds left to the user and typecast
the value into a double float. */
timeallowed=(double)fl;
strcpy(gfiles,ptr[16]); /* What is the gfiles dir? */
strcpy(data,ptr[17]); /* What is the data dir? */
strcpy(sysoplog,gfiles); /* These two lines get the full pathname
for the sysoplog file. */
strcat(sysoplog,ptr[18]);
strcpy(curspeed,ptr[19]); /* A string containing the user's
bps/baud rate or KB if local. */
comport=atoi(ptr[20]); /* The user's comport if remote. */
return(0); /* Return and give a 'we read it in fine'
message. */
}
char upcase(char ch)
/* This converts a character to uppercase */
{
if ((ch > '`') && (ch < '{'))
ch = ch - 32;
return(ch);
}
void quit()
{
exit(0);
}
void nogo()
{
printf("\n
You can't go that way!\n");
}
void pausescr()
/* This will pause output, displaying the [PAUSE] message, and wait for
* a key to be hit.
*/
{
printf("\n
[
Pausing Bama
!
]\x1b[15D");
getche();
printf(" \x1b[15D");
}
void help()
{
printf("\n
Game Commands:\n");
printf("
N North\n");
printf("S South\n");
printf("E East\n");
printf("W West\n");
printf("? Help\n");
printf("U Up\n");
printf("D Down\n");
printf("Q Quit\n");
}
void command()
{
if (cho=='?')printf("\b\b
Help");
if (cho=='N')printf("\b\b
North");
if (cho=='S')printf("\b\b
South");
if (cho=='W')printf("\b\b
West");
if (cho=='E')printf("\b\b
East");
if (cho=='U')printf("\b\b
Up");
if (cho=='D')printf("\b\b
Down");
if (cho=='Q')printf("\b\b
Quit");
if (cho=='L')printf("\b\b
Left");
if (cho=='R')printf("\b\b
Right");
}
void entrance()
{
printf("\n\n
You are in the Entrance Hall\n");
printf("Command? ");
cho=upcase(getche());
command();
switch(cho) {
case 'N':
stairs();
case 'S':
nogo();
puts("
A locked door blocks your exit.");
entrance();
case 'E':
ballroom();
case 'W':
living();
case '?':
help();
entrance();
case 'Q':
quit();
default:
entrance();
}
}
void ballroom()
{
printf("\n\n
You are in the ballroom\n");
printf("Command? ");
cho=upcase(getche());
command();
switch(cho) {
case 'N':
patio();
case 'S':
puts("\n
There are only barred windows here.");
ballroom();
case 'E':
puts("\n
There are only barred windows here.");
ballroom();
case 'W':
entrance();
case '?':
help();
ballroom();
case 'Q':
quit();
default:
ballroom();
}
}
void stairs()
{
printf("\n\n
You are at the bottom of a staircase.\n");
printf("Command? ");
cho=upcase(getche());
command();
switch(cho) {
case 'N':
nogo();
stairs();
case 'S':
entrance();
case 'E':
nogo();
stairs();
case 'W':
nogo();
stairs();
case 'U':
landing();
case 'D':
puts("\n
You are already down.");
stairs();
case '?':
help();
stairs();
case 'Q':
quit();
default:
stairs();
}
}
void living()
{
printf("\n\n
You are in the living room.\n");
printf("Command? ");
cho=upcase(getche());
command();
switch(cho) {
case 'N':
dining();
case 'S':
puts("\n
There are only barred windows here.");
living();
case 'E':
entrance();
case 'W':
study();
case '?':
help();
living();
case 'Q':
quit();
default:
living();
}
}
void patio()
{
printf("\n\n
You are outside on the patio.\n");
printf("Command? ");
cho=upcase(getche());
command();
switch(cho) {
case 'N':
puts("\n
A huge wall of shrubbery blocks your way!");
patio();
case 'S':
ballroom();
case 'E':
puts("\n
You wouldn't survive the drop off the patio.");
patio();
case 'W':
puts("\n
You can't walk through the side of the house!");
patio();
case '?':
help();
patio();
case 'Q':
quit();
default:
patio();
}
}
void landing()
{
printf("\n\n
You are on the landing at the top of the stairs.\n");
printf("Command? ");
cho=upcase(getche());
command();
switch(cho) {
case 'N':
hallone();
case 'S':
nogo();
landing();
case 'E':
nogo();
landing();
case 'W':
nogo();
landing();
case 'U':
puts("\n
You are already up!");
landing();
case 'D':
stairs();
case '?':
help();
landing();
case 'Q':
quit();
default:
landing();
}
}
void dining()
{
printf("\n\n
You are in the vast dining hall.\n");
printf("Command? ");
cho=upcase(getche());
command();
switch(cho) {
case 'N':
backpat();
case 'S':
living();
case 'E':
kitchen();
case 'W':
nogo();
dining();
case '?':
help();
dining();
case 'Q':
quit();
default:
dining();
}
}
void study()
{
printf("\n\n
You are in the study.\n");
printf("Command? ");
cho=upcase(getche());
command();
switch(cho) {
case 'N':
green();
case 'S':
nogo();
study();
case 'E':
living();
case 'W':
nogo();
study();
case '?':
help();
study();
case 'Q':
quit();
default:
study();
}
}
void green()
{
printf("\n\n
You are now in the greenhouse.\n");
printf("Command? ");
cho=upcase(getche());
command();
switch(cho) {
case 'N':
backpat();
case 'S':
study();
case 'E':
nogo();
green();
case 'W':
nogo();
green();
case '?':
help();
green();
case 'Q':
quit();
default:
green();
}
}
void kitchen()
{
printf("\n\n
You are in the kitchen.\n");
printf("Command? ");
cho=upcase(getche());
command();
switch(cho) {
case 'N':
drive();
case 'S':
bath();
case 'E':
pantry();
case 'W':
dining();
case '?':
help();
kitchen();
case 'Q':
quit();
default:
kitchen();
}
}
void drive()
{
printf("\n\n
You are on the driveway.\n");
printf("Command? ");
cho=upcase(getche());
command();
switch(cho) {
case 'N':
puts("\n
A huge iron fence blocks your way.");
drive();
case 'S':
kitchen();
case 'E':
puts("\n
A huge locked gate blocks your way.");
drive();
case 'W':
puts("\n
You can't get through the bushes.");
drive();
case '?':
help();
drive();
case 'Q':
quit();
default:
drive();
}
}
void bath()
{
printf("\n\n
You are in the bathroom.\n");
printf("Command? ");
cho=upcase(getche());
command();
switch(cho) {
case 'N':
kitchen();
case 'S':
puts("\n
You see the toilet.");
bath();
case 'E':
puts("\n
You see yourself in the mirror.");
bath();
case 'W':
puts("\n
Ooo! See the pretty wallpaper!");
bath();
case '?':
help();
bath();
case 'Q':
quit();
default:
bath();
}
}
void pantry()
{
printf("\n\n
You are in the pantry.\n");
printf("Command? ");
cho=upcase(getche());
command();
switch(cho) {
case 'N':
nogo();
pantry();
case 'S':
nogo();
pantry();
case 'E':
nogo();
pantry();
case 'W':
kitchen();
case '?':
help();
pantry();
case 'Q':
quit();
default:
pantry();
}
}
void backpat()
{
printf("\n\n
You are on the back patio.\n");
printf("Command? ");
cho=upcase(getche());
command();
switch(cho) {
case 'N':
nogo();
backpat();
case 'S':
puts("\n\n
There are two doors, left to the dining room, right to the greenhouse.");
printf("Which door? (L or R) ");
cho=upcase(getche());
switch(cho) {
case 'L':
printf("\b\b
Left");
dining();
case 'R':
printf("\b\b
Right");
green();
default:
backpat();
}
case 'E':
puts("\n
There are bushes in your way.");
backpat();
case 'W':
puts("\n
There are bushes in your way.");
case '?':
help();
backpat();
case 'Q':
quit();
default:
backpat();
}
}
void newperson()
{
int qn; /* question number */
char question[81], /* stores the question read in from a file */
choice; /* stores user's answer */
FILE *fp;
char ch;
if(!(fp=fopen("QUEST.ANS", "r"))) {
printf("cannot open");
exit(1);
}
while((ch=getc(fp))!=EOF)
printf("%c", ch);
fclose(fp);
pausescr();
printf("
You are a new prospect.\n");
strcpy(p.name,name);
p.sex=sex;
printf("Would you like to play?\n");
cho=getche();
if (cho=='N' || cho=='n') {
printf("\nToo bad. C-ya!\n");
exit(0); }
printf("\n
Oh Joy of Joys! You are going to play!\n\n");
p.age=age;
printf("
Welcome, %s.\n",p.name);
printf("Have fun and enjoy the game!\n\n");
printf("You have just stepped into a large seemingly abandoned mansion. You are\n");
printf("standing in the entrace hall. Suddenly the large heavy front door swings\n");
printf("shut behind you and locks itself. You must explore this huge structure\n");
printf("and try to find your way home. You may need to pick up some seemingly useless\n");
printf("items on the way.");
printf("\n\n");
entrance();
}
void main(int argc, char *argv[])
{
int zots=0; /* zots is a flag to tell if the user is new */
/* zots==1 means his record has been found, and
his record will not be appended at the end. */
argc=argc;
argv=argv;
if (read_in_data("chain.txt")==-1) { /* Try to read in the parameter file
and if it returns the -1 error message,
quit the program with an error message. */
printf("\nData file not found\n\n");
/* abort(); */
}
if (okansi) printf("\x1B[2J");
printf("Welcome to Quest For Freedom!\n");
printf("This game is brought to you by Stimpy\n");
printf("Sysop of The Devil's Doorknob (410-442-1601)\n");
df=fopen(DATAF,"r");
if (df==NULL)
{
df=fopen(DATAF,"w");
printf("Initializing data file.\n\n");
strcpy(p.name,"nul");
p.sex='N';
strcpy(p.phone,"555-1212");
strcpy(p.answ,"2222222222222222222222222222222222222222222");
strcpy(p.coin,"N"); strcpy(p.match,"N"); strcpy(p.lamp,"N");
fwrite(&p,sizeof(p),1,df);
}
else
{
printf("Loading data file.\n\n");
pausescr();
do
{
zots=fread(&p,sizeof(p),1,df);
} while ((zots==1) && (strcmp(name,p.name)!=0));
}
fclose(df);
if (zots==0)
{
newperson();
df=fopen(DATAF,"a");
fwrite(&p,sizeof(p),1,df);
fclose(df);
}
else printf("Welcome back, %s.\n",name);
entrance();
}