97 |
|
|
98 |
int option_index = 1; |
int option_index = 1; |
99 |
int res; |
int res; |
100 |
|
bool found_d = false; |
101 |
|
bool found_m = false; |
102 |
while ((res = getopt_long(argc, argv, short_options, |
while ((res = getopt_long(argc, argv, short_options, |
103 |
long_options, &option_index)) != -1) |
long_options, &option_index)) != -1) |
104 |
{ |
{ |
114 |
return NULL; |
return NULL; |
115 |
case 'd': |
case 'd': |
116 |
m_dicStr = optarg; |
m_dicStr = optarg; |
117 |
|
found_d = true; |
118 |
break; |
break; |
119 |
case 'm': |
case 'm': |
120 |
m_modeStr = optarg; |
m_modeStr = optarg; |
121 |
|
found_m = true; |
122 |
break; |
break; |
123 |
case 300: |
case 300: |
124 |
m_human++; |
m_human++; |
132 |
} |
} |
133 |
} |
} |
134 |
|
|
135 |
// 2) Try to load the dictionary |
// 2) Make sure the mandatory options are present |
136 |
|
if (!found_d || !found_m) |
137 |
|
{ |
138 |
|
cerr << "Mandatory option missing: "; |
139 |
|
if (!found_d) |
140 |
|
cerr << "dict"; |
141 |
|
else if (!found_m) |
142 |
|
cerr << "mode"; |
143 |
|
cerr << "\n"; |
144 |
|
|
145 |
|
printUsage(argv[0]); |
146 |
|
return NULL; |
147 |
|
} |
148 |
|
|
149 |
|
// 3) Try to load the dictionary |
150 |
if (Dic_load(&m_dic, m_dicStr.c_str())) |
if (Dic_load(&m_dic, m_dicStr.c_str())) |
151 |
{ |
{ |
152 |
cerr << "Could not load dictionary '" << m_dicStr << "'\n"; |
cerr << "Could not load dictionary '" << m_dicStr << "'\n"; |
153 |
return NULL; |
return NULL; |
154 |
} |
} |
155 |
|
|
156 |
// 3) Try to create a game object |
// 4) Try to create a game object |
157 |
Game *game = NULL; |
Game *game = NULL; |
158 |
if (m_modeStr == "training" || m_modeStr == "t") |
if (m_modeStr == "training" || m_modeStr == "t") |
159 |
{ |
{ |
173 |
return NULL; |
return NULL; |
174 |
} |
} |
175 |
|
|
176 |
// 4) Add the players |
// 5) Add the players |
177 |
for (int i = 0; i < m_human; i++) |
for (int i = 0; i < m_human; i++) |
178 |
game->addHumanPlayer(); |
game->addHumanPlayer(); |
179 |
for (int i = 0; i < m_ai; i++) |
for (int i = 0; i < m_ai; i++) |
180 |
game->addAIPlayer(); |
game->addAIPlayer(); |
181 |
|
|
182 |
// 5) Set the variant |
// 6) Set the variant |
183 |
if (m_joker) |
if (m_joker) |
184 |
game->setVariant(Game::kJOKER); |
game->setVariant(Game::kJOKER); |
185 |
|
|
196 |
void GameFactory::printUsage(const string &iBinaryName) const |
void GameFactory::printUsage(const string &iBinaryName) const |
197 |
{ |
{ |
198 |
cout << "Usage: " << iBinaryName << " [options]\n" |
cout << "Usage: " << iBinaryName << " [options]\n" |
199 |
<< "\n" |
<< "Options:\n" |
200 |
<< " -h, --help Print this help and exit\n" |
<< " -h, --help Print this help and exit\n" |
201 |
<< " -v, --version Print version information and exit\n" |
<< " -v, --version Print version information and exit\n" |
202 |
<< " -m, --mode {duplicate,d,freegame,f,training,t}\n" |
<< " -m, --mode {duplicate,d,freegame,f,training,t}\n" |
203 |
<< " Choose game mode\n" |
<< " Choose game mode (mandatory)\n" |
204 |
<< " -d, --dict <string> Choose a dictionary\n" |
<< " -d, --dict <string> Choose a dictionary (mandatory)\n" |
205 |
<< " --human Add a human player\n" |
<< " --human Add a human player\n" |
206 |
<< " --ai Add a AI (Artificial Intelligence) player\n" |
<< " --ai Add a AI (Artificial Intelligence) player\n" |
207 |
<< " --joker Play with the \"Joker game\" variant\n"; |
<< " --joker Play with the \"Joker game\" variant\n"; |