Jump to content
  • Advertisement


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


C++ class problem

This topic is 5753 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m working on my Text RPG (source atthis place. As you can see, in the Item member functions, I have SetItem. In the newly-created member function, *ConvertName, I want to take in the intem type, item number, and whether there is 1, or != 1 items. What I want to do is make it easy to output any item''s number, in the loop at the bottom, in the inventory outputing function. So, in the *ConvertName, I want to create and object of the Item class to SetStats, and the GetName with, in order to easily output an item''s name. Is this the right way to do it? How is it done?

Share this post

Link to post
Share on other sites
a) You''re using C strings, with strcpy
b) Each and every data member has a pair of functions modifying it that exactly reflect its type ( char[21], char[7] ...)
c) The initialisation data is in huge nested switch statements.
d) The classes themselves offer zero functionality
e) The main logic is laid out as switch statements, without decoupling code and ''world'' data.

a,b and d alone would have me wondering why you''re using classes at all
c and e alone would have me teaching you about data files

All together leave me speechless and reluctant to further examine the code.

- For text fields in a class, use a C++ std::string. They support direct assignment, concatenation, array access ...
- Only offer access functions for data members that need to be exposed
- Consider placing your attributes in an array : there is no need for separate GetLevel, GetSpellLevel ... it could be GetAttribute( ATTR_LEVEL ), GetAttribute( ATTR_SPELL_LEVEL ) ... ONE single member function ( two if you want read/write ).
- Your initialisation data in text (or binary) files and load them up. Or in arrays. NOT in switch statements. Switch statements are good when you want to execute different code based on a switch value. Here, you''re just loading different data, which could be stored at different array offsets.
- Your race & class modifiers could likewise be stored in an array, or a file, not hardcoded at the point of use, where they will be a pain to change ( and cause a full recompile everytime they do ... think about the playtesting phase of the game ... do you think they rebuild it everytime they want to tweak ONE single parameter ? )
- Idem of your ''room'' descriptions and available choices. Learn to load them from files (Hint: fstream works just like iosstream)
- You direct all your print commands to cout. Shouldn''t the output stream be a function parameter ?

There is MUCH more to be said, but you already have your plate full.

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!