Just so people know, I am hoping that the OP is aiming at implementing the suggestions I made in this post. There are also other threads on the same subject. I wish people would not do this - I would rather 10 pages in one thread than a new thread every 2 days.
@Ch1156
OK, here is the class layout I was envisaging (Note the leading C on the class names ):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
class CMainApp {}; //Generic for loading / saving files, menus etc
class CGamePlay {}; //Generic controls the playing of the game
class CShop {}; //Buy CResources such as CAmmo, CMedipacks etc
class CBAckpack {}; //To keep CResources in - the Player has one of these as a member
class CResource {}; //Generic The backpack has Resorurces as members
class CMoney : public CResource {};
class CAmmo : public CResource {};
class CMedipack : public CResource {};
class CWeapon : public CResource {};//Generic
class CRifle : public CWeapon {};
class CShotgun : public CWeapon {};
class CPistol : public CWeapon {};
class CActor {}; //Generic You have Character which is OK
class CPlayer : public CActor {};//Generic
class CEnemy : public CActor {};//Generic
class CHero : public CPlayer {}; //optional
class CDinosaur : public CEnemy {};//Generic
class CTrex : public CDinosaur {};
class CRaptor : public CDinosaur {};
|
The classes with Generic in the comment means that you shouldn't be to create objects from these. One way to achieve this is to make their constructors protected. An attempt to create an object of this type result in a compile error. The other way is if the class has pure virtual functions - an interface class say.
Now, can I get you to believe in the idea that each class has it's own .h & .cpp files? And not to put code in header files? Don't combine 2 headers together. As I said several times you should be able to get your IDE to do this automatically with the class wizard. Well mine does (KDevelop on Linux) anyway - I am hoping the others do too.
The reason header files don't have code in them is because you need to include them in whatever .cpp needs to use that type of object. Having code in the header just makes a huge mess if the file is included everywhere. The header file declares the class and it's functions once, but could be included many times into other files - that is why you have header guards and /or
#pragma once
. The code for the class functions is written once and once only in a .cpp file, and never ever included in anything. You can have forward declarations of classes, to get around circular dependencies.
The other thing is that naming of variables is important. For example, the CActor class can have a protected variable m_Health (member variables start with m_), which inherited by everything underneath it. This is much better than having EnemyHealth, PlayerHealth. One of the main ideas is to specify things once only, and write code once. If you see things being being repeated, then you need to alter the design - push things higher up the tree, create new classes if you need to. Keeping names general helps with this.
I am using some naming conventions - CMyClass, m_MemberVariable & CamelCaseForNames, these are not my particular conventions and IMO there are good reasons for using them. Some people have other conventions - I am just showing what I do.
I know this is all a big learning curve for you, but stick with it - I think it is great when one learns lots of new things. And I think there will a great sense of pride when you get it finished and know that it has been done very well compared to your original attempt. Ha - now you have lots to go on with. Once you have made all the classes, we can start at the highest level of class, to put in member variables and functions.
Above all - have fun !!!