Thread: Text Adventure

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    2

    Text Adventure

    I'm new to C++ and object oriented programming. I've done some really basic stuff, but I wanted to try something a little more advanced. I'm trying to put together a text adventure game. Something that would start out simple, but I could improve over time if I wanted to.

    I have the basic idea down for the game, but I'm having trouble figuring out how to structure the different rooms.

    I want the rooms set up so they each have values places on 4 directional values

    int moveN;
    int moveS;
    int moveE;
    in moveW;

    The values of each would give the number of the room you'd go to if you typed N,S,E, or W.

    Then I want a class type to define the different attributes of each room. Then I want a currentroom function to preform tasks based on the values of the room the player is currently in.

    I have the class sort of set up, but I don't know how I should store the data for each room or how I would retrieve it.

    To me this doesn't seem like it should be extremely difficult, but I haven't been able to figure it out, and if any documentation explains how to do it, this little ArtGeek hasn't been able to get it through her thick skull.

    Sorry for longwindedness

  2. #2
    Well, the common way is to store it in a file but there are more methods than time to recount them. Have a look on my site here for an example of one of the 1000's of ways.
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

  3. #3
    Comment your source code! Lynux-Penguin's Avatar
    Join Date
    Apr 2002
    Posts
    533
    perhaps you would want characters then initialize the integers like...

    (btw: C++ is not completely object oriented, and in my opinion, not at all)
    Code:
    char ans;
    printf("Where do you want to move? [N/E/S/W]: ");
    scanf("%c",&ans);
    switch(ans)
    {
    	case 'n'
    		N:
    		//code for north here
    		break;
    	case 'N'
    		goto N;
    		break;
    	case 'e'
    		E:
    		//code for east here
    		break;
    	case 'E'
    		goto E;
    		break;
    	//...  continuing switch case
    	default
    		return 0;
    }
    
    //etc...
    Asking the right question is sometimes more important than knowing the answer.
    Please read the FAQ
    C Reference Card (A MUST!)
    Pointers and Memory
    The Essentials
    CString lib

  4. #4
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    Just so you know you can make it

    case 'n':
    case 'N':
    //code
    break;

    case 'e':
    case 'E':
    //code
    break;

    So you wont have to do double switch statements

  5. #5
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    ...or use toupper(ans);/tolower(ans)l; n ctype.h (or your compiler specific) to use a single case either uppercase or lowercase in your switch statements.

    -

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Text adventure engine idea. thoughts?
    By suzakugaiden in forum Game Programming
    Replies: 16
    Last Post: 01-15-2006, 05:13 AM
  2. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 02:59 PM
  3. my text adventure
    By ckeener in forum C++ Programming
    Replies: 2
    Last Post: 06-06-2005, 08:33 AM
  4. Replies: 3
    Last Post: 05-25-2005, 01:50 PM