class DieT {
SetCommand(std::string);
std::string GetCommand();
bool ValidCommand()
void Roll();
int GetValue();
...
}
class GenericDieView {
virtual ~GenericDieView=default;
virtual void Display(int value) = 0;
virtual void Error()=0;
...
};
class GenericDieCommand{
virtual ~GenericDieCommand() = default;
virtual std::string GetCommandString();
virtual bool::HasNewString();
virtual bool::DoReroll();
virtual void::Reset();
...
};
class DieController() {
public:
void AddView(GenericDieView * view);
void AddInput(GenericDieCommand * command);
void Update() {
for (auto cmd : commands) {
if (cmd->HasNewString()) {
s = cmd->GetCommandString();
die.SetCommand(s);
if (not die.ValidCommand()) {
for(auto view: views){
view->Error();
}
}
}
if (cmd->DoReroll()) {
die.Roll();
v = die.GetValue()
for(auto view: views){
view->SetValue(v);
}
}
cmd->Reset();
}
}
...
private:
std::vector<GenericDieView> views;
std::vector<GenericDieCommand> commands;
DieT die;
}
enum ClassT { WIZARD, FIGHTER, BATTLEMAGE, BARD ...}
class PersonFactory {
public :
virtual ~PersonFactory() = default;
virtual PersonT * MakePerson(ClassT class){
PersonT * rv;
switch(class) {
case : WIZARD:
rv = new WizardT(...);
break;
}
return rv;
}
vector<std::string> ClassTypes();
ClassT ClassFromString(std::string classString);
};
PersontT * MakePlayerCharacter() {
PersonFactory maker;
auto classes = maker.ClassTypes();
cout << "Select the type of player you want.";
int choice = 1;
for(auto x: classes) {
cout << choice << " " << x << endl;
}
cin >> choice;
return maker.MakePerson( maker.ClassFromString(classes[i-1]));
}