C++ Loop Help

Started by
7 comments, last by SSJGaz 20 years, 9 months ago
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
[SSJGaz][Newbie C++ Programmer]
Advertisement
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...
{


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

[SSJGaz][Newbie C++ Programmer]
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]
The monkeys are listening...
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.

[SSJGaz][Newbie C++ Programmer]
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

throw table_exception("(? ???)? ? ???");

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]
The monkeys are listening...
ok thx
[SSJGaz][Newbie C++ Programmer]
Commenty your code, then e-mail me it and I will help.

Scott Simontis
C++ Guy
Scott SimontisMy political blog

This topic is closed to new replies.

Advertisement