Simple RPG.h newbie style

This is a discussion on Simple RPG.h newbie style within the C++ Programming forums, part of the General Programming Boards category; Just a nOOb, I have had a hard time thinking of things to program that will help me reinforce what ...

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    450

    Simple RPG.h newbie style

    Just a nOOb, I have had a hard time thinking of things to program that will help me reinforce what I am learning. I am just learning about classes, operator overloading and friends functions but really haven't done any programming.

    With that in mind I decided to start on somthing that has been overdone before a simple rpg charachter generator. So far I have just a header file and would like some comments on it.
    Code:
    #ifndef _RPG_H_
    #define _RPG_H_
    
    class Charachter
    {
        private:
            // charachter attributes
            sruct attribs
            {
                    char name[30];
                    char profession[20];
                    char armortype[20];
                    int armorclass;
                    int abilities[6];
                    int hitpoints;
            };
        
            // professions/armortypes to be read from file containing four choices
            char professions[20,4];
            char armortypes[20,4];
                                                    
            void rollabilities(int ab[6]);// or void rollabilities(int * ab)
            int rollhitpoints(const char * profess);
            int calcarmorclass(const char * armortyp);
            
         public:   
            Charachter();
            ~Charachter();
            
            char * getname();
            char * getprofession(const char * professions);
            char * getarmortype(const char * armortypes);
            
                    
            char * readprofessions();
            char * readarmortypes();
            
            void displaysheet(const attribs & odin);
            
    };
    #endif
    One thing I would like to implement though I do not know if it should be part of my charachter class is to have the possible professions and armortypes in a file hence my readprofessions function that will read the possible professions. I haven't used any of the new things I am learning like operator overloading of friends functions, but I feel I need to start two step backwards and implement the new features in the future (if needed).

  2. #2
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    I think the biggest thing is that "charachter" is spelled character.

    Having said that, instead of char arrays, you might want to investigate the standard template library's string class. It's a lot easier to use, and won't take you long to learn.
    Away.

  3. #3
    Registered User
    Join Date
    Jul 2003
    Posts
    450
    lol I must say I have always spelled character as charachter, guess you could say it is stupid or just part of my unique style

    I did buy a book on the STL but was waiting to finish C++ Primer Plus (for my second time, the first time was a couple years agoe and I have forgotten most everything.). Guess I could skip side ways and learn about strings, thanks.

  4. #4
    Registered User
    Join Date
    Jul 2003
    Posts
    450

    to strings

    I have switched over the variables to string in my class but have a few questions.

    Code:
    #ifndef _RPG_H_
    #define _RPG_H_
    
    class Charachter
    {
        private:
            // charachter attributes
            sruct attribs
            {
                    std::string name;
                    std::string profession;
                    std::string armortype;
                    std::string race;
                    int armorclass;
                    int abilities[6];
                    int hitpoints;
            };
        
            // professions/armortypes/races  to be read from file containing four choices
            static std::string professions[4];
            static std::string armortypes[4];
            static std::string races[4];
            
             // should I pass by refrence here or use a pointer instead?                                                                       
            void rollabilities(int ab[6],const std::string & race);
            int rollhitpoints(const std::string & profession);
            int calcarmorclass(const std::string & armortype);
            
    
            // should I put these functions in a different class along with the arrays?  They aren't strictly attributes of the charachter class rather possibilites to be checked against.
            //
            void readprofessions(std::string & professions);
            void readarmortypes(std::string & armortypes);
            void readraces(std::string & races);
            
         public:   
            Charachter();
            ~Charachter();
            
            std::string getname();
            std::string getprofession(const string * professions);
            //if I was to pass the string array professions should I use a pointer or refrence?
            std::string getarmortype(const string * armortypes);
                           
            void displaysheet(const attribs & odin);
            
    };
    #endif

  5. #5
    Registered User Azmeos's Avatar
    Join Date
    Jun 2003
    Posts
    65
    And those questions are...?

    You still have some spelling errors:
    Code:
    sruct attribs
    should be
    Code:
    struct attribs
    I also think you need to
    Code:
    #include <string>

  6. #6
    Registered User
    Join Date
    Jul 2003
    Posts
    450
    Wasn't sure if I needed to include <string> in my main or my header file.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple simple graphics
    By triplem in forum C Programming
    Replies: 2
    Last Post: 05-19-2003, 02:52 AM
  2. Very simple question, problem in my Code.
    By Vber in forum C Programming
    Replies: 7
    Last Post: 11-16-2002, 02:57 PM
  3. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  4. Need help with simple DAQ program
    By canada-paul in forum C++ Programming
    Replies: 12
    Last Post: 03-15-2002, 07:52 AM
  5. how do I extract a style from a DWORD style
    By zMan in forum Windows Programming
    Replies: 1
    Last Post: 01-17-2002, 09:09 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21