Thread: Please help (Text Adventure Game)

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    13

    Please help (Text Adventure Game)

    I am creating a text adventure game. I have a class called room with a list of rooms in it. I want to set descriptions for these rooms, what objects are in them and what exits there are to the other rooms but i dont know how to. Any suggestions. Thank you.

    Angel

    Code:
    //Room.h
    
    #include <iostream>
    using std::ostream;
    using std::istream;
    
    
    class Room
    {
    
    private:
    
    string room1;
    string room2;
    string room3;
    string room4;
    string kitchen;
    string hall;
    string descriptionroom1;
    string descriptionroom2;
    string descriptionroom3;
    string descriptionroom4;
    string descriptionkitchen;
    string descriptionhall;
    
    public:
    
    
    
    }//class Room

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    You have to get back to the basics of Object oriented programming. You don't create a class and then... put all the objects in the class. Each room should be an object. You declare as many of those objects as you have rooms.
    Sent from my iPadŽ

  3. #3
    Registered User Kurisu's Avatar
    Join Date
    Feb 2006
    Posts
    62
    Code:
    //Room.h
    
    class Room
    {
    
    private:
    
    string description;
    string exits;
    string objects;
    
    public:
      Room(...);
      string getDescription();
      string getExits();
      string getObjects();
    
    };
    Code:
    int main()
    {
      Room kitchen(...);
      Room hallway(...);
      Room bedroom(...);
    
      return 0;
    }
    I of course wouldn't use strings, but since I'm not really sure what ur doing I just used them for the sake of example.
    Last edited by Kurisu; 02-23-2006 at 03:55 PM.

  4. #4
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    If you're going to write the getters you might as well right the setters.

    Code:
    void setDescription(string);
    void setExits(string);
    void setObjects(string);
    ...but in reality, you have to go back and think about what your rooms really contain. Would objects really be a string? What about exits? Look at how I've implemented this and tell me if it makes more sense to you.

    Code:
    class roomObject;  // Implement this later, just know it's there
    
    class Room {
       public:
          void setDescription(string);
          string showDescrition();
          void takeObject(roomObject);
          void dropObject(roomObject);
          void exitThrough(Room);
       private:
          string Description;
          vector<roomObject> Objects(1);
          vector<Room *> Exits(1);   // I'm not sure if you can use a vector of pointers,
                                     // infact I think STL has better containers for this
                                     // but you get the idea.
    };
    Last edited by SlyMaelstrom; 02-23-2006 at 04:07 PM.
    Sent from my iPadŽ

  5. #5
    Registered User Kurisu's Avatar
    Join Date
    Feb 2006
    Posts
    62
    yep, but I have a feeling he won't know what either are :P

  6. #6
    Registered User
    Join Date
    Feb 2006
    Posts
    13
    Quote Originally Posted by Kurisu
    Code:
    //Room.h
    
    class Room
    {
    
    private:
    
    string description;
    string exits;
    string objects;
    
    public:
      Room(...);    
      string getDescription();
      string getExits();
      string getObjects();
    
    };
    Code:
    int main()
    {
      Room kitchen(...);
      Room hallway(...);
      Room bedroom(...);
    
      return 0;
    }
    I of course wouldn't use strings, but since I'm not really sure what ur doing I just used them for the sake of example.

    Thank you everyone for your help but i am still al little confused. Why wouldnt you use strings? And where do i put the list of rooms and the objects in them and the description? Thank you.

  7. #7
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    You should use strings (although maybe not as a way of storing exits or objects). You should also remember to add the #include <string> when you do.

    You can have a list of rooms anywhere else, like in your main game engine, or in main(), or in another class that handles all the rooms.
    Last edited by Daved; 02-23-2006 at 04:14 PM.

  8. #8
    Registered User
    Join Date
    Feb 2006
    Posts
    13
    Quote Originally Posted by SlyMaelstrom
    If you're going to write the getters you might as well right the setters.

    Code:
    void setDescription(string);
    void setExits(string);
    void setObjects(string);
    ...but in reality, you have to go back and think about what your rooms really contain. Would objects really be a string? What about exits? Look at how I've implemented this and tell me if it makes more sense to you.

    Code:
    class roomObject;  // Implement this later, just know it's there
    
    class Room {
       public:
          void setDescription(string);
          string showDescrition();
          void takeObject(roomObject);
          void dropObject(roomObject);
          void exitThrough(Room);
       private:
          string Description;
          vector<roomObject> Objects(1);
          vector<Room *> Exits(1);   // I'm not sure if you can use a vector of pointers,
                                     // infact I think STL has better containers for this
                                     // but you get the idea.
    };

    I dont know what a vector is but i do have to use a lot of pointer because i have 4 different classes.

  9. #9
    Me pwn you.
    Join Date
    Feb 2006
    Location
    At my computer or in my bed.
    Posts
    46
    Okay, maybe we could actually HELP the poor fellow.
    But first, what are you doing, none bothred to ask that.
    Mabe you should make classes for the objects FIRST and then slap them into you're room
    Also, maybe you should do without rooms for now. It would do better for a learning
    expirance to just wok on the basics. I'm working on a text based
    RPG right now, I have classes for all types of items, then classes
    n'such for spells and crap like that. You should work on the little
    stuff before you write the big stuff. Like, for examle, the ellefant
    wasn't made all at once. It's made up of tiny cells, that make bigger cells that make bigger cells. In a similer way you should
    make classes that are used in other classes and more and more
    like this

    Code:
    class WEAPON {
    
    //weapon code
    
    
    };
    
    class ARMOR {
    
    //armor code
    
    };
    
    class POTION {
    
    //potion code
    
    };
    
    
    class ITEM {
    
    int type // 0 for potion 1 for weapon....
    
    POTION P;
    WEAPON W;
    ARMOR A;
    
    };
    
    
    class INV {
    
    ITEM Items[5];
    
    long GOLD;  
    
    //..........
    
    
    };
    
    
    class PLAYER {
    
    INV Invintory;
    
    int HP, CON, DEX, STR, WIS, CHA, INT, MANNA, ....
    
    };

    See what I mean... Don't make the player before you make the ARMOR.

  10. #10
    Registered User
    Join Date
    Feb 2006
    Posts
    13
    So what you are saying is i should work on my thing class which hold all the objects which are supposed to go in the room? Because i also have a player class which is where i was going to know what objects the player is holding and the players location, a game class which i was gonna have keep the current information about the game, initialize the game and set up all the location so if i type N it knows to go north 2 the other room and i also wanted this class to process the move typed in by the player and determine when the game is over. Then there is the room class where i was gonna contain the name of the room and the description what is in the room and where each exit goes. Thank you.

    Angel

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C Programming 2d Array Question
    By jeev2005 in forum C Programming
    Replies: 3
    Last Post: 04-26-2006, 03:18 PM
  2. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 02:59 PM
  3. Game Independent Anti-cheat Project Needs Programmers
    By GIA Project Lea in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 09-15-2005, 07:41 PM
  4. Saving a text game
    By Unregistered in forum C++ Programming
    Replies: 4
    Last Post: 03-27-2002, 01:33 PM
  5. Text Based Game
    By drdroid in forum C++ Programming
    Replies: 2
    Last Post: 02-18-2002, 06:21 PM