home *** CD-ROM | disk | FTP | other *** search
/ Shareware 1 2 the Maxx / sw_1.zip / sw_1 / PROGRAM / CPTUTS22.ZIP / MAP.CPP < prev    next >
C/C++ Source or Header  |  1992-01-20  |  8KB  |  280 lines

  1. #include <iostream.h>
  2. #include "conio.h"
  3. #include "map.h"
  4. #include "message.txt"
  5. #include "words.h"
  6. #include "items.h"
  7. #include "schedule.h"
  8.  
  9. location your_car;
  10. location pass_drop_off;
  11. location lobby;
  12. location baggage_claim;
  13. location dark_room;
  14. location ticket_counter;
  15. location tunnel;
  16. location rest_room;
  17. location snack_bar;
  18. location security;
  19. location waiting_area;
  20. location gate1;
  21. location gate2;
  22. location gate3;
  23. location gate4;
  24. location plane1;
  25. location plane2;
  26. location plane3;
  27. location plane4;
  28.  
  29. extern schedule flight_info;
  30. extern items personal_items;
  31. extern words input_words;
  32.  
  33.  
  34. void map::initialize(void)
  35. {
  36.    cout << startup_message;
  37.  
  38.    present_location = &your_car;
  39.  
  40.    your_car.init(&pass_drop_off, // North from here
  41.               NULL,              // East from here
  42.               NULL,              // South from here
  43.               NULL,              // West from here
  44.               your_car_message,  // message when entering here
  45.               y_c_look_message); // message for look command
  46.  
  47.    pass_drop_off.init(&lobby,
  48.               NULL,
  49.               NULL,    // You cannot go back to the car, it leaves
  50.               NULL,
  51.               pass_drop_off_message,
  52.               p_d_o_look_message);
  53.  
  54.    lobby.init(&ticket_counter,
  55.               NULL,
  56.               &pass_drop_off,
  57.               &baggage_claim,
  58.               lobby_message,
  59.               l_look_message);
  60.  
  61.    baggage_claim.init(NULL,
  62.               &lobby,
  63.               NULL,
  64.               &dark_room,
  65.               baggage_claim_message,
  66.               b_c_look_message);
  67.  
  68.    dark_room.init(NULL,
  69.               NULL,
  70.               NULL,
  71.               NULL,
  72.               dark_room_message,
  73.               d_r_look_message);
  74.  
  75.    ticket_counter.init(&tunnel,
  76.               NULL,
  77.               &lobby,
  78.               NULL,
  79.               ticket_counter_message,
  80.               t_c_look_message);
  81.  
  82.    tunnel.init(&security,
  83.               &snack_bar,
  84.               &ticket_counter,
  85.               &rest_room,
  86.               tunnel_message,
  87.               t_look_message);
  88.  
  89.    rest_room.init(NULL,
  90.               &tunnel,
  91.               NULL,
  92.               NULL,
  93.               rest_room_message,
  94.               r_r_look_message);
  95.  
  96.    snack_bar.init(NULL,
  97.               NULL,
  98.               NULL,
  99.               &tunnel,
  100.               snack_bar_message,
  101.               s_b_look_message);
  102.  
  103.    security.init(&waiting_area,
  104.               NULL,
  105.               &tunnel,
  106.               NULL,
  107.               security_message,
  108.               s_look_message);
  109.  
  110.    waiting_area.init(NULL,
  111.               &gate3,
  112.               &security,
  113.               &gate2,
  114.               waiting_area_message,
  115.               w_a_look_message);
  116.  
  117.    gate1.init(&plane1,
  118.               &gate2,
  119.               NULL,
  120.               NULL,
  121.               gate1_message,
  122.               g1_look_message);
  123.  
  124.    plane1.init(NULL,
  125.               NULL,
  126.               NULL,
  127.               NULL,
  128.               plane_message,
  129.               plane_look_message);
  130.  
  131.    gate2.init(&plane2,
  132.               &waiting_area,
  133.               NULL,
  134.               &gate1,
  135.               gate2_message,
  136.               g2_look_message);
  137.  
  138.    plane2.init(NULL,
  139.               NULL,
  140.               NULL,
  141.               NULL,
  142.               plane_message,
  143.               plane_look_message);
  144.  
  145.    gate3.init(&plane3,
  146.               &gate4,
  147.               NULL,
  148.               &waiting_area,
  149.               gate3_message,
  150.               g3_look_message);
  151.  
  152.    plane3.init(NULL,
  153.               NULL,
  154.               NULL,
  155.               NULL,
  156.               plane_message,
  157.               plane_look_message);
  158.  
  159.    gate4.init(&plane4,
  160.               NULL,
  161.               NULL,
  162.               &gate3,
  163.               gate4_message,
  164.               g4_look_message);
  165.  
  166.    plane4.init(NULL,
  167.               NULL,
  168.               NULL,
  169.               NULL,
  170.               plane_message,
  171.               plane_look_message);
  172.  
  173.    personal_items.add_item(keys);     // Player gets keys
  174.    personal_items.add_item(money);    // Player gets money
  175.  
  176.    your_car.add_item(ticket);         // Ticket is in car
  177.    snack_bar.add_item(candy);         // Candy is in snack bar
  178. }
  179.  
  180.  
  181.  
  182.  
  183. void map::perform_action(void)
  184. {
  185.    if (input_words.is_a_direction()) {      // Move to a new location
  186.       result = present_location->move(input_words.get_verb());
  187.       if (result) {                  // If Non-NULL
  188.          present_location = result;  // Valid move found
  189.          present_location->display_message();
  190.       }
  191.  
  192.                                  // Force end of game if in dark room
  193.       if (present_location == &dark_room) {
  194.          input_words.stop_game();  // Set the verb to "quit"
  195.          cout << "Hit any key to end the game.";
  196.          getch();
  197.       }
  198.    }
  199.                                                          // Inventory
  200.    else if (input_words.get_verb() == inventory)
  201.       personal_items.list_items();
  202.  
  203.                                                               // Look
  204.    else if (input_words.get_verb() == look)
  205.       present_location->display_list_of_items();
  206.  
  207.                                                          // Drop item
  208.    else if (input_words.get_verb() == drop) {
  209.       if (personal_items.item_here(input_words.get_noun())) {
  210.          personal_items.drop_item(input_words.get_noun());
  211.          present_location->add_item(input_words.get_noun());
  212.          cout << " Dropped.\n";
  213.       } else {
  214.          cout << "You can't drop what you don't have.\n";
  215.       }
  216.    }
  217.  
  218.                                                           // Get item
  219.    else if (input_words.get_verb() == get) {
  220.       if (present_location->item_here(input_words.get_noun())) {
  221.          present_location->drop_item(input_words.get_noun());
  222.          personal_items.add_item(input_words.get_noun());
  223.          cout << " Picked up.\n";
  224.       } else {
  225.          cout << "It isn't here so you can't pick it up.\n";
  226.       }
  227.    }
  228.  
  229.                                                          // Buy candy
  230.    else if ((input_words.get_verb() == buy) &&
  231.                   (input_words.get_noun() == candy) &&
  232.                            (present_location == &snack_bar)) {
  233.       if ((personal_items.item_here(money)) &&
  234.                            (present_location->item_here(candy))) {
  235.          personal_items.drop_item(money);
  236.          personal_items.add_item(candy);
  237.          present_location->drop_item(candy);
  238.          present_location->add_item(money);
  239.          cout << " You now have candy.\n";
  240.       } else
  241.          cout << "Surely you are not serious about that!\n";
  242.    }
  243.  
  244.                                                        // Read ticket
  245.    else if ((input_words.get_verb() == read) &&
  246.                              (input_words.get_noun() == ticket))
  247.       if (personal_items.item_here(ticket))
  248.          flight_info.list_actual_destination();
  249.       else
  250.          cout << "You don't have a ticket to read.\n";
  251.  
  252.                                                       // Read monitor
  253.    else if ((input_words.get_verb() == read) &&
  254.                      (input_words.get_noun() == monitor) &&
  255.                             (present_location == &ticket_counter))
  256.       flight_info.list_flights(present_location);
  257.  
  258.                                                       // Read monitor
  259.    else if ((input_words.get_verb() == read) &&
  260.                    (input_words.get_noun() == monitor) &&
  261.                               (present_location == &waiting_area))
  262.       flight_info.list_flights(present_location);
  263.  
  264.                                                         // Read paper
  265.    else if ((input_words.get_verb() == read) &&
  266.                    (input_words.get_noun() == paper) &&
  267.                                      (present_location == &lobby))
  268.       cout << paper_message;
  269.                                                               // Help
  270.    else if (input_words.get_verb() == help)
  271.       cout << help_message;
  272.                                                               // Quit
  273.    else if (input_words.get_verb() == quit)      // Ignore to prevent
  274.       ;                                          //  message output
  275.  
  276.    else
  277.       cout << "I don't understand what you want.\n";
  278.  
  279. }
  280.