?? shadow.cpp
字號:
// SHADOW.CPP
// Compile as a CONSOLE application or straight DOS16/32 application
// make sure to enable the ANSI.SYS color driver by adding the line:
// DEVICE=C:\WINDOWS\COMMAND\ANSI.SYS
// to your config.sys file
// I N C L U D E S ///////////////////////////////////////////////////////////
#include <io.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
#include <fcntl.h>
#include <memory.h>
#include <malloc.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
// D E F I N E S /////////////////////////////////////////////////////////////
// size of universe in blocks
#define NUM_ROWS 32
#define NUM_COLUMNS 32
// id's for objects and geometry in universe
#define EMPTY_ID ' '
#define WALL_ID '*'
#define LAMP_ID 'l'
#define SANDWICH_ID 's'
#define KEYS_ID 'k'
// general directions
#define EAST 0
#define WEST 1
#define NORTH 2
#define SOUTH 3
// language details
#define MAX_TOKENS 64
#define NUM_TOKENS 28
#define FIRST_WORD 0
#define SECOND_WORD 1
#define THIRD_WORD 2
#define FOURTH_WORD 3
#define FIFTH_WORD 4
#define OBJECT_START 50
#define OBJECT_LAMP 50
#define OBJECT_SANDWICH 51
#define OBJECT_KEYS 52
#define OBJECT_END 52
// directions (adjectives)
#define DIR_1_START 100
#define DIR_1_EAST 100
#define DIR_1_WEST 101
#define DIR_1_NORTH 102
#define DIR_1_SOUTH 103
#define DIR_1_END 103
#define DIR_2_START 150
#define DIR_2_FORWARD 150
#define DIR_2_BACKWARD 151
#define DIR_2_RIGHT 152
#define DIR_2_LEFT 153
#define DIR_2_END 153
// define actions (verbs)
#define ACTION_START 200
#define ACTION_MOVE 200
#define ACTION_TURN 201
#define ACTION_SMELL 202
#define ACTION_LOOK 203
#define ACTION_LISTEN 204
#define ACTION_PUT 205
#define ACTION_GET 206
#define ACTION_EAT 207
#define ACTION_INVENTORY 208
#define ACTION_WHERE 209
#define ACTION_EXIT 210
#define ACTION_END 210
// articles
#define ART_START 300
#define ART_THE 300
#define ART_END 300
// prepositions
#define PREP_START 325
#define PREP_IN 325
#define PREP_ON 326
#define PREP_TO 327
#define PREP_DOWN 328
#define PREP_END 328
// the phrases that add meaning to us, but not to the computer
#define PHRASE_TO 0
#define PHRASE_THE 1
#define PHRASE_TO_THE 2
#define PHRASE_DOWN 3
#define PHRASE_DOWN_THE 4
// S T R U C T U R E S ///////////////////////////////////////////////////////
// this is the structure for a single token
typedef struct token_typ
{
char symbol[16]; // the string that represents the token
int value; // the integer value of the token
} token, *token_ptr;
// this is the structure used to hold a single string that is used to
// describe something in the game like a smell, sight, sound...
typedef struct info_string_typ
{
char type; // the type of info string i.e. what does it describe
char string[100]; // the actual description string
} info_string, *info_string_ptr;
// this structure holds everything pertaining to the player
typedef struct player_typ
{
char name[16]; // name of player
int x,y; // postion of player
int direction; // direction of player, east,west north,south
char inventory[8]; // objects player is holding (like pockets)
int num_objects; // number of objects player is holding
} player, *player_ptr;
// this structure holds an object
typedef struct object_typ
{
char thing; // the actual object
int x,y; // position of object in universe
} object, *object_ptr;
// P R O T O T Y P E S //////////////////////////////////////////////////////
void Introduction();
int Vision_System(int depth,
int direction,
object *stuff,
int *num_objects);
int Check_For_Phrase(int phrase,int index);
void Print_Info_Strings(info_string strings[],char where);
char *Get_Line(char *buffer);
int Get_Token(char *input,char *output,int *current_pos);
int Extract_Tokens(char *string);
void Verb_Parser(void);
int Verb_MOVE(void);
int Verb_TURN(void);
int Verb_SMELL(void);
int Verb_LOOK(void);
int Verb_LISTEN(void);
int Verb_PUT(void);
int Verb_GET(void);
int Verb_EAT(void);
int Verb_INVENTORY(void);
int Verb_EXIT(void);
int Verb_WHERE(void);
// G L O B A L S //////////////////////////////////////////////////////////////
// this is the entire "language" of the language.
token language[MAX_TOKENS] = {
{"LAMP", OBJECT_LAMP },
{"SANDWICH", OBJECT_SANDWICH },
{"KEYS", OBJECT_KEYS },
{"EAST", DIR_1_EAST },
{"WEST", DIR_1_WEST },
{"NORTH", DIR_1_NORTH },
{"SOUTH", DIR_1_SOUTH },
{"FORWARD", DIR_2_FORWARD },
{"BACKWARD", DIR_2_BACKWARD },
{"RIGHT", DIR_2_RIGHT },
{"LEFT", DIR_2_LEFT },
{"MOVE", ACTION_MOVE },
{"TURN", ACTION_TURN },
{"SMELL", ACTION_SMELL },
{"LOOK", ACTION_LOOK },
{"LISTEN", ACTION_LISTEN },
{"PUT", ACTION_PUT },
{"GET", ACTION_GET },
{"EAT", ACTION_EAT },
{"INVENTORY", ACTION_INVENTORY},
{"WHERE", ACTION_WHERE },
{"EXIT", ACTION_EXIT },
{"THE", ART_THE },
{"IN", PREP_IN },
{"ON", PREP_ON },
{"TO", PREP_TO },
{"DOWN", PREP_DOWN },
};
// now for the definition of the universe and the objects within it
// this array holds the geometry of the universe
// l - living room
// b - bedroom
// k - kitchen
// w - washroom
// h - hall way
// r - restroom
// e - entry way
// o - office
// ^
// NORTH
//
// < WEST EAST >
//
// SOUTH
// v
char *universe_geometry[NUM_ROWS]={"********************************",
"*lllllllll*bbbbbbbbbbbbbbbbbbbb*",
"*llllllllll*bbbbbbbbbbbbbbbbbbb*",
"*lllllllllll*bbbbbbbbbbbbbbbbbb*",
"*llllllllllll*bbbbbbbbbbbbbbbbb*",
"*llllllllllll*bbbbbbbbbbbbbbbbb*",
"*llllllllllll*bbbbbbbbbbbbbbbbb*",
"*llllllllllll*bbbbbbbbbbbbbbbbb*",
"*llllllllllll*bbbbbbbbbbbbbbbbb*",
"*llllllllllll*bbbbbbbbbbbbbbbbb*",
"*llllllllllll*bbbbbbbbbbbbbbbbb*",
"*llllllllllll*bbbb*rrr**********",
"*lllllllllllhhhhhh*rrrrrrrrrrrr*",
"*lllllllllllhhhhhh*rrrrrrrrrrrr*",
"*lllllllllhhh******rrrrrrrrrrrr*",
"*********hhhh*rrrrrrrrrrrrrrrrr*",
"*kkkkkkk*hhhh*rrrrrrrrrrrrrrrrr*",
"*kkkkkkk*hhhh*rrrrrrrrrrrrrrrrr*",
"*kkkkkkk*hhhh*rrrrrrrrrrrrrrrrr*",
"*kkkkkkkhhhhh*******************",
"*kkkkkkkhhhhhhhhhhhwwwwwwwwwwww*",
"*kkkkkkkhhhhhhhhhhhwwwwwwwwwwww*",
"*kkkkkkk*hhhhhhhhhhwwwwwwwwwwww*",
"*kkkkkkk*hhhh*ooooo*************",
"*kkkkkkk*hhhh*ooooooooooooooooo*",
"*kkkkkkk*hhhh*ooooooooooooooooo*",
"*kkkkkk*hhhhh*ooooooooooooooooo*",
"*******hhhhhh*ooooooooooooooooo*",
"*eeeeeeeeeeee*ooooooooooooooooo*",
"*eeeeeeeeeeee*ooooooooooooooooo*",
"*eeeeeeeeeeee*ooooooooooooooooo*",
"********************************",};
// this array holds the objects within the universe
// l - lamp
// s - sandwich
// k - keys
// ^
// NORTH
//
// < WEST EAST >
//
// SOUTH
// v
char *universe_objects[NUM_ROWS]={" ",
" l k ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" l ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" s ",
" ",
" ",
" ",
" ",
" s ",
" l ",
" ",
" ",};
// these info strings hold the views in each room
info_string views[]={
{'l',"You see an expansive white room with a vaulted ceiling. The walls are adorned "},
{'l',"with medieval art. To the North, is a plate glass window through which colored"},
{'l',"strands of light pierce. They reflect off the carpeted floor and create a "},
{'l',"silhouette of the towering pines just outdside. In the Northeast corner of "},
{'l',"the room, you see a fire place with a half burnt log in it. Finally, against "},
{'l',"the West wall there's a white leather couch and in each corner of the room "},
{'l',"are large green palms potted in hexogonal black pots. "},
{'b',"You see a black lacquer bedroom set surrounding a king size platform bed."},
{'b',"On the walls, you see pictures of mystical landscapes and underwater cities. "},
{'b',"To the North there is a window thru which you see a group of large trees just "},
{'b',"beyond a small pond. On the floor of the room you see black silk stockings "},
{'b',"and lingerie thrown with abandon about the area. "},
{'k',"You are surrounded by stone washed granite counters. On the counters are the"},
{'k',"normal appliances found in a kitchen. To the West there is a large glass "},
{'k',"door refrigerator with a varitable plethora of food. Against the South wall"},
{'k',"there is a small nook with a white refuge container. Above your head dangle"},
{'k',"down many cooking utensils and exotic pans suspended from a anodized "},
{'k',"aluminum structure. "},
{'w',"There is a large vanity mirror and a black porcellin wash basin. To the East"},
{'w',"is a rack of black and white towels hung on brass rails. On the counter "},
{'w',"surrounding the walls there are small spherically shaped soap balls in a "},
{'w',"myriad of colors set in cyrstal dishes. The floor is made of black and white"},
{'w',"marble with a hint of grey running thru it. "},
{'h',"You see an ordinary hallway with track lighting above head. "},
{'r',"You see a large wash area with two basins. To the West through a glass "},
{'r',"enclosure you see the outline of a young woman apperantly bathing... To "},
{'r',"the East you see a second smaller room with many plants hanging from the"},
{'r',"celing along with the shadow of a dark,muscular man moving around. On "},
{'r',"the floor below you are plush tapestries of Egyption origin. "},
{'e',"To the West you see a small opening into what appears to be a kitchen. "},
{'e',"The lights are low and you can't make out much more in this direction. "},
{'e',"Under your feet is a large black rectangular cut of carpet. Lastly, leading to"},
{'e',"the East and North are hallways to the remainder of the house. "},
{'o',"You are astounded by the amount of computer equipment in every corner of the "},
{'o',"room. To the South is a Silicon Graphics OYNX Super Computer, the screen of "},
{'o',"which seems to displaying a mesmorizing array of mathematical equations. To "},
{'o',"the North you are faced with literally hundreds of books on every topic from "},
{'o',"quantum mechanics to molecular bio-chemistry. Against the East wall there "},
{'o',"is a full collection of electrical engineering equipment with a oscilloscope "},
{'o',"displaying a curious waveform apparently an input from a black box resting on"},
{'o',"the floor. As you look around the walls of the room, you see schematics of "},
{'o',"digital hardware and paintings of great scientific pioneers such as Einstein,"},
{'o',"Newton and Maxwell. Strewn about the floor are small electronic "},
{'o',"components and pieces of paper with scribbles upon them. "},
{'X',""}, // terminate
};
// these info strings hold the smells in each room
info_string smells[]={
{'l',"You smell the sweet odor of Jasmine with an undertone of potpourri. "},
{'b',"The sweet smell of perfume dances within your nostrils...Realities possibly. "},
{'k',"You take a deep breath and your senses are tantallized with the smell of"},
{'k',"tender breasts of chicken marinating in a garlic sauce. Also, there is "},
{'k',"a sweet berry smell emanating from the oven. "},
{'w',"You are almost overwhelmed by the smell of bathing fragrance as you"},
{'w',"inhale. "},
{'h',"You smell nothing to make note of. "},
{'r',"Your nose is filled with steam and the smell of baby oil... "},
{'e',"You smell pine possibly from the air coming thru a small orifice near"},
{'e',"the front door. "},
{'o',"You are greeted with the familiar odor of burning electronics. As you inhale"},
{'o',"a second time, you can almost taste the rustic smell of aging books. "},
{'X',""}, // terminate
};
// these info strings hold the sounds in each room
info_string sounds[]={
{'l',"You hear the faint sounds of Enigma playing in the background along with"},
{'l',"the wind howling against the exterior of the room. "},
{'b',"You hear the wind rubbing against the window making a sound similar to"},
{'b',"sheets being pulled off a bed. "},
{'k',"You hear expansion of the hot ovens along with the relaxing sounds produced"},
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -