-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cc
86 lines (75 loc) · 2.51 KB
/
main.cc
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <iostream>
#include <sstream>
#include <string>
#include "controller/game.h"
#include "public/global.h"
using namespace std;
int main(int nargs, const char** arglist) {
try {
/* parse commandline argument */
string argstr;
for (int i = 0; i < nargs; i++) {
argstr += arglist[i];
argstr += " ";
}
unsigned long p = string::npos;
if (argstr.find("-text") != string::npos) {
Global:: TEXTMODE = true;
cerr << ">> text-only mode on" << endl;
p = string::npos;
} else {
Global:: TEXTMODE = false;
}
if (argstr.find("-no-op") != string::npos) {
Global:: OPTIMIZED = false;
cerr << ">> optimized mode off" << endl;
p = string::npos;
} else {
Global:: OPTIMIZED = true;
}
if ((p = argstr.find("-seed")) != string::npos) {
string tmp = argstr.substr(p+5);
stringstream ss(tmp.c_str());
int i = 0;
ss >> i;
if (! ss.good()) {throw string("\nERROR: missing -seed number");}
Global:: SEED = i;
cerr << ">> set seed to " << i << endl;
p = string::npos;
} else {
Global:: SEED = 0;
}
if ((p = argstr.find("-scriptfile")) != string::npos) {
string tmp = argstr.substr(p+11);
stringstream ss(tmp.c_str());
string filename;
ss >> filename;
if (! ss.good()) {throw string("\nERROR: missing scriptfile name");}
Global:: SCRIPTFILE = filename;
cerr << ">> using scriptfile: "<< filename << endl;
p = string::npos;
}
if ((p = argstr.find("-startlevel")) != string::npos) {
string tmp = argstr.substr(p+11);
stringstream ss(tmp.c_str());
int i;
ss >> i;
if (! ss.good()) {throw string("\nERROR: missing -startlevel number");}
Global:: STARTLEVEL = i;
cerr << ">> set startlevel to " << i << endl;
p = string::npos;
} else {
Global:: STARTLEVEL = 0;
}
#if DEBUG
int i;
cerr << "Size: ";
cin >> i;
Game game(i);
#else
Game game(10); // a 10 x 10 game begins
#endif
} catch (const string& e) {
cerr << e << endl;
}
}