-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
193 lines (175 loc) · 6.02 KB
/
main.cpp
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#include <iostream>
#include <string>
#include <vector>
#include "Game.h"
#include "Assets.h"
#include "Settings.h"
template <class Container>
void split(const std::string& str, Container& cont, const std::string& delims = " ")
{
std::size_t current, previous = 0;
current = str.find_first_of(delims);
while (current != std::string::npos)
{
cont.push_back(str.substr(previous, current - previous));
previous = current + 1;
current = str.find_first_of(delims, previous);
}
cont.push_back(str.substr(previous, current - previous));
}
int main(int argc, char* argv[])
{
if (argc > 1)
{
std::string arg;
std::vector<std::string> splitResult;
for (int i = 1; i < argc; ++i)
{
arg = argv[i];
if (arg == "--help")
{
std::cout << "usage: Asteroids.exe [--help] [--version] [-window <value>x<value>] [-map <value>x<value>]"
"[-num_asteroids <value>] [-num_ammo <value>] [-ability_probability <value>]"
<< std::endl;
return 0;
}
else if (arg == "--version")
{
std::cout << "Asteroids version 0.3.4" << std::endl;
return 0;
}
else if (arg == "-window")
{
if (i + 1 < argc)
{
split(argv[++i], splitResult, "xX");
if (splitResult.size() == 2)
{
try
{
Settings::Instance().setVidoeMode(std::stoi(splitResult[0]), std::stoi(splitResult[1]));
}
catch (std::exception const& ex)
{
std::cout << "Input correct integer value" << std::endl;
return 1;
}
}
else
{
std::cout << "Argument must have 1 value letter x and 1 value. Example: 800x600 " << std::endl;
return 1;
}
splitResult.clear();
}
else
{
std::cerr << "-window option requires one argument size window (800x600)." << std::endl;
return 1;
}
}
else if (arg == "-map")
{
if (i + 1 < argc)
{
split(argv[++i], splitResult, "xX");
if (splitResult.size() == 2)
{
try
{
Settings::Instance().setMapSize(std::stoi(splitResult[0]), std::stoi(splitResult[1]));
}
catch (std::exception const& ex)
{
std::cout << "Input correct integer value" << std::endl;
return 1;
}
}
else
{
std::cout << "Argument must have 1 value letter x and 1 value. Example: 1000x1000 " << std::endl;
return 1;
}
splitResult.clear();
}
else
{
std::cerr << "-map option requires one argument size map (1000x1000)." << std::endl;
return 1;
}
}
else if (arg == "-num_asteroids")
{
if (i + 1 < argc)
{
try
{
Settings::Instance().setNumberOfAsteroids(std::stoi(argv[++i]));
}
catch (std::exception const& ex)
{
std::cout << "Input correct integer value" << std::endl;
return 1;
}
}
else
{
std::cerr << "-num_asteroids option requires one argument numver of asteroids (10)." << std::endl;
return 1;
}
}
else if (arg == "-num_ammo")
{
if (i + 1 < argc)
{
try
{
Settings::Instance().setNumberOfAmmo(std::stoi(argv[++i]));
}
catch (std::exception const& ex)
{
std::cout << "Input correct integer value" << std::endl;
return 1;
}
}
else
{
std::cerr << "-num_ammo option requires one argument numver of ammo (4)." << std::endl;
return 1;
}
}
else if (arg == "-ability_probability")
{
if (i + 1 < argc)
{
try
{
Settings::Instance().setAbilityProbability(std::stof(argv[++i]));
}
catch (std::exception const& ex)
{
std::cout << "Input correct float value" << std::endl;
return 1;
}
}
else
{
std::cerr << "-num_ammo option requires one argument numver of ammo (4)." << std::endl;
return 1;
}
}
else
{
std::cerr << "unknown option: " << arg << std::endl;
return 1;
}
}
}
Assets::Instance().load();
Game game;
game.setupSystem();
game.initialize();
while (game.loop());
game.shutdown();
return 0;
}