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

1. ## 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. code it in.

3. code it in.
HA!

4. 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. ## 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. YA THE LAST ONE IS WHAT I MEAN :P lol

7. you could use stl map

8. 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

9. >> 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. 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];
}```

11. 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.

12. 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. 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. 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. ok then umm.....yea what ever you say man

Popular pages Recent additions