1. No, but you're missing an important point. C++ supports procedural and object oriented programming. And typically, C++ programs use a mix of both techniques. It helps to be clear what code is using what paradigm.
Procedural programming uses classes as abstract data types to control resource management and templates to do generic things.
Object oriented programming uses classes as objects and interfaces. And they use virtual functions for methods and possibly RTTI. The object oriented facility in C++ only works thru pointers (or references).
Example:
Let's say we have your Fighter, Archer, Cavalry and Civilian objects, all derived from Person. Typically, you'll need to hold them in a collection, like:
|
typedef std::vector<Person*> characters_type
| |
Then, in the game loop, you'll probably want to run the attack() method on each. The OO mechanism makes the call to the right attack() method.
1 2 3 4 5 6 7 8 9 10 11
|
void run(characters_type& characters) {
for (bool quit = false; !quit; ) {
// do other stuff ...
for (Person* character : characters) {
character->attack();
}
// do other stuff ...
}
}
| |
And to create your characters, you use a factory of some kind. This code reads a json string like:
|
{ "name1" : "archer", "name2" : "archer", "name3" : "civilian" }
| |
The factory that reads it using RapidJSON might look like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
characters_type create_characters(const std::string& json_config) {
characters_type characters;
rapidjson::Document doc;
doc.Parse(json_config.c_str());
for (auto p = doc.MemberBegin(); p != doc.MemberEnd(); ++p) {
if (p->value.IsString() && !strcmp(p->GetString(), "archer")) {
characters.push_back(new Archer(p->name.GetString());
}
if (p->value.IsString() && !strcmp(p->GetString(), "civilian")) {
characters.push_back(new Civilian(p->name.GetString());
}
// and so on ...
}
return characters;
}
| |
2. Your names are ok. Personally, I'm not hung up on style. Just pick any style and be consistent through the program.
3. Not sure what else to say other than, please come back with any questions.