#include #include #include "PlayerT.h" #include "PesantT.h" #include "FighterT.h" #include "WizardT.h" #include "BattleMageT.h" #include "PersonFactoryT.h" #include "names.h" using namespace std; string RandName() { size_t pos = rand() % People_Names.size(); return People_Names[pos]; } shared_ptr RandomPlayer() { vector classes = ClassTypes(); PersonFactoryT factory; ClassT type = classes[rand() % (classes.size()-1)]; return factory.MakePerson(type, RandName()); } void PrintPlayer(shared_ptr p) { cout << "*******************************************" << endl; // speak cout << p->Name() << " says \"" << p->Speak() << '"' << endl; cout << endl; // fight a bit. cout << "An attack by " << p->Name() << endl; cout << p->Fight() << endl; cout << p->Fight() << endl; cout << p->Fight() << endl; cout << p->Fight() << endl; cout << endl; // note that the dammage incured is different p->ChangeHP(-4); cout << p->Name() << " is injured for 4 points"; cout << " and now has " << p->HP() <<"/" << p->MaxHP() << endl; cout << endl; return; } void DoSpecial(const shared_ptr & p) { shared_ptr fighterPtr; shared_ptr wizardPtr; wizardPtr = dynamic_pointer_cast(p); if (wizardPtr != nullptr) { cout << "Time to study " << wizardPtr->Study() << endl; } fighterPtr = dynamic_pointer_cast(p); if (fighterPtr != nullptr) { cout << "Time to workout " << fighterPtr->Workout() << endl; } cout << endl; } int main() { srand(static_cast(time(nullptr))); vector> players; for(int i = 0; i < 5; i++) { players.push_back(RandomPlayer()); } for(auto x: players) { PrintPlayer(x); DoSpecial(x); } return 0; }