Thread: Text adventure game - desgin

  1. #1
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321

    Text adventure game - desgin

    Hi cboard.

    I have been working on a text adventure engine and I coudn't work it so I decided to scrap the whole thing and design a new one. All engines need a base class right?

    Code:
    class CGame_manager
    {
        public:
        CGame_manager();
        ~CGame_manager();
    
        protected:
    };
    ......something like that? Well I obviously need functions etc. But I still need to design which functions to make.

    Next thing that came to my mind was a game mode class. We obviously need to distiguish between game modes. I mean, you can't attack when looking in your inventory can you? Mayby a little something like this?

    Code:
    class CGame_mode
    {
        public:
        CGame_mode();
        ~CGame_mode();
       
        /*Havn't decided what i need here*/
        protected:
        std::vector<CGame_mode>CGame_states;
    };
    Then i thought that I need to manage the txt files that contain the storyline etc. How would I go about this?

    I recently read a thread containing a Menu class, should I also design a Menu class?

    Thats what I need help with, just getting the framework (if you want to call it that) set up so i can design the rest of my engine.

    All help is appreciated.

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    All engines need a base class right?
    Not necessarily. But if not, then you still need a function or something that is in charge of the whole program.

    A nice way to implement game modes would be to have a separate class for each mode.

    You could have a base class which all of these game mode classes derive from. This base class would handle printing stuff to the screen, clearing it, getting user input, etc. This is perhaps what you meant by a Menu class.

    Just a thought.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    You need to decide what your engine is going to do and how it is going to do it. Then you can create classes to handle those tasks. I'm not sure I understand the concept of game mode as it corresponds to a text adventure engine.

  4. #4
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321
    So.. something like this for a base class?

    Code:
    #include <fstream>
    
    class CGame_mode
    {
        public:
        CGame_mode();
        virtual ~CGame_mode();
    
        void CLoad_file(filename)
        {
            ifstream fin;
            fin << filename;
        }
        
        void Close_file(filename)
        {
            fstream fin;
            fin.close();
        }
    
        protected:
        std::string filename;
        fstream fin;
    };
    ....Then i would derive a class. Say......Inventory?

  5. #5
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    Why would you want an inventory class to inherit the Game_mode class?

    I'd start by setting up a class for the player, and a class for locations. Heres an example for a room on another thread:

    http://cboard.cprogramming.com/showt...t=93989&page=2

  6. #6
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    I just started working on my little text engine from the ground up... I figured, what do I need first? Well I figured that text was the most important thing in a text game so I needed to figure out a way to store and relay messages as well as translate input into actions.

    So I made a few classes to do this for me, I actually don't have the code here at work so when I get home I'll post some examples.
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  7. #7
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321
    Thanks, HURRY =P

  8. #8
    Registered User
    Join Date
    Oct 2006
    Location
    Little Rock, Arkansas
    Posts
    2

    Question

    I'm interested in learning this same game design process, but I see you never came back and posted the information you referred to.

    What Classes would you create for a text based game?

    Player Class
    Weapon Class
    Item Class
    Location Class
    Enemy Class
    Money Class

    What do you all think?

  9. #9
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    The State Design Pattern is a good way to manage game modes/states.

  10. #10
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Last post prior to xzk was nearly 4 months ago.

    Closed. Please do not bump old threads.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. New Project, text game, design stage.
    By Shamino in forum Game Programming
    Replies: 9
    Last Post: 05-23-2007, 06:39 AM
  2. C Programming 2d Array Question
    By jeev2005 in forum C Programming
    Replies: 3
    Last Post: 04-26-2006, 03:18 PM
  3. Text adventure engine idea. thoughts?
    By suzakugaiden in forum Game Programming
    Replies: 16
    Last Post: 01-15-2006, 05:13 AM
  4. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 02:59 PM
  5. Saving a text game
    By Unregistered in forum C++ Programming
    Replies: 4
    Last Post: 03-27-2002, 01:33 PM

Tags for this Thread