Thread: Linking the rooms, problem?

  1. #1
    Registered User
    Join Date
    Mar 2010
    Location
    Salem's Lot
    Posts
    19

    Linking the rooms, problem?

    Code:
    #include <iostream>
    using namespace std;
    int main ()
    {
    
    cout<< "You can enter the house to the East or go down the road to the south.\n\n" << "Choose your path.\n\n";
    int patha;
    cout<< "1.South\n2. West\n";
    cin>> patha;
    
    switch (patha)
    {
    case 1:
    cout<< "As you enter the house you notice a distinct smell... It almost makes you vomit.  The smell of, flesh.\n";
    break;
    
    case 2:
    cout<< "You move down the road towards the center of the city... You wonder where this street will lead you.\n";
    break;
    
    default:
    cout<< "Please pick again...\n";
    }
    
    system ("PAUSE");
    }
    How do I let the user move back to the original location? I'm thinking of... Linking the rooms would be something better to ask?

    Thanks,

    -SP

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Unless you're thinking of teleporting, the player should turn around and walk back. This means nothing more than if, for example, Player went south and east, one goes west and north to get back.

  3. #3
    Registered User
    Join Date
    Mar 2010
    Location
    Salem's Lot
    Posts
    19
    So, there's a lot of coding going on I assume?

    Shouldn't there be a way where if they move east they can go back west but they can see

    Code:
    cout<< "You can enter the house to the East or go down the road to the south.\n\n" << "Choose your path.\n\n";
    int patha;
    cout<< "1.South\n2. West\n";
    cin>> patha;
    without me typing it all out again? When they say go west it takes them to this function?

    Do you know what I'm saying or am I rambling? Lol.

    -SP

  4. #4
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    I get what you mean.

    You're thinking too hard. Let the player control his character. Like I previously explained, a character can "go back" easily by following his steps in reverse, in the opposite direction. No matter what the player chooses to do, you need two things: a description for wherever Player can go, and a marker for where Player is, so you know which descriptions to use.

    So figuring this out really depends on which directions the Player can follow on the map and how you want to handle it. Most maps are two dimensional (unless you fly to the Floating Continent).

    A really simple solution, that I just thought of, is a matrix (two-dee array) of "rooms," and an index for player. Moving the player should be reflected on the matrix: maybe a step west is

    map[pos-1]

    among other things. But the other aspects of the map, like encounters and dropped items, are probably coupled with this greater matrix and require some thinking. It would be very boring if say, items were always in the same place.

    Keep thinking, and uh, take a break from coding. You should actually draw the map so you don't confuse yourself.
    Last edited by whiteflags; 03-26-2010 at 12:21 AM. Reason: link!

  5. #5
    Registered User
    Join Date
    Mar 2010
    Location
    Salem's Lot
    Posts
    19
    Yeah. I probably should just take a break for tonight. Been studying for hours now. Lol.

    I'll make a small map tomorrow and get started after.

    Thanks,

    -SP

  6. #6
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Either use a 2D array or you can use nodes. 2D array is the easiest. Each 'cell' in the array can either be a room (not recommended) or it can be a room ID. The room ID then indexes into a global list of rooms available in the game. This allows you to use a room more than once yet only have 1 copy of it in memory. Directions to/from the rooms can be determined by searching the 8 map cells around the player's location and checking to see if the map cell is a valid room ID or if the cell is in the bounds of the array.

    Nodes can be done as well and you can either use pointers to other rooms or you can maintain a vector or list of room IDs that attach to a room.

    virtual bool AttachRoom(unsigned int direction,unsigned int roomID)

    or

    virtual bool AttachRoom(unsigned int direction,Room *pRoom);

    Any one of those approaches will work.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with linking .LIB
    By lapo in forum C Programming
    Replies: 2
    Last Post: 10-31-2007, 03:41 AM
  2. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM
  3. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM
  4. Long file linking problem
    By hypertension in forum C Programming
    Replies: 3
    Last Post: 10-15-2002, 09:55 PM
  5. Linking problem...
    By BrianK in forum C++ Programming
    Replies: 2
    Last Post: 10-08-2002, 04:13 PM