⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shadow.cpp

📁 一个游戏 F1:记分模式,过关加500分
💻 CPP
📖 第 1 页 / 共 5 页
字号:
////////////////////////////////////////////////////////////////////////////////

int Vision_System(int depth,         // depth of scan
                  int direction,     // direction of scan N,E,S,W
                  object *stuff,     // objects seen in scan
                  int *num_objects)  // number of objects seen in scan

{
// this function is rather complex. It is responsible for the vision of
// the player. It works by scanning a upside down pryamid of squares in
// front of the player.  The objects within this vision window will be
// returned in the objects array along withe the number of them.
// the vision window is built up by consequtively scanning rows of blocks
// in the geometry universe along with testing the objects universe for
// instances of objects. It is sort of like ray casting, but the distance
// is irrelevant and only four directions are used.  For example if the
// player was looking north and a depth of 3 was sent for the scan then the
// scan pattern would look like:
//
//       .....
//        ...
//         P
// where 'P' is the position of player and the '.' is a scanned block
// similary a scan of depth 5 to the east would like like
//      .
//      ..
//      ...
//      ....
//      ....P
//      ....
//      ...
//      ..
//      .
// note: the field of view (FOV) will always be 90 degrees
// anyway the function is basically used for the "LOOK" verb and the "GET"
// verb and I admit that the code is redundant for each case, but to merge
// it all would make it too hard to follow!

int x,y,           // used to hold current universe cell location
    index,         // loop index
    scan_level;    // current level or iteration of the scan

*num_objects=0;

// which direction is vision requested in?

switch(direction)
      {

      case NORTH:
           {
           // scan like this
           //  .....
           //   ...
           //    P

           for (y=you.y,scan_level=0; y>=(you.y-depth); y--,scan_level++)
               {
               for (x=you.x-scan_level; x<=you.x+scan_level; x++)
                   {
                   // x,y is test point, make sure it is within the universe
                   // boundaries and within the same room

                   if (x>=1 && x<NUM_COLUMNS-1 &&
                       y>=1 && x<NUM_ROWS-1 &&
                       universe_geometry[y][x]==universe_geometry[you.y][you.x])


                      {
                      // test to see if square has an object in it

                      if (universe_objects[y][x]!=' ')
                         {
                         // insert the object into object list

                         stuff[*num_objects].thing = universe_objects[y][x];
                         stuff[*num_objects].x     = x;
                         stuff[*num_objects].y     = y;

                         // increment the number of objects

                         (*num_objects)++;

                         } // end if an object was found

                      } // end if in boundaries

                   } // end for x

               } // end for y

           // return number of objects found

           return(*num_objects);

           } break;

      case SOUTH:
           {
           // scan like this
           //  P
           // ...
           //.....

           for (y=you.y,scan_level=0; y<=(you.y+depth); y++,scan_level++)
               {
               for (x=you.x-scan_level; x<=you.x+scan_level; x++)
                   {
                   // x,y is test point, make sure it is within the universe
                   // boundaries

                   if (x>=1 && x<NUM_COLUMNS-1 &&
                       y>=1 && x<NUM_ROWS-1 &&
                       universe_geometry[y][x]==universe_geometry[you.y][you.x])
                      {
                      // test to see if square has an object in it

                      if (universe_objects[y][x]!=' ')
                         {
                         // insert the object into object list

                         stuff[*num_objects].thing = universe_objects[y][x];
                         stuff[*num_objects].x     = x;
                         stuff[*num_objects].y     = y;

                         // increment the number of objects

                         (*num_objects)++;

                         } // end if an object was found

                      } // end if in boundaries

                   } // end for x

               } // end for y

           // return number of objects found

           return(*num_objects);

           } break;


      case EAST:
           {
           // scan like this
           //   .
           //  ..
           // P..
           //  ..
           //   .

           for (x=you.x,scan_level=0; x<=(you.x+depth); x++,scan_level++)
               {
               for (y=you.y-scan_level; y<=you.y+scan_level; y++)
                   {
                   // x,y is test point, make sure it is within the universe
                   // boundaries

                   if (x>=1 && x<NUM_COLUMNS-1 &&
                       y>=1 && x<NUM_ROWS-1 &&
                       universe_geometry[y][x]==universe_geometry[you.y][you.x])
                      {
                      // test to see if square has an object in it

                      if (universe_objects[y][x]!=' ')
                         {
                         // insert the object into object list

                         stuff[*num_objects].thing = universe_objects[y][x];
                         stuff[*num_objects].x     = x;
                         stuff[*num_objects].y     = y;

                         // increment the number of objects

                         (*num_objects)++;

                         } // end if an object was found

                      } // end if in boundaries

                   } // end for y

               } // end for x

           // return number of objects found

           return(*num_objects);

           } break;

      case WEST:
           {
           // scan like this
           // .
           // ..
           // ..P
           // ..
           // .
           //

           for (x=you.x,scan_level=0; x>=(you.x-depth); x--,scan_level++)
               {
               for (y=you.y-scan_level; y<=you.y+scan_level; y++)
                   {
                   // x,y is test point, make sure it is within the universe
                   // boundaries

                   if (x>=1 && x<NUM_COLUMNS-1 &&
                       y>=1 && x<NUM_ROWS-1 &&
                       universe_geometry[y][x]==universe_geometry[you.y][you.x])
                      {
                      // test to see if square has an object in it

                      if (universe_objects[y][x]!=' ')
                         {
                         // insert the object into object list

                         stuff[*num_objects].thing = universe_objects[y][x];
                         stuff[*num_objects].x     = x;
                         stuff[*num_objects].y     = y;

                         // increment the number of objects

                         (*num_objects)++;

                         } // end if an object was found

                      } // end if in boundaries

                   } // end for y

               } // end for x

           // return number of objects found

           return(*num_objects);

           } break;

      } // end switch direction

return(0);

} // end Vision_System

////////////////////////////////////////////////////////////////////////////////

int Check_For_Phrase(int phrase,int index)
{
// this function is used to test for small phrases that when extracted don't
// change the measning of a sentence for example:"look to the west" and
// "loo west" and "look to west" all mean the same thing.

// test which phrase is to be checked

switch(phrase)
      {
      case PHRASE_TO: // have we found the prep. "to"
           {

           if (sentence[index]==PREP_TO)
              return(1);

           } break;

      case PHRASE_THE: // have we found the article "the"
           {

           if (sentence[index]==ART_THE)
              return(1);

           } break;


     case PHRASE_DOWN: // have we found the prep/adj "down"
          {

          if (sentence[index]==PREP_DOWN)
             return(1);

          } break;

      case PHRASE_TO_THE: // have we found the prep. phrase "to the"
           {

           if (sentence[index]==PREP_TO)
              {
              if (sentence[index+1]==ART_THE)
                  return(1);
              else
                  return(0);
              } // end if got "to the"
           } break;

      case PHRASE_DOWN_THE: // have we found the prep. phrase "down the"
           {

           if (sentence[index]==PREP_DOWN)
              {
              if (sentence[index+1]==ART_THE)
                  return(1);
              else
                  return(0);
              } // end if got "down the"
           } break;


      default:break; // there is a serious problem!

      } // end switch

// we have failed

return(0);

} // end Check_For_Phrase

///////////////////////////////////////////////////////////////////////////////

void Print_Info_Strings(info_string strings[],char where)
{
// this function will print the info strings out of the sent array based
// on the the current location of the player i.e. bedroom, kitchen etc.

int index=0;

printf("\n");

// traverse list and print all string relating to this room

while(strings[index].type!='X')
     {

     // should this string be printed

     if (strings[index].type==where)
        {

        printf("\n%s",strings[index].string);

        } // end if this is a relevant string

     // next string

     index++;

     } // end while

printf("\n");

} // end Print_Info_Strings

///////////////////////////////////////////////////////////////////////////////

void Introduction(void)
{

int index;

for (index=0; index<50; index++,printf("\n"));

// make the screen blue with white characters
// only works with ansi driver

printf("%c%c37;44m",27,91);

printf("\n     SSSSSSSSSS  H      H  AAAAAAAA  DDDDD     OOOOOOOO  W       W");
printf("\n     S           H      H  A      A  D    D    O      O  W       W");
printf("\n     S           H      H  A      A  D     D   O      O  W       W");
printf("\n     S           H      H  A      A  D      D  O      O  W       W");
printf("\n     S           H      H  A      A  D      D  O      O  W       W");
printf("\n     SSSSSSSSSS  HHHHHHHH  AAAAAAAA  D      D  O      O  W       W");
printf("\n              S  H      H  A      A  D      D  O      O  W       W");
printf("\n              S  H      H  A      A  D      D  O      O  W   W   W");
printf("\n              S  H      H  A      A  D      D  O      O  W   W   W");
printf("\n              S  H      H  A      A  D     D   O      O  W   W   W");
printf("\n              S  H      H  A      A  D    D    O      O  W   W   W");
printf("\n     SSSSSSSSSS  H      H  A      A  DDDDD     OOOOOOOO  WWWWWWWWW");
printf("\n                                                                  ");
printf("\n     L         AAAAAAA  NNNNNNN  DDDDDD                           ");
printf("\n     L         A     A  N     N  D     D                          ");
printf("\n     L         A     A  N     N  D      D                         ");
printf("\n     L         A     A  N     N  D      D                         ");
printf("\n     L         AAAAAAA  N     N  D      D                         ");
printf("\n     L         A     A  N     N  D      D                         ");
printf("\n     L         A     A  N     N  D     D                          ");
printf("\n     L         A     A  N     N  D    D                           ");
printf("\n     LLLLLLL   A     A  N     N  DDDDD                            ");
printf("\n                                                                  ");
printf("\n     By Andre' LaMothe                                            ");


while(!kbhit());

for (index=0; index<50; index++,printf("\n"));

} // end Introduction

// M A I N /////////////////////////////////////////////////////////////////////

void main(void)
{

// call up intro

Introduction();

printf("\n\nWelcome to the world of  S H A D O W  L A N D...\n\n\n");

// obtain users name to make game more personal

printf("\nWhat is your first name?");
scanf("%s",you.name);

// main event loop,note: it is NOT real-time

while(!global_exit)
     {
     // put up an input notice to user

     printf("\n\nWhat do you want to do?");

     // get the line of text

     Get_Line(global_input);

     printf("\n");

     // break the text down into tokens and build up a sentence

     Extract_Tokens(global_input);

     // parse the verb and execute the command

     Verb_Parser();

     } // end main event loop

printf("\n\nExiting the universe of S H A D O W  L A N D...see you later %s.\n",you.name);

// restore screen color

printf("%c%c37;40m",27,91);

} // end main


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -