Archived

This topic is now archived and is closed to further replies.

SSJGaz

C++ Loop Help

Recommended Posts

I started learning C++ 3 days ago. I am making an MS DOS Console Text Based Advenure game but im having difficultys performing a loop. The problem is - You walk North into a room and the only way out, is to go south, that will take you back to the place you started. I want it so that when - if(tolower(dir[0])==''s'') it will loop me back to were i started. i hope u can understand, not had much leep in last 48hrs, been working on this. any help would be great thx

Share this post


Link to post
Share on other sites
You really need to give more information before anyone will be able to help you. How are the rooms represented? How is the position represented?

Maybe you could post more code...

Share this post


Link to post
Share on other sites
{


if(tolower(dir[0])==''n'')

cout << endl

<<"You are now in a room with a desk and seats. The room is empty. There is a";

if(tolower(dir[0])==''n'')

cout << endl

<<"Sign marked Reception. To the North is a strange door. To the East are toilets";

if(tolower(dir[0])==''n'')

cout << endl

<<"To the South is the room where you started and West is to some Offices";

cout << endl

<<"Which Way? (North, East, South or West)";
cin >> &dir[0]
;}

----------------------------------------------------------------
then the user keys in South
----------------------------------------------------------------
{
if(tolower(dir[0])==''s'')

cout << endl

(COMMAND HERE)
}
----------------------------------------------------------------
i want a loop command were it says that will take me back to the top part pf the code posted here

Share this post


Link to post
Share on other sites
I don't understand exactly what you want but I think I have an idea. You want the user to change rooms right? if so what you need to do is have a variable like...

int current_room=1;

now have the main loop of the game like this:

while(!done)
{
if(current_room==1)
{
//do stuff in room one

}
if(current_room==2)
{
//do stuff in room two

}
}


Is that what you mean? I hope it helps...




The monkeys are listening...

[edited by - FtMonkey on July 5, 2003 10:56:50 PM]

Share this post


Link to post
Share on other sites
its a very basic game, being that it is my first i dont know much. The rooms are not named. the way it works is the user reads the text and is given for options. To go North, East, South or West. The way it works is that the user keys in were they want to go.

Say the user wants to go North. they type North and the first letter ( N ) is stored in the variable named "dir". the next like of code is an IF. the if checks to see what the user has typed in. If the user has typed in North, then the IF will notice that the letter stored in variable "dir" is an N and it will then perform the command i have keyed in, which is text, telling the user what is in the room, and were they can go next. Thats how it works.

But what happens if a user goes into a room, that has only one way out? He/She will have to go back into the other room. Now i dont want to have to type out the same code 4 times, i just want it so that when the user leaves the room it will go back to the begining of the code of the room they were just in.

Share this post


Link to post
Share on other sites
I would suggest you learn some more of the language, then come back to your game and re-think the design. Programming a ton of if(...)s is bad style. I undertand that you''re just starting out, but thats all the more reason to learn (and fully comprehend) your basics first.

Ravyne, NYN Interactive Entertainment
HTTP://nyn.studio42games.com

Share this post


Link to post
Share on other sites
quote:
Original post by Ravyne
I would suggest you learn some more of the language, then come back to your game and re-think the design. Programming a ton of if(...)s is bad style. I undertand that you're just starting out, but thats all the more reason to learn (and fully comprehend) your basics first.

Ravyne, NYN Interactive Entertainment
HTTP://nyn.studio42games.com


I agree, try learning more about the language first and then come back to the game. Try to make simple programs first so you get a better understanding of the language (like a number guessing game, or a calculator program). Here are some links that might help you:

click here
and here






The monkeys are listening...

[edited by - FtMonkey on July 5, 2003 11:30:34 PM]

Share this post


Link to post
Share on other sites