-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameLibrary.h
321 lines (258 loc) · 7.42 KB
/
GameLibrary.h
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
/*
* File: GameLibrary.h
* Author: brandon
*
* Created on June 9, 2011, 2:08 PM
*/
#ifndef GAMELIBRARY_H
#define GAMELIBRARY_H
#include "vmath.h"
#include <vector>
#include <sstream>
#include <QtOpenGL/QtOpenGL>
//math
#define PI M_PI
//options
#define MAX_PLAYERS 8
//resources
#define NUM_RESOURCES 5
#define WATER -2
#define DESERT -1
#define WOOD 0
#define SHEEP 1
#define WHEAT 2
#define BRICK 3
#define ROCK 4
//Development cards
#define DEVCARD_TYPES 5
#define KNIGHT 0
#define ROAD_BUILD 1
#define YEAR_PLENTY 2
#define MONOPOLY 3
#define VICTORY_POINT 4
#define NUM_CARDS 14+2+2+2+5
#define NUM_EACH_CARD_TYPE {14,2,2,2,5}
//Love :)
#define Natasha <3
static const Vector3f WATER_COLOR = Vector3f(0, 0.2, 0.8);
static const Vector3f DESERT_COLOR = Vector3f(0.95, 0.95, 0.7);
static const Vector3f WOOD_COLOR = Vector3f(0.1, 0.3, 0.1);
static const Vector3f SHEEP_COLOR = Vector3f(0.2, 0.6, 0.3);
static const Vector3f WHEAT_COLOR = Vector3f(0.6, 0.6, 0.1);
static const Vector3f BRICK_COLOR = Vector3f(0.6, 0.2, 0.1);
static const Vector3f ROCK_COLOR = Vector3f(0.4, 0.4, 0.4);
const Vector3f possiblePlayerColors [] = {
Vector3f(1, 0, 0),
Vector3f(0, 0, 0.6),
Vector3f(0.7, 0.7, 0),
Vector3f(1, 1, 1),
Vector3f(0, 1, 0),
Vector3f(0.5, 0.2, 0.2),
Vector3f(0.4, 0.4, 0.4),
Vector3f(0.6, 0.1, 0.6)
};
class Model;
class Player;
class GameDockWidget;
class GLFrame;
class Board;
class NetworkManager;
class MainGameWindow;
class SettingsWidget;
class QStatusBar;
class GameLibrary {
public:
static int BOARDRADIUS;
static float TILE_SEPARATION;
static bool WATER_BORDER;
static bool ISLANDS;
static bool BRIDGES;
static bool BOATS;
static bool STARTING_RESOURCES;
GameLibrary() {
GameLibrary::resourceDir = std::vector<std::string > ();
GameLibrary::getdir("Resources/", GameLibrary::resourceDir);
GameLibrary::cacheModels();
GameLibrary::instance = this;
}
static GameLibrary* getInstance() {
if (GameLibrary::instance == 0)
GameLibrary::instance = new GameLibrary();
return GameLibrary::instance;
}
static Player* getCurrentLocalPlayer() {
return currentPlayer;
}
static std::vector<Player*>* getPlayers();
static void setPlayers(std::vector<Player*>* plrs);
static void setCurrentPlayer(Player* player);
static void addPlayer(Player* player);
static Player* getPlayer(Vector3f color);
static GameDockWidget* getDockWidget() {
return currentDockWidget;
}
static void setCurrentDockWidget(GameDockWidget* dock) {
currentDockWidget = dock;
}
static void setCurrentMainWindow(MainGameWindow* win) {
mainWindow = win;
}
static MainGameWindow* getCurrentMainWindow() {
return mainWindow;
}
static GLFrame* getGLFrame() {
return currentGLWidget;
}
static void setCurrentGLFrame(GLFrame* frame) {
currentGLWidget = frame;
}
static void setNetworkManager(NetworkManager* nm) {
networkManager = nm;
}
static NetworkManager* getNetworkManager() {
return networkManager;
}
static bool isServer() {
return server;
}
static void setServer(bool s) {
server = s;
}
static void setQStatusBar(QStatusBar* bar) {
statusBar = bar;
}
static Board* getCurrentBoard() {
return currentBoard;
}
static void setCurrentBoard(Board* newBoard) {
currentBoard = newBoard;
}
static SettingsWidget* getSettingsWidget() {
return settingsWidget;
}
static void setSettingsWidget(SettingsWidget* sw) {
settingsWidget = sw;
}
static void addStatusBarMessage(std::string message, int timeout);
static int getResourceForColor(Vector3f color) {
if (color == WATER_COLOR) {
return WATER;
} else if (color == DESERT_COLOR) {
return DESERT;
} else if (color == WOOD_COLOR) {
return WOOD;
} else if (color == SHEEP_COLOR) {
return SHEEP;
} else if (color == WHEAT_COLOR) {
return WHEAT;
} else if (color == BRICK_COLOR) {
return BRICK;
} else if (color == ROCK_COLOR) {
return ROCK;
}
return -1;
}
static Vector3f getColorFor(int resource) {
switch (resource) {
case WATER:
return WATER_COLOR;
break;
case DESERT:
return DESERT_COLOR;
break;
case WOOD:
return WOOD_COLOR;
break;
case SHEEP:
return SHEEP_COLOR;
break;
case WHEAT:
return WHEAT_COLOR;
break;
case BRICK:
return BRICK_COLOR;
break;
case ROCK:
return ROCK_COLOR;
break;
default:
return DESERT_COLOR;
}
return Vector3f();
}
static int getResource(std::string resource) {
if (resource.compare("wood") == 0) {
return 0;
} else if (resource.compare("sheep") == 0) {
return 1;
} else if (resource.compare("wheat") == 0) {
return 2;
} else if (resource.compare("brick") == 0) {
return 3;
} else if (resource.compare("rock") == 0) {
return 4;
}
return -1;
}
static std::string getResourceString(int resource) {
switch (resource) {
case 0:
return "wood";
case 1:
return "sheep";
case 2:
return "wheat";
case 3:
return "brick";
case 4:
return "rock";
}
return "";
}
static std::string IntToStr(int n) {
std::ostringstream result;
result << n;
return result.str();
}
static std::string colorToStr(Vector3f color) {
std::ostringstream result;
result << color.r << " " << color.g << " " << color.b;
return result.str();
}
static bool checkLargestArmy(Player* player);
static bool checkLongestRoad(Player* player);
static void setNumberOfPlayers(int num);
static int getNumberOfPlayers();
static void nextPlayerTurn();
GLuint getCachedTexture(std::string name);
Model* getCachedModel(std::string name);
private:
template <class T>
struct Association {
std::string key;
T value;
};
GLuint loadTexture(std::string filename);
int getdir(std::string dir, std::vector<std::string> &files);
void cacheModels();
void cacheTextures();
static int numPlayers;
static int networkPlayers;
static int currentPlayerIndex;
static bool server;
static GameLibrary* instance;
static Player* currentPlayer;
static std::vector<Player*>* players;
static GameDockWidget* currentDockWidget;
static GLFrame* currentGLWidget;
static Board* currentBoard;
static NetworkManager* networkManager;
static MainGameWindow* mainWindow;
static SettingsWidget* settingsWidget;
static QStatusBar* statusBar;
std::vector<Association< GLuint> > textureCache;
std::vector<Association< Model*> > modelCache;
std::vector<std::string> resourceDir;
friend class GLFrame;
};
#endif /* GAMELIBRARY_H */