Thread: how do a make a room in a text game

  1. #1
    Registered User Joe100's Avatar
    Join Date
    Jul 2003
    Posts
    63

    how do a make a room in a text game

    hey all can u tell me a how to create rooms in text adventures?

  2. #2
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    code it in.
    Away.

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    249
    code it in.
    HA!
    Well, there are a few things wrong with your code:

    1) It does not work.
    2) It does not work.
    3) It does not work.

    Hope this helps.

  4. #4
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    consider using a 2D array of chars to store the 'object' at each location. if you have trouble with that, post a specific problem along with the code you've written

  5. #5
    plzduntlakliekthiskthx
    Join Date
    Oct 2002
    Posts
    138

    Re: how do a make a room in a text game

    Originally posted by Joe100
    hey all can u tell me a how to create rooms in text adventures?
    By text adventure do you mean ASCII graphics, or do you mean the kind of game where it is "You walk forward, you walk left, etc..."?

  6. #6
    Registered User Joe100's Avatar
    Join Date
    Jul 2003
    Posts
    63
    YA THE LAST ONE IS WHAT I MEAN :P lol

  7. #7
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    you could use stl map

  8. #8
    plzduntlakliekthiskthx
    Join Date
    Oct 2002
    Posts
    138
    Yeah, a 2d array would be easy for a room. When your character moves just see whats at the spot in your room where the character x,y pos is. Assuming your room starts at the top left of the console window, and you are your room to be 30 "spaces" x 30 "spaces" you would do....
    Code:
    char  room[30][30];
    Then, when they user presses up you would do something like....
    Code:
    switch(input){
    case Up:
         y--;
    break;  //you should get the idea for the rest of the cases...
    You could then have a function that checks to see if anything is at the spot where the character is. Have statements like this in the function...
    Code:
    if(room[y][x]=='D')
    {
         cout<<"You are at a door";
    }
    edit: Messed up the room array... thanks Perspective
    Last edited by o0obruceleeo0o; 08-05-2003 at 10:25 PM.

  9. #9
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    >> char room[29][29];

    erm, to make a 30 x 30 grid you would need to declare it like...

    char map[30][30];

    and index it from 0 to 29

  10. #10
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    When checking what is at a certain element in your room-array, make sure you're not looking outside the bounds (like when you stand at the top of the room and press UP). A simple check in the beginning makes sure this won't happen, in this case I assume that is is a wall outside the array (to prevent the player from walking there).
    Code:
    char GetBlock(int X, int Y)
    {
       //Assume walls if outside the array
       if(X < 0) return 'W';
       if(X >= 30) return 'W';
       if(Y < 0) return 'W';
       if(Y >= 30) return 'W';
    
       //Return what is in the array
       return Map[X][Y];
    }
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  11. #11
    Registered User
    Join Date
    Mar 2002
    Posts
    249
    If you want just want it to be like "you moved left" then that should be fairly simple to do. If you want to have graphics - like '|' represents a wall, then it gets a little more complicated only because you have to draw it all out...So if I were you I would stick with first approach, and then when your're done you can go and add text graphics to it.
    Well, there are a few things wrong with your code:

    1) It does not work.
    2) It does not work.
    3) It does not work.

    Hope this helps.

  12. #12
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942
    IMO, the best way to do this is create a text game editor and make the game that way, but that may be above your current ability

  13. #13
    You might want to check out the Text Advnetur tutorial located at GameTutorials.com, it is very simple to understand.

    link: Text Adventure Tuts

  14. #14
    Registered User MicroFiend's Avatar
    Join Date
    Nov 2002
    Posts
    80
    off the topic but.. perspective u should have the wc3 tft illidan as your avatar he looks so much better.. but how the f**k does artharas kill him.. i dont c how

  15. #15
    Registered User Joe100's Avatar
    Join Date
    Jul 2003
    Posts
    63
    ok then umm.....yea what ever you say man
    "Be Quick Or Be Dead"

    [img]
    http://www.danasoft.com/sig/GU.jpg
    [/img]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Please help (Text Adventure Game)
    By C++angel in forum C++ Programming
    Replies: 9
    Last Post: 02-23-2006, 04:33 PM
  2. Game Engine Link Prob
    By swgh in forum Game Programming
    Replies: 2
    Last Post: 01-26-2006, 12:14 AM
  3. Text based game..
    By MipZhaP in forum C++ Programming
    Replies: 8
    Last Post: 02-28-2005, 08:35 AM
  4. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 04:49 PM
  5. Text Game Question
    By Unregistered in forum Game Programming
    Replies: 4
    Last Post: 03-08-2002, 04:55 AM