?? shadow.cpp
字號:
} break;
case DIR_2_LEFT: // parry left
{
// compute translation factors using look up tables
dx = left_x[you.direction];
dy = left_y[you.direction];
} break;
} // end switch direction of motion
// based on the translation factors move the player
you.x+=dx;
you.y+=dy;
// test for collision with a wall
if (universe_geometry[you.y][you.x]==WALL_ID)
{
// let' user know he hit a wall
printf("\nOuch! that hurt. Can't you see this wall %s?\n",you.name);
// back player up
you.x-=dx;
you.y-=dy;
} // end collision detection
else
{
printf("\nYou take a few steps.\n");
} // end else ok
return(1);
} // end if direction is valid
else
{
printf("\n%\"%s\" is an invalid sentence.",global_input);
printf("\nI don't understand the direction you wish me to move in?");
return(0);
} // end else invalid direction
} // end Verb_MOVE
////////////////////////////////////////////////////////////////////////////////
int Verb_TURN(void)
{
// this function will figure out which way the player wants to turn,
// then turn the player and test for syntax errors
int token_index;
// if the player look in general then give him the full view, otherwise
// look for walls and objects
token_index=0;
// first test for a direction
if (num_tokens==1)
{
// no direction, so tell user to give one next time
printf("\n%s, I don't know which way to turn?\n",you.name);
return(0);
} // end if only turn
else
{
// check if the next word is a direction and if so turn in that
// direction
// first test if the words 'to' or 'to the' are inserted bewteen action
// verb and noun (object)
token_index=1;
if (Check_For_Phrase(PHRASE_TO_THE,token_index))
{
// consume preposition since it has to bearing on the final
// meaning sentence
// index token scan to directon
token_index=3;
} // end if prep and article
else
if (Check_For_Phrase(PHRASE_TO,token_index))
{
// consume preposition since it has to bearing on the final
// meaning sentence
// index token scan to directon
token_index=2;
} // end if prep
// at this point the token_index is pointing to the direction
if (sentence[token_index] >= DIR_1_START &&
sentence[token_index] <= DIR_1_END)
{
// at this point we finally know what the user is asking for, so
// let's do it
// update the players direction based on new direction
you.direction = sentence[token_index]-DIR_1_START;
printf("\nYou turn...");
return(1);
} // end if direction is valid
else
{
printf("\n%\"%s\" is an invalid sentence.",global_input);
printf("\nI don't understand the direction you wish me to turn to?");
return(0);
} // end else invalid direction
} // end else
} // end Verb_TURN
////////////////////////////////////////////////////////////////////////////////
int Verb_SMELL(void)
{
// this function will just smell without paying attention to the rest
// of the sentence
if (num_tokens==1)
{
Print_Info_Strings(smells,universe_geometry[you.y][you.x]);
return(1);
} // end if smell
else
{
printf("\n%\"%s\" is an invalid sentence.",global_input);
printf("\nI don't understand what you want me to smell?");
return(0);
} // end else invalid
} // end Verb_SMELL
////////////////////////////////////////////////////////////////////////////////
int Verb_LOOK(void)
{
// this function will look in the direction commanded to
int token_index, // current word being processed
direction, // direction player wants to look
num_items, // number of objects seen during vision scan
index; // used as look index
object objects[8]; // holds the objects
// if the player look in general then give him the full view, otherwise
// look for walls and objects
token_index=0;
// first test for a direction
if (num_tokens==1)
{
// no direction, so give long version
Print_Info_Strings(views,universe_geometry[you.y][you.x]);
return(1);
} // end if only look
else
{
// check if the next word is a direction and if so look in that
// direction
// first test if the words 'to' or 'to the' are inserted bewteen action
// verb and noun (object)
token_index=1;
if (Check_For_Phrase(PHRASE_TO_THE,token_index))
{
// consume preposition since it has to bearing on the final
// meaning sentence
// index token scan to directon
token_index=3;
} // end if prep and article
else
if (Check_For_Phrase(PHRASE_TO,token_index))
{
// consume preposition since it has to bearing on the final
// meaning sentence
// index token scan to directon
token_index=2;
} // end if prep
// at this point the token_index is pointing to the direction
if (sentence[token_index] >= DIR_1_START &&
sentence[token_index] <= DIR_1_END)
{
// at this point we finally know what the user is asking for, so
// let's do it
printf("\nYou see walls");
// compute direction
direction = sentence[token_index] - DIR_1_START;
// test if there are any objects in sight
if (Vision_System(24,direction,objects,&num_items))
{
// print out what was seen
printf(" and,");
for (index=0; index<num_items; index++)
{
// print out the correct description
switch(objects[index].thing)
{
case LAMP_ID:
{
printf("\na torch lamp.");
} break;
case KEYS_ID:
{
printf("\na set of car keys.");
} break;
case SANDWICH_ID:
{
printf("\na turkey sandwich.");
} break;
default:break;
} // end switch
} // end for index
} // end if we saw something
return(1);
} // end if direction is valid
else
{
printf("\n%\"%s\" is an invalid sentence.",global_input);
printf("\nI don't understand the direction you wish me to look in?");
return(0);
} // end else invalid direction
} // end else
} // end Verb_LOOK
////////////////////////////////////////////////////////////////////////////////
int Verb_LISTEN(void)
{
// this function will just listen without paying attention to the rest of
// the sentence
if (num_tokens==1)
{
Print_Info_Strings(sounds,universe_geometry[you.y][you.x]);
return(1);
} // end if sound
else
{
printf("\n%\"%s\" is an invalid sentence.",global_input);
printf("\nI don't understand what you want me to listen to?");
return(0);
} // end else invalid
} // end Verb_LISTEN
////////////////////////////////////////////////////////////////////////////////
int Verb_PUT(void)
{
// this function will put down the object requested
// this look up table is used to convert object token numbers into object id's
static char object_to_id[]={'l','s','k'};
int token_index, // current toek nbeing precessed
index; // loop index
char object; // object we are currently looking at
token_index=0;
// first test for a object
if (num_tokens==1)
{
// no object, so tell user to give one next time
printf("\n%s, I don't know what you want me to put down?\n",you.name);
return(0);
} // end if only put
else
{
// check if the next word is an object, if so put is down
// direction
// first test if the words 'down' or 'down the' are inserted bewteen action
// verb and noun (object)
token_index=1;
if (Check_For_Phrase(PHRASE_DOWN_THE,token_index))
{
// consume preposition since it has to bearing on the final
// meaning sentence
// index token scan to object
token_index=3;
} // end if prep and article
else
if (Check_For_Phrase(PHRASE_DOWN,token_index))
{
// consume preposition since it has to bearing on the final
// meaning sentence
// index token scan to object
token_index=2;
} // end if prep
// at this point the token_index is pointing to the object
if (sentence[token_index] >= OBJECT_START &&
sentence[token_index] <= OBJECT_END)
{
// at this point we finally know what the user is asking for, so
// let's do it
// check to see if object is in inventory..if so then put it down
// in the current square
// first convert object token to object id
object = object_to_id[sentence[token_index]-OBJECT_START];
// do scan in pockets
for (index=0; index<you.num_objects; index++)
{
// test if this pocket has the object we are looking for
if (you.inventory[index]==object)
{
// take object out of pocket
you.inventory[index] = EMPTY_ID;
// decrement number of objects
you.num_objects--;
// place the object back into object universe
universe_objects[you.y][you.x] = object;
// say something
printf("\nPutting down the ");
switch(object)
{
case LAMP_ID:
{printf("torch lamp.\n");}break;
case SANDWICH_ID:
{printf("sandwich.\n");}break;
case KEYS_ID:
{printf("keys.\n");}break;
default:break;
} // end switch
// **************************************************************
// if the player puts the keys in the kitchen where they should be
// then he will win! Test that condition here
if (object==KEYS_ID && universe_geometry[you.y][you.x]=='k')
{
printf("\nCongratulation %s! You have solved the game.\n",you.name);
} // end if win
// **************************************************************
return(1);
} // end if found object
} // end for index
// if we get this far then the player wasn't carrying the requested
// object to be dropped
printf("\n%s, you don't have that to drop!\n",you.name);
return(1);
} // end if object is valid
else
{
printf("\n%\"%s\" is an invalid sentence.",global_input);
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -