Archived

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

HTML

Text Adventure Help

Recommended Posts

I didn''t name the problem in the topic because I''ll just use this for all the problems. I have the commands: n for north, e, s, and w. So I typed: else if(strInput == "n" || strInput == "north") { Move(fin, room, room.strRoomNorth); } What I want to do is make it so they work on CAPS LOCK and no caps without having to do an strInput == for N n North NORTH north ect... How would I do this? Second, I want to add color to my text game. I am not sure how to do this part because I didn''t see it in my C book (getting a C++ book soon) I am still trying to learn C++ from www.cplusplus.com at the tutorals section, but it got difficult to understand, so I thought if I tried learning for a text adventure , then reviewing the code over and over from the tutorials, it might help more. Then when I got comfortable with it , then do more of the cplusplus and other tutorials. I am on the part with the operators, but I understand a little more than that.. btw, anyone have any suggestions to learn c++ a little easier? I think doing game tutorials and reviewing the keywords they used from the c++ tutorial seems to help me learn it a little more....but it probably has disadvantages too..

Share this post


Link to post
Share on other sites
use the strupr command for converting the string to uppercase before you check.

char Word[20] = "blah blah blah";
strupr(Word);

then the string should be "BLAH BLAH BLAH", then check for the uppercase version of it.

There''s also strlwr, if you want to do everything lowercase

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by HTML
So the strupr command will let me do both, lower and upper case or just upper?


After you use strupr on the input string, the input string will be upper case, regardless of the case the user typed in. Then you only need to test it against "N" and "NORTH".

Conversely, if you used strlwr, you would only need to test against "n" and "north" because the input string is changed to lower case.

Share this post


Link to post
Share on other sites
Is that all? Because I did that and got errors...I'll check the cplusplus tutorial on char and strings to see what else I should put and where.

[edited by - HTML on October 11, 2003 6:04:12 PM]

Share this post


Link to post
Share on other sites
char North [20];
strlwr(north);

I know I did it wrong but I am not sure how I am supposed to do it.

Is North the right word to put in?
where do I put my strInput? After strlwr?

Here is what I had before:
else if(strInput == "n" || strInput == "north")

{
Move(fin, room, room.strRoomNorth);
}

I am still learning C++ so I am not exactly sure what to do. I tried a bunch of different things but still can''t figure out why it won''t work. I even tried looking at the tutorial part with char. I understand most of that part it but I am not sure what to do with it. (ie: 20 for 20 letters, char =data type, then I input my variables, but it isn''t working...

thanks, and sorry I am very new to c++

Share this post


Link to post
Share on other sites
if strInput is a char array (char*), you cannot compare it using the "==" operator; this would compare the memory addresses of the two strings, which will NEVER match.

either use std::string (which behaves the way you would expect it to), or compare the char arrays with "strcmp()"...

Share this post


Link to post
Share on other sites
^bump^

K, i''ll try that, but I am still not sure where to input the code for all this and where to put north and str.RoomNorth

Share this post


Link to post
Share on other sites
Make an input function that checks for the input. THat should make everything easy. Whenever you need input just call the function.

Scott Simontis
e-mail:ageofscott@comcast.net
AIM:ssimontis

Share this post


Link to post
Share on other sites
quote:
Original post by sSimontis
Make an input function that checks for the input. THat should make everything easy. Whenever you need input just call the function.

Scott Simontis
e-mail:ageofscott@comcast.net
AIM:ssimontis


Good idea, I will try that, execpt I am not quite sure how to do that.

Share this post


Link to post
Share on other sites