home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / CPTUTOR2.ZIP / LOCATION.CPP < prev    next >
C/C++ Source or Header  |  1990-07-20  |  4KB  |  137 lines

  1. #include "location.hpp"
  2. #include "iostream.h"
  3. #include "items.hpp"
  4. #include "schedule.hpp"
  5.  
  6. extern location snack_bar;     // Special action in "move"
  7. extern location security;      // Special action in "move"
  8. extern items personal_items;   // Reference to players items
  9. extern schedule flight_info;
  10.  
  11.  
  12.  
  13. void location::init(location *valid_north,
  14.             location *valid_east,
  15.             location *valid_south,
  16.             location *valid_west,
  17.             char *local_message,
  18.             char *local_look_message)
  19. {
  20.    north_move = valid_north;
  21.    east_move = valid_east;
  22.    south_move = valid_south;
  23.    west_move = valid_west;
  24.    message = local_message;
  25.    look_message = local_look_message;
  26. }
  27.  
  28.  
  29.  
  30.  
  31. location
  32. *location::move(word direction)
  33. {
  34. int no_go = FALSE;
  35.  
  36.                                       // Getting out of the snack bar
  37.    if ((this == &snack_bar) && (personal_items.item_here(money)) &&
  38.                                     (personal_items.item_here(candy)))
  39.       cout << 
  40.       "You took a candy bar and didn't pay for it.  Airport security\n"
  41.       "grabs you and after much verbal abuse agrees to let you go if\n"
  42.       "you will either return the candy bar or pay for it.\n";
  43.  
  44.                                            // Getting through security
  45.    else if ((this == &security) && (direction == north) &&
  46.                                   ((personal_items.item_here(keys)) ||
  47.                                    (personal_items.item_here(money))))
  48.       cout <<
  49.       "You cannot get through security because the beeper detects\n"
  50.       "some metallic object on you.  Many people are staring at\n"
  51.       "you and thinking that you look dangerous.\n";
  52.  
  53.                                            // A normal move somewhere
  54.    else
  55.    switch (direction) {
  56.       case north : if (north_move) 
  57.                       return (north_move); // Location to north
  58.                    else
  59.                       no_go = TRUE;        // You can't go that way!
  60.                    break;
  61.       case east  : if (east_move) 
  62.                       return (east_move);  // Location to east
  63.                    else
  64.                       no_go = TRUE;        // You can't go that way!
  65.                    break;
  66.       case south : if (south_move) 
  67.                       return (south_move); // Location to south
  68.                    else
  69.                       no_go = TRUE;        // You can't go that way!
  70.                    break;
  71.       case west  : if (west_move) 
  72.                       return (west_move);  // Location to west
  73.                    else
  74.                       no_go = TRUE;        // You can't go that way!
  75.                    break;
  76.       default    : cout << "This is not a move.\n";
  77.                    return(NULL);
  78.    }
  79.    if (no_go) cout << "Sorry, you cannot go that way!\n";
  80.    return (NULL);
  81. }
  82.  
  83.  
  84.  
  85.  
  86.         // This adds an item to the items object in this room
  87. void
  88. location::add_item(word item_to_add)
  89. {
  90.    list_of_items.add_item(item_to_add);
  91. }
  92.  
  93.  
  94.  
  95.  
  96.         // This drops an item from the list in this room
  97. void
  98. location::drop_item(word item_to_drop)
  99. {
  100.    list_of_items.drop_item(item_to_drop);
  101. }
  102.  
  103.  
  104.  
  105.  
  106.          // This returns TRUE if the item is located here
  107. char
  108. location::item_here(word item_to_check)
  109. {
  110.    return (list_of_items.item_here(item_to_check));
  111. }
  112.  
  113.  
  114.  
  115.  
  116.         // This displays the message when the room is entered
  117.         // It also displays the flight information at a gate
  118. void
  119. location::display_message()
  120. {
  121.    cout << message;
  122. }
  123.  
  124.  
  125.  
  126.  
  127.         // This displays the items located in this room
  128. void
  129. location::display_list_of_items(void)
  130. {
  131.    cout << look_message;
  132.    list_of_items.list_items_in_room();
  133.    flight_info.gate_message(this);   // List the flight information
  134.                                      //  if you are at a gate
  135. }
  136.  
  137.