[4c202e0] | 1 | #include "../../common/Compiler.h"
|
---|
| 2 |
|
---|
[e08572c] | 3 | #if defined WINDOWS
|
---|
[0dde5da] | 4 | #include <winsock2.h>
|
---|
[6319311] | 5 | #include <ws2tcpip.h>
|
---|
[e08572c] | 6 | #elif defined LINUX
|
---|
[0dde5da] | 7 | #include <sys/types.h>
|
---|
| 8 | #include <unistd.h>
|
---|
| 9 | #include <sys/socket.h>
|
---|
| 10 | #include <netinet/in.h>
|
---|
| 11 | #include <netdb.h>
|
---|
| 12 | #include <cstring>
|
---|
[34bd549] | 13 | #elif defined MAC
|
---|
| 14 | #include <netdb.h>
|
---|
[a845faf] | 15 | #endif
|
---|
[1912323] | 16 |
|
---|
[88cdae2] | 17 | #include <cstdio>
|
---|
| 18 | #include <cstdlib>
|
---|
[8c74150] | 19 | #include <sys/types.h>
|
---|
[a845faf] | 20 | #include <string>
|
---|
[1912323] | 21 | #include <iostream>
|
---|
[ace001a] | 22 | #include <iomanip>
|
---|
[88cdae2] | 23 | #include <sstream>
|
---|
[8271c78] | 24 | #include <fstream>
|
---|
[3a79253] | 25 | #include <map>
|
---|
[f63aa57] | 26 | #include <vector>
|
---|
[8aed9c0] | 27 | #include <stdexcept>
|
---|
[3a79253] | 28 |
|
---|
[d352805] | 29 | #include <allegro5/allegro.h>
|
---|
| 30 | #include <allegro5/allegro_font.h>
|
---|
| 31 | #include <allegro5/allegro_ttf.h>
|
---|
[88cdae2] | 32 | #include <allegro5/allegro_primitives.h>
|
---|
[7d7df47] | 33 |
|
---|
[e607c0f] | 34 | #include "../../common/Common.h"
|
---|
[b35b2b2] | 35 | #include "../../common/MessageContainer.h"
|
---|
[10f6fc2] | 36 | #include "../../common/MessageProcessor.h"
|
---|
[62ee2ce] | 37 | #include "../../common/WorldMap.h"
|
---|
[4c202e0] | 38 | #include "../../common/Player.h"
|
---|
[fbcfc35] | 39 | #include "../../common/Projectile.h"
|
---|
[2ee386d] | 40 | #include "../../common/Game.h"
|
---|
[3e44a59] | 41 | #include "../../common/GameSummary.h"
|
---|
[7d7df47] | 42 |
|
---|
[87b3ee2] | 43 | #include "Window.h"
|
---|
[6319311] | 44 | #include "TextLabel.h"
|
---|
[87b3ee2] | 45 | #include "Button.h"
|
---|
[6319311] | 46 | #include "Textbox.h"
|
---|
[5c95436] | 47 | #include "RadioButtonList.h"
|
---|
[6319311] | 48 |
|
---|
| 49 | #include "GameRender.h"
|
---|
| 50 |
|
---|
[6475138] | 51 | #include "chat.h"
|
---|
| 52 |
|
---|
[a845faf] | 53 | #ifdef WINDOWS
|
---|
[6475138] | 54 | #pragma comment(lib, "ws2_32.lib")
|
---|
[a845faf] | 55 | #endif
|
---|
[1912323] | 56 |
|
---|
| 57 | using namespace std;
|
---|
| 58 |
|
---|
[0dde5da] | 59 | void initWinSock();
|
---|
| 60 | void shutdownWinSock();
|
---|
[b29ff6b] | 61 | void createGui(ALLEGRO_FONT* font);
|
---|
[6f64166] | 62 |
|
---|
| 63 | void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, map<unsigned int, Player*>& mapPlayers, map<string, int>& mapGames, unsigned int& curPlayerId);
|
---|
| 64 | void handleMsgPlayer(NETWORK_MSG &msg, map<unsigned int, Player*>& mapPlayers, map<string, int>& mapGames);
|
---|
| 65 | void handleMsgGameInfo(NETWORK_MSG &msg, map<unsigned int, Player*>& mapPlayers, map<string, int>& mapGames);
|
---|
| 66 |
|
---|
[1f1eb58] | 67 | int getRefreshRate(int width, int height);
|
---|
[929b4e0] | 68 | void drawMessageStatus(ALLEGRO_FONT* font);
|
---|
[87b3ee2] | 69 |
|
---|
[929b4e0] | 70 | // Callback declarations
|
---|
[5c95436] | 71 | void goToLoginScreen();
|
---|
| 72 | void goToRegisterScreen();
|
---|
[87b3ee2] | 73 | void registerAccount();
|
---|
| 74 | void login();
|
---|
| 75 | void logout();
|
---|
| 76 | void quit();
|
---|
| 77 | void sendChatMessage();
|
---|
[b35b2b2] | 78 | void toggleDebugging();
|
---|
[fd9cdb5] | 79 | void goToProfileScreen();
|
---|
| 80 | void goToLobbyScreen();
|
---|
[a0ce8a3] | 81 | void joinGame(); // for joining the game lobby
|
---|
| 82 | void createGame(); // for joining the game lobby
|
---|
| 83 | void joinWaitingArea();
|
---|
| 84 | void joinRedTeam();
|
---|
| 85 | void joinBlueTeam();
|
---|
| 86 | void startGame(); // for leaving game lobby and starting the actual game
|
---|
[03ba5e3] | 87 | void leaveGame();
|
---|
[3e44a59] | 88 | void closeGameSummary();
|
---|
[4da5aa3] | 89 |
|
---|
[d352805] | 90 | const float FPS = 60;
|
---|
[9b1e12c] | 91 | const int SCREEN_W = 1024;
|
---|
| 92 | const int SCREEN_H = 768;
|
---|
[0cc431d] | 93 |
|
---|
| 94 | enum STATE {
|
---|
| 95 | STATE_START,
|
---|
[1785314] | 96 | STATE_LOBBY,
|
---|
[a0ce8a3] | 97 | STATE_GAME_LOBBY,
|
---|
[e0fd377] | 98 | STATE_GAME
|
---|
[d352805] | 99 | };
|
---|
[87b3ee2] | 100 |
|
---|
| 101 | int state;
|
---|
| 102 |
|
---|
| 103 | bool doexit;
|
---|
| 104 |
|
---|
[f63aa57] | 105 | vector<GuiComponent*> vctComponents;
|
---|
| 106 |
|
---|
[87b3ee2] | 107 | Window* wndLogin;
|
---|
[5c95436] | 108 | Window* wndRegister;
|
---|
[1785314] | 109 | Window* wndLobby;
|
---|
[f63aa57] | 110 | Window* wndLobbyDebug;
|
---|
[fd9cdb5] | 111 | Window* wndProfile;
|
---|
[a0ce8a3] | 112 | Window* wndGameLobby;
|
---|
[3ff2bd7] | 113 | Window* wndGame;
|
---|
[3e44a59] | 114 | Window* wndGameSummary;
|
---|
[87b3ee2] | 115 | Window* wndCurrent;
|
---|
| 116 |
|
---|
[5c95436] | 117 | // wndLogin
|
---|
[87b3ee2] | 118 | Textbox* txtUsername;
|
---|
| 119 | Textbox* txtPassword;
|
---|
[365e156] | 120 | TextLabel* lblLoginStatus;
|
---|
[5c95436] | 121 |
|
---|
| 122 | // wndRegister
|
---|
| 123 | Textbox* txtUsernameRegister;
|
---|
| 124 | Textbox* txtPasswordRegister;
|
---|
| 125 | RadioButtonList* rblClasses;
|
---|
[365e156] | 126 | TextLabel* lblRegisterStatus;
|
---|
[5c95436] | 127 |
|
---|
[929b4e0] | 128 | // wndLobby
|
---|
| 129 | Textbox* txtJoinGame;
|
---|
| 130 | Textbox* txtCreateGame;
|
---|
[87b3ee2] | 131 | Textbox* txtChat;
|
---|
| 132 |
|
---|
| 133 | int sock;
|
---|
| 134 | struct sockaddr_in server, from;
|
---|
| 135 | struct hostent *hp;
|
---|
| 136 | NETWORK_MSG msgTo, msgFrom;
|
---|
| 137 | string username;
|
---|
[b35b2b2] | 138 | chat chatConsole, debugConsole;
|
---|
| 139 | bool debugging;
|
---|
[803566d] | 140 | Game* game;
|
---|
[3e44a59] | 141 | GameSummary* gameSummary;
|
---|
[a0ce8a3] | 142 | Player* currentPlayer;
|
---|
[1f1eb58] | 143 |
|
---|
[4c00935] | 144 | int honorPoints, wins, losses, numGames;
|
---|
[b28e2bf] | 145 | int** gameHistory;
|
---|
| 146 |
|
---|
[10f6fc2] | 147 | MessageProcessor msgProcessor;
|
---|
| 148 |
|
---|
[d352805] | 149 | int main(int argc, char **argv)
|
---|
| 150 | {
|
---|
| 151 | ALLEGRO_DISPLAY *display = NULL;
|
---|
| 152 | ALLEGRO_EVENT_QUEUE *event_queue = NULL;
|
---|
| 153 | ALLEGRO_TIMER *timer = NULL;
|
---|
[e6c26b8] | 154 | map<unsigned int, Player*> mapPlayers;
|
---|
[6f64166] | 155 | map<string, int> mapGames;
|
---|
[88cdae2] | 156 | unsigned int curPlayerId = -1;
|
---|
[68d94de] | 157 | ofstream outputLog;
|
---|
| 158 |
|
---|
[803566d] | 159 | doexit = false;
|
---|
[b35b2b2] | 160 | debugging = false;
|
---|
[803566d] | 161 | bool redraw = true;
|
---|
| 162 | bool fullscreen = false;
|
---|
| 163 | game = NULL;
|
---|
[3e44a59] | 164 | gameSummary = NULL;
|
---|
[15efb4e] | 165 |
|
---|
[b28e2bf] | 166 | honorPoints = 0;
|
---|
[4c00935] | 167 | wins = 0;
|
---|
| 168 | losses = 0;
|
---|
[b28e2bf] | 169 | numGames = 0;
|
---|
| 170 | gameHistory = NULL;
|
---|
| 171 |
|
---|
[87b3ee2] | 172 | state = STATE_START;
|
---|
[9a3e6b1] | 173 |
|
---|
[d352805] | 174 | if(!al_init()) {
|
---|
| 175 | fprintf(stderr, "failed to initialize allegro!\n");
|
---|
| 176 | return -1;
|
---|
| 177 | }
|
---|
| 178 |
|
---|
[8271c78] | 179 | outputLog.open("client.log", ios::app);
|
---|
| 180 | outputLog << "Started client on " << getCurrentDateTimeString() << endl;
|
---|
| 181 |
|
---|
[88cdae2] | 182 | if (al_init_primitives_addon())
|
---|
| 183 | cout << "Primitives initialized" << endl;
|
---|
| 184 | else
|
---|
| 185 | cout << "Primitives not initialized" << endl;
|
---|
| 186 |
|
---|
[d352805] | 187 | al_init_font_addon();
|
---|
| 188 | al_init_ttf_addon();
|
---|
| 189 |
|
---|
[b29ff6b] | 190 | ALLEGRO_FONT* font;
|
---|
[88cdae2] | 191 | #if defined WINDOWS
|
---|
[b29ff6b] | 192 | font = al_load_ttf_font("../pirulen.ttf", 12, 0);
|
---|
[88cdae2] | 193 | #elif defined LINUX
|
---|
[b29ff6b] | 194 | font = al_load_ttf_font("pirulen.ttf", 12, 0);
|
---|
[34bd549] | 195 | #elif defined MAC
|
---|
| 196 | font = al_load_ttf_font("pirulen.ttf", 12, 0);
|
---|
[88cdae2] | 197 | #endif
|
---|
| 198 |
|
---|
[d352805] | 199 | if (!font) {
|
---|
| 200 | fprintf(stderr, "Could not load 'pirulen.ttf'.\n");
|
---|
| 201 | getchar();
|
---|
[803566d] | 202 | return -1;
|
---|
[d352805] | 203 | }
|
---|
| 204 |
|
---|
| 205 | if(!al_install_keyboard()) {
|
---|
| 206 | fprintf(stderr, "failed to initialize the keyboard!\n");
|
---|
| 207 | return -1;
|
---|
| 208 | }
|
---|
[87b3ee2] | 209 |
|
---|
| 210 | if(!al_install_mouse()) {
|
---|
| 211 | fprintf(stderr, "failed to initialize the mouse!\n");
|
---|
| 212 | return -1;
|
---|
| 213 | }
|
---|
[d352805] | 214 |
|
---|
| 215 | timer = al_create_timer(1.0 / FPS);
|
---|
| 216 | if(!timer) {
|
---|
| 217 | fprintf(stderr, "failed to create timer!\n");
|
---|
| 218 | return -1;
|
---|
| 219 | }
|
---|
| 220 |
|
---|
[1f1eb58] | 221 | int refreshRate = getRefreshRate(SCREEN_W, SCREEN_H);
|
---|
| 222 | // if the computer doesn't support this resolution, just use windowed mode
|
---|
| 223 | if (refreshRate > 0 && fullscreen) {
|
---|
| 224 | al_set_new_display_flags(ALLEGRO_FULLSCREEN);
|
---|
| 225 | al_set_new_display_refresh_rate(refreshRate);
|
---|
| 226 | }
|
---|
| 227 | display = al_create_display(SCREEN_W, SCREEN_H);
|
---|
[d352805] | 228 | if(!display) {
|
---|
| 229 | fprintf(stderr, "failed to create display!\n");
|
---|
| 230 | al_destroy_timer(timer);
|
---|
| 231 | return -1;
|
---|
| 232 | }
|
---|
[87b3ee2] | 233 |
|
---|
[b35b2b2] | 234 | debugConsole.addLine("Debug console:");
|
---|
| 235 | debugConsole.addLine("");
|
---|
| 236 |
|
---|
[b29ff6b] | 237 | createGui(font);
|
---|
[3e44a59] | 238 |
|
---|
[49da01a] | 239 | goToLoginScreen();
|
---|
[d352805] | 240 |
|
---|
| 241 | event_queue = al_create_event_queue();
|
---|
| 242 | if(!event_queue) {
|
---|
| 243 | fprintf(stderr, "failed to create event_queue!\n");
|
---|
| 244 | al_destroy_display(display);
|
---|
| 245 | al_destroy_timer(timer);
|
---|
| 246 | return -1;
|
---|
| 247 | }
|
---|
| 248 |
|
---|
| 249 | al_set_target_bitmap(al_get_backbuffer(display));
|
---|
| 250 |
|
---|
| 251 | al_register_event_source(event_queue, al_get_display_event_source(display));
|
---|
| 252 | al_register_event_source(event_queue, al_get_timer_event_source(timer));
|
---|
| 253 | al_register_event_source(event_queue, al_get_keyboard_event_source());
|
---|
[87b3ee2] | 254 | al_register_event_source(event_queue, al_get_mouse_event_source());
|
---|
[d352805] | 255 |
|
---|
| 256 | al_clear_to_color(al_map_rgb(0,0,0));
|
---|
| 257 |
|
---|
| 258 | al_flip_display();
|
---|
[9a3e6b1] | 259 |
|
---|
| 260 | if (argc != 3) {
|
---|
| 261 | cout << "Usage: server port" << endl;
|
---|
| 262 | exit(1);
|
---|
| 263 | }
|
---|
| 264 |
|
---|
| 265 | initWinSock();
|
---|
[803566d] | 266 |
|
---|
[9a3e6b1] | 267 | sock = socket(AF_INET, SOCK_DGRAM, 0);
|
---|
| 268 | if (sock < 0)
|
---|
| 269 | error("socket");
|
---|
| 270 |
|
---|
[e607c0f] | 271 | set_nonblock(sock);
|
---|
| 272 |
|
---|
[9a3e6b1] | 273 | server.sin_family = AF_INET;
|
---|
| 274 | hp = gethostbyname(argv[1]);
|
---|
[9c18cb7] | 275 | if (hp == 0)
|
---|
[9a3e6b1] | 276 | error("Unknown host");
|
---|
| 277 |
|
---|
| 278 | memcpy((char *)&server.sin_addr, (char *)hp->h_addr, hp->h_length);
|
---|
| 279 | server.sin_port = htons(atoi(argv[2]));
|
---|
| 280 |
|
---|
[68d94de] | 281 | msgProcessor = MessageProcessor(sock, &outputLog);
|
---|
| 282 |
|
---|
[d352805] | 283 | al_start_timer(timer);
|
---|
[e607c0f] | 284 |
|
---|
[883bb5d] | 285 | while (!doexit)
|
---|
[d352805] | 286 | {
|
---|
| 287 | ALLEGRO_EVENT ev;
|
---|
[0b6f9ec] | 288 |
|
---|
[d352805] | 289 | al_wait_for_event(event_queue, &ev);
|
---|
[87b3ee2] | 290 |
|
---|
| 291 | if(wndCurrent->handleEvent(ev)) {
|
---|
| 292 | // do nothing
|
---|
| 293 | }
|
---|
| 294 | else if(ev.type == ALLEGRO_EVENT_TIMER) {
|
---|
[883bb5d] | 295 | redraw = true;
|
---|
| 296 |
|
---|
| 297 | // remove any other timer events in the queue
|
---|
| 298 | while (al_peek_next_event(event_queue, &ev) && ev.type == ALLEGRO_EVENT_TIMER) {
|
---|
| 299 | al_get_next_event(event_queue, &ev);
|
---|
| 300 | }
|
---|
[d352805] | 301 | }
|
---|
| 302 | else if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
|
---|
[9a3e6b1] | 303 | doexit = true;
|
---|
[d352805] | 304 | }
|
---|
| 305 | else if(ev.type == ALLEGRO_EVENT_KEY_DOWN) {
|
---|
| 306 | }
|
---|
| 307 | else if(ev.type == ALLEGRO_EVENT_KEY_UP) {
|
---|
| 308 | switch(ev.keyboard.keycode) {
|
---|
| 309 | case ALLEGRO_KEY_ESCAPE:
|
---|
| 310 | doexit = true;
|
---|
| 311 | break;
|
---|
[4926168] | 312 | case ALLEGRO_KEY_S: // pickup an item next to you
|
---|
[e0fd377] | 313 | if (state == STATE_GAME) {
|
---|
[4926168] | 314 | msgTo.type = MSG_TYPE_PICKUP_FLAG;
|
---|
| 315 | memcpy(msgTo.buffer, &curPlayerId, 4);
|
---|
[68d94de] | 316 | msgProcessor.sendMessage(&msgTo, &server);
|
---|
[4926168] | 317 | }
|
---|
| 318 | break;
|
---|
[626e5b0] | 319 | case ALLEGRO_KEY_D: // drop the current item
|
---|
[e0fd377] | 320 | if (state == STATE_GAME) {
|
---|
[6c9bcdd] | 321 | try {
|
---|
[5c7f28d] | 322 | Player* p = mapPlayers.at(curPlayerId);
|
---|
[f66d04f] | 323 | int flagType = OBJECT_NONE;
|
---|
[626e5b0] | 324 |
|
---|
| 325 | if (p->hasBlueFlag)
|
---|
[f66d04f] | 326 | flagType = OBJECT_BLUE_FLAG;
|
---|
[626e5b0] | 327 | else if (p->hasRedFlag)
|
---|
[f66d04f] | 328 | flagType = OBJECT_RED_FLAG;
|
---|
[626e5b0] | 329 |
|
---|
[f66d04f] | 330 | if (flagType != OBJECT_NONE) {
|
---|
[626e5b0] | 331 | msgTo.type = MSG_TYPE_DROP_FLAG;
|
---|
| 332 | memcpy(msgTo.buffer, &curPlayerId, 4);
|
---|
[68d94de] | 333 | msgProcessor.sendMessage(&msgTo, &server);
|
---|
[626e5b0] | 334 | }
|
---|
[5c7f28d] | 335 | } catch (const out_of_range& ex) {}
|
---|
[626e5b0] | 336 | }
|
---|
| 337 | break;
|
---|
[d352805] | 338 | }
|
---|
| 339 | }
|
---|
[88cdae2] | 340 | else if(ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP) {
|
---|
[a0ce8a3] | 341 | if (wndCurrent == wndGame) {
|
---|
[e1f78f5] | 342 | if (ev.mouse.button == 1) { // left click
|
---|
| 343 | msgTo.type = MSG_TYPE_PLAYER_MOVE;
|
---|
[88cdae2] | 344 |
|
---|
[e1f78f5] | 345 | POSITION pos;
|
---|
| 346 | pos.x = ev.mouse.x;
|
---|
| 347 | pos.y = ev.mouse.y;
|
---|
| 348 | pos = screenToMap(pos);
|
---|
[62ee2ce] | 349 |
|
---|
[e1f78f5] | 350 | if (pos.x != -1)
|
---|
| 351 | {
|
---|
| 352 | memcpy(msgTo.buffer, &curPlayerId, 4);
|
---|
| 353 | memcpy(msgTo.buffer+4, &pos.x, 4);
|
---|
| 354 | memcpy(msgTo.buffer+8, &pos.y, 4);
|
---|
| 355 |
|
---|
[68d94de] | 356 | msgProcessor.sendMessage(&msgTo, &server);
|
---|
[e1f78f5] | 357 | }
|
---|
| 358 | else
|
---|
| 359 | cout << "Invalid point: User did not click on the map" << endl;
|
---|
| 360 | }else if (ev.mouse.button == 2) { // right click
|
---|
[b8abc90] | 361 | cout << "Detected a right-click" << endl;
|
---|
| 362 | map<unsigned int, Player*>::iterator it;
|
---|
[e1f78f5] | 363 |
|
---|
[cbc70eb] | 364 | Player* curPlayer = mapPlayers[curPlayerId];;
|
---|
[fbcfc35] | 365 |
|
---|
[b8abc90] | 366 | cout << "Got current player" << endl;
|
---|
| 367 | cout << "current game: " << game << endl;
|
---|
[e1f78f5] | 368 |
|
---|
[b8abc90] | 369 | map<unsigned int, Player*> playersInGame = game->getPlayers();
|
---|
| 370 | Player* target;
|
---|
| 371 |
|
---|
[a0ce8a3] | 372 | for (it = playersInGame.begin(); it != playersInGame.end(); it++)
|
---|
[b8abc90] | 373 | {
|
---|
| 374 | target = it->second;
|
---|
| 375 | cout << "set target" << endl;
|
---|
[e70b66b] | 376 | if (target->team != curPlayer->team)
|
---|
[e1f78f5] | 377 | {
|
---|
[b8abc90] | 378 | cout << "Found valid target" << endl;
|
---|
[88cdae2] | 379 |
|
---|
[e70b66b] | 380 | POSITION cursorPos;
|
---|
| 381 | cursorPos.x = ev.mouse.x;
|
---|
| 382 | cursorPos.y = ev.mouse.y;
|
---|
| 383 | cursorPos = screenToMap(cursorPos);
|
---|
[5b92307] | 384 |
|
---|
[e70b66b] | 385 | float distance =posDistance(cursorPos.toFloat(), target->pos);
|
---|
[b8abc90] | 386 |
|
---|
[e70b66b] | 387 | if (distance < 25) {
|
---|
| 388 | unsigned int targetId = target->getId();
|
---|
| 389 |
|
---|
| 390 | msgTo.type = MSG_TYPE_ATTACK;
|
---|
| 391 | memcpy(msgTo.buffer, &curPlayerId, 4);
|
---|
| 392 | memcpy(msgTo.buffer+4, &targetId, 4);
|
---|
| 393 |
|
---|
| 394 | msgProcessor.sendMessage(&msgTo, &server);
|
---|
| 395 | }
|
---|
[e1f78f5] | 396 | }
|
---|
[b8abc90] | 397 | }
|
---|
[62ee2ce] | 398 | }
|
---|
[ad5d122] | 399 | }
|
---|
[88cdae2] | 400 | }
|
---|
[e607c0f] | 401 |
|
---|
[68d94de] | 402 | if (msgProcessor.receiveMessage(&msgFrom, &from) >= 0)
|
---|
[6f64166] | 403 | processMessage(msgFrom, state, chatConsole, mapPlayers, mapGames, curPlayerId);
|
---|
[054b50b] | 404 |
|
---|
[a1a3bd5] | 405 | if (redraw)
|
---|
[e607c0f] | 406 | {
|
---|
[d352805] | 407 | redraw = false;
|
---|
[88cdae2] | 408 |
|
---|
[68d94de] | 409 | msgProcessor.resendUnackedMessages();
|
---|
[10f6fc2] | 410 |
|
---|
[f63aa57] | 411 | if (debugging && wndCurrent == wndLobby)
|
---|
| 412 | wndLobbyDebug->draw(display);
|
---|
[b35b2b2] | 413 | else
|
---|
| 414 | wndCurrent->draw(display);
|
---|
[9a3e6b1] | 415 |
|
---|
[50e6c7a] | 416 | if (wndCurrent == wndLobby) {
|
---|
[f63aa57] | 417 | if (!debugging)
|
---|
| 418 | chatConsole.draw(font, al_map_rgb(255,255,255));
|
---|
[53d41ea] | 419 |
|
---|
[11ad6fb] | 420 | al_draw_text(font, al_map_rgb(0, 255, 0), SCREEN_W*1/2-100, 120, ALLEGRO_ALIGN_LEFT, "Current Games");
|
---|
| 421 |
|
---|
[321fbbc] | 422 | map<string, int>::iterator it;
|
---|
[2ee386d] | 423 | int i=0;
|
---|
[11ad6fb] | 424 | ostringstream oss;
|
---|
[2ee386d] | 425 | for (it = mapGames.begin(); it != mapGames.end(); it++) {
|
---|
[11ad6fb] | 426 | oss << it->first << " (" << it->second << " players)" << endl;
|
---|
| 427 | al_draw_text(font, al_map_rgb(0, 255, 0), SCREEN_W*1/2-100, 135+i*15, ALLEGRO_ALIGN_LEFT, oss.str().c_str());
|
---|
| 428 | oss.clear();
|
---|
| 429 | oss.str("");
|
---|
| 430 | i++;
|
---|
| 431 | }
|
---|
| 432 |
|
---|
| 433 | al_draw_text(font, al_map_rgb(0, 255, 0), SCREEN_W*3/4-100, 120, ALLEGRO_ALIGN_LEFT, "Online Players");
|
---|
| 434 |
|
---|
| 435 | map<unsigned int, Player*>::iterator itPlayers;
|
---|
| 436 | i=0;
|
---|
| 437 | for (itPlayers = mapPlayers.begin(); itPlayers != mapPlayers.end(); itPlayers++) {
|
---|
| 438 | oss << itPlayers->second->name << endl;
|
---|
| 439 | al_draw_text(font, al_map_rgb(0, 255, 0), SCREEN_W*3/4-100, 135+i*15, ALLEGRO_ALIGN_LEFT, oss.str().c_str());
|
---|
| 440 | oss.clear();
|
---|
| 441 | oss.str("");
|
---|
[2ee386d] | 442 | i++;
|
---|
[50e6c7a] | 443 | }
|
---|
| 444 | }
|
---|
[fd9cdb5] | 445 | else if (wndCurrent == wndProfile)
|
---|
| 446 | {
|
---|
[b28e2bf] | 447 | ostringstream oss;
|
---|
| 448 | oss << "Honor Points: " << honorPoints << endl;
|
---|
| 449 | al_draw_text(font, al_map_rgb(0, 255, 0), 65, 90, ALLEGRO_ALIGN_LEFT, oss.str().c_str());
|
---|
| 450 | oss.clear();
|
---|
| 451 | oss.str("");
|
---|
[fd9cdb5] | 452 |
|
---|
[4c00935] | 453 | oss << "Wins: " << wins << endl;
|
---|
| 454 | al_draw_text(font, al_map_rgb(0, 255, 0), 65, 105, ALLEGRO_ALIGN_LEFT, oss.str().c_str());
|
---|
| 455 | oss.clear();
|
---|
| 456 | oss.str("");
|
---|
| 457 |
|
---|
[81c4e8a] | 458 | oss << "Losses: " << losses << endl;
|
---|
[4c00935] | 459 | al_draw_text(font, al_map_rgb(0, 255, 0), 65, 120, ALLEGRO_ALIGN_LEFT, oss.str().c_str());
|
---|
| 460 | oss.clear();
|
---|
| 461 | oss.str("");
|
---|
| 462 |
|
---|
[fd9cdb5] | 463 | // display records of the last 10 games
|
---|
[b28e2bf] | 464 | for (int i=0; i<numGames; i++) {
|
---|
| 465 |
|
---|
| 466 | if (gameHistory[i][0] == 0)
|
---|
| 467 | oss << "DEFEAT" << endl;
|
---|
| 468 | else if (gameHistory[i][0] == 1)
|
---|
| 469 | oss << "VICTORY" << endl;
|
---|
| 470 |
|
---|
[4c00935] | 471 | al_draw_text(font, al_map_rgb(0, 255, 0), 142, 190+30*(i+1), ALLEGRO_ALIGN_CENTRE, oss.str().c_str());
|
---|
[b28e2bf] | 472 | oss.clear();
|
---|
| 473 | oss.str("");
|
---|
| 474 |
|
---|
| 475 | oss << gameHistory[i][2] << endl;
|
---|
[4c00935] | 476 | al_draw_text(font, al_map_rgb(0, 255, 0), 302, 190+30*(i+1), ALLEGRO_ALIGN_CENTRE, oss.str().c_str());
|
---|
[b28e2bf] | 477 | oss.clear();
|
---|
| 478 | oss.str("");
|
---|
| 479 |
|
---|
| 480 | oss << gameHistory[i][3] << endl;
|
---|
[4c00935] | 481 | al_draw_text(font, al_map_rgb(0, 255, 0), 462, 190+30*(i+1), ALLEGRO_ALIGN_CENTRE, oss.str().c_str());
|
---|
[b28e2bf] | 482 | oss.clear();
|
---|
| 483 | oss.str("");
|
---|
| 484 |
|
---|
[ace001a] | 485 | time_t time_finished = gameHistory[i][4];
|
---|
| 486 | struct tm* now = localtime(&time_finished);
|
---|
| 487 |
|
---|
| 488 | oss << (now->tm_mon + 1) << "/" << now->tm_mday << "/" << (now->tm_year + 1900) << " ";;
|
---|
| 489 |
|
---|
| 490 | if (now->tm_hour == 0)
|
---|
| 491 | oss << "12";
|
---|
| 492 | else if (now->tm_hour <= 12)
|
---|
| 493 | oss << now->tm_hour;
|
---|
| 494 | else
|
---|
| 495 | oss << now->tm_hour-12;
|
---|
| 496 |
|
---|
| 497 | oss << ":" << setfill('0') << setw(2) << now->tm_min << setfill(' ') << " ";
|
---|
| 498 |
|
---|
| 499 | if (now->tm_hour < 12)
|
---|
| 500 | oss << "AM";
|
---|
| 501 | else
|
---|
| 502 | oss << "PM";
|
---|
| 503 |
|
---|
| 504 | oss << endl;
|
---|
| 505 |
|
---|
[4c00935] | 506 | al_draw_text(font, al_map_rgb(0, 255, 0), 622, 190+30*(i+1), ALLEGRO_ALIGN_CENTRE, oss.str().c_str());
|
---|
[b28e2bf] | 507 | oss.clear();
|
---|
| 508 | oss.str("");
|
---|
| 509 |
|
---|
[fd9cdb5] | 510 | }
|
---|
| 511 |
|
---|
| 512 | }
|
---|
[a0ce8a3] | 513 | else if (wndCurrent == wndGameLobby)
|
---|
| 514 | {
|
---|
| 515 | al_draw_text(font, al_map_rgb(0, 255, 0), 200, 100, ALLEGRO_ALIGN_LEFT, "Waiting Area");
|
---|
| 516 | al_draw_text(font, al_map_rgb(0, 255, 0), 400, 100, ALLEGRO_ALIGN_LEFT, "Blue Team");
|
---|
| 517 | al_draw_text(font, al_map_rgb(0, 255, 0), 600, 100, ALLEGRO_ALIGN_LEFT, "Red Team");
|
---|
| 518 |
|
---|
| 519 | int drawPosition = 0;
|
---|
| 520 |
|
---|
| 521 | map<unsigned int, Player*> gamePlayers = game->getPlayers();
|
---|
| 522 | map<unsigned int, Player*>::iterator itPlayers;
|
---|
| 523 | ostringstream oss;
|
---|
| 524 | int i=0;
|
---|
| 525 | for (itPlayers = gamePlayers.begin(); itPlayers != gamePlayers.end(); itPlayers++) {
|
---|
[3476207] | 526 | switch (itPlayers->second->team) {
|
---|
[7fa452f] | 527 | case 0:
|
---|
[3476207] | 528 | drawPosition = 200;
|
---|
| 529 | break;
|
---|
[7fa452f] | 530 | case 1:
|
---|
[3476207] | 531 | drawPosition = 400;
|
---|
| 532 | break;
|
---|
[7fa452f] | 533 | case 2:
|
---|
[3476207] | 534 | drawPosition = 600;
|
---|
| 535 | break;
|
---|
| 536 | }
|
---|
| 537 |
|
---|
[a0ce8a3] | 538 | oss << itPlayers->second->name << endl;
|
---|
| 539 | al_draw_text(font, al_map_rgb(0, 255, 0), drawPosition, 135+i*15, ALLEGRO_ALIGN_LEFT, oss.str().c_str());
|
---|
| 540 | oss.clear();
|
---|
| 541 | oss.str("");
|
---|
| 542 | i++;
|
---|
| 543 | }
|
---|
| 544 | }
|
---|
[3ff2bd7] | 545 | else if (wndCurrent == wndGame)
|
---|
[03ba5e3] | 546 | {
|
---|
[b4c5b6a] | 547 | al_draw_text(font, al_map_rgb(0, 255, 0), 4, 4, ALLEGRO_ALIGN_LEFT, "Players");
|
---|
| 548 |
|
---|
| 549 | map<unsigned int, Player*>& gamePlayers = game->getPlayers();
|
---|
| 550 | map<unsigned int, Player*>::iterator it;
|
---|
| 551 |
|
---|
[3ff2bd7] | 552 | if (!debugging) {
|
---|
| 553 | int playerCount = 0;
|
---|
| 554 | for (it = gamePlayers.begin(); it != gamePlayers.end(); it++)
|
---|
| 555 | {
|
---|
| 556 | al_draw_text(font, al_map_rgb(0, 255, 0), 4, 19+(playerCount+1)*15, ALLEGRO_ALIGN_LEFT, it->second->name.c_str());
|
---|
| 557 | playerCount++;
|
---|
| 558 | }
|
---|
[b4c5b6a] | 559 | }
|
---|
| 560 |
|
---|
[03ba5e3] | 561 | ostringstream ossScoreBlue, ossScoreRed;
|
---|
| 562 |
|
---|
| 563 | ossScoreBlue << "Blue: " << game->getBlueScore() << endl;
|
---|
| 564 | ossScoreRed << "Red: " << game->getRedScore() << endl;
|
---|
| 565 |
|
---|
| 566 | al_draw_text(font, al_map_rgb(0, 255, 0), 330, 80, ALLEGRO_ALIGN_LEFT, ossScoreBlue.str().c_str());
|
---|
| 567 | al_draw_text(font, al_map_rgb(0, 255, 0), 515, 80, ALLEGRO_ALIGN_LEFT, ossScoreRed.str().c_str());
|
---|
[0693e25] | 568 |
|
---|
[fef7c69] | 569 | // update players
|
---|
| 570 | for (it = game->getPlayers().begin(); it != game->getPlayers().end(); it++)
|
---|
| 571 | {
|
---|
| 572 | it->second->updateTarget(game->getPlayers());
|
---|
| 573 | }
|
---|
| 574 |
|
---|
| 575 | for (it = game->getPlayers().begin(); it != game->getPlayers().end(); it++)
|
---|
| 576 | {
|
---|
| 577 | it->second->move(game->getMap()); // ignore return value
|
---|
| 578 | }
|
---|
| 579 |
|
---|
[58ca135] | 580 | // update projectile positions
|
---|
| 581 | map<unsigned int, Projectile>::iterator it2;
|
---|
| 582 | for (it2 = game->getProjectiles().begin(); it2 != game->getProjectiles().end(); it2++)
|
---|
| 583 | {
|
---|
| 584 | it2->second.move(game->getPlayers());
|
---|
| 585 | }
|
---|
| 586 |
|
---|
[6319311] | 587 | GameRender::drawMap(game->getMap());
|
---|
| 588 | GameRender::drawPlayers(game->getPlayers(), font, curPlayerId);
|
---|
[e5697b1] | 589 | GameRender::drawProjectiles(game->getProjectiles(), game->getPlayers());
|
---|
[03ba5e3] | 590 | }
|
---|
[f63aa57] | 591 | else if (wndCurrent == wndGameSummary)
|
---|
[50e6c7a] | 592 | {
|
---|
[635ad9b] | 593 | ostringstream ossBlueScore, ossRedScore;
|
---|
| 594 |
|
---|
| 595 | ossBlueScore << "Blue Score: " << gameSummary->getBlueScore();
|
---|
| 596 | ossRedScore << "Red Score: " << gameSummary->getRedScore();
|
---|
| 597 |
|
---|
[3e44a59] | 598 | string strWinner;
|
---|
| 599 |
|
---|
| 600 | if (gameSummary->getWinner() == 0)
|
---|
[635ad9b] | 601 | strWinner = "Blue Team Wins";
|
---|
[3e44a59] | 602 | else if (gameSummary->getWinner() == 1)
|
---|
[635ad9b] | 603 | strWinner = "Red Team Wins";
|
---|
| 604 | else
|
---|
| 605 | strWinner = "winner set to wrong value";
|
---|
| 606 |
|
---|
[3e44a59] | 607 | al_draw_text(font, al_map_rgb(0, 255, 0), 512, 40, ALLEGRO_ALIGN_CENTRE, gameSummary->getName().c_str());
|
---|
[635ad9b] | 608 | al_draw_text(font, al_map_rgb(0, 255, 0), 330, 80, ALLEGRO_ALIGN_LEFT, ossBlueScore.str().c_str());
|
---|
| 609 | al_draw_text(font, al_map_rgb(0, 255, 0), 515, 80, ALLEGRO_ALIGN_LEFT, ossRedScore.str().c_str());
|
---|
[3e44a59] | 610 | al_draw_text(font, al_map_rgb(0, 255, 0), 512, 120, ALLEGRO_ALIGN_CENTRE, strWinner.c_str());
|
---|
[87b3ee2] | 611 | }
|
---|
| 612 |
|
---|
[b35b2b2] | 613 | if (debugging) {
|
---|
| 614 | drawMessageStatus(font);
|
---|
| 615 | }
|
---|
| 616 |
|
---|
[d352805] | 617 | al_flip_display();
|
---|
| 618 | }
|
---|
| 619 | }
|
---|
[9a3e6b1] | 620 |
|
---|
| 621 | #if defined WINDOWS
|
---|
| 622 | closesocket(sock);
|
---|
| 623 | #elif defined LINUX
|
---|
| 624 | close(sock);
|
---|
| 625 | #endif
|
---|
| 626 |
|
---|
| 627 | shutdownWinSock();
|
---|
[d352805] | 628 |
|
---|
[f63aa57] | 629 | // delete all components
|
---|
| 630 | for (unsigned int x=0; x<vctComponents.size(); x++)
|
---|
| 631 | delete vctComponents[x];
|
---|
| 632 |
|
---|
[87b3ee2] | 633 | delete wndLogin;
|
---|
[1785314] | 634 | delete wndRegister;
|
---|
| 635 | delete wndLobby;
|
---|
[f63aa57] | 636 | delete wndLobbyDebug;
|
---|
[a0ce8a3] | 637 | delete wndGameLobby;
|
---|
[3ff2bd7] | 638 | delete wndGame;
|
---|
[f63aa57] | 639 | delete wndGameSummary;
|
---|
[87b3ee2] | 640 |
|
---|
[eb2ad4f] | 641 | // game should be deleted when the player leaves a gamw
|
---|
[d519032] | 642 | if (game != NULL)
|
---|
| 643 | delete game;
|
---|
[62ee2ce] | 644 |
|
---|
[3e44a59] | 645 | if (gameSummary != NULL)
|
---|
| 646 | delete gameSummary;
|
---|
| 647 |
|
---|
[e6c26b8] | 648 | map<unsigned int, Player*>::iterator it;
|
---|
| 649 |
|
---|
| 650 | for (it = mapPlayers.begin(); it != mapPlayers.end(); it++) {
|
---|
| 651 | delete it->second;
|
---|
| 652 | }
|
---|
| 653 |
|
---|
[b28e2bf] | 654 | if (gameHistory != NULL) {
|
---|
| 655 | for (int i=0; i<numGames; i++) {
|
---|
| 656 | free(gameHistory[i]);
|
---|
| 657 | }
|
---|
| 658 |
|
---|
| 659 | free(gameHistory);
|
---|
| 660 | }
|
---|
| 661 |
|
---|
[d352805] | 662 | al_destroy_event_queue(event_queue);
|
---|
| 663 | al_destroy_display(display);
|
---|
| 664 | al_destroy_timer(timer);
|
---|
[8271c78] | 665 |
|
---|
| 666 | outputLog << "Stopped client on " << getCurrentDateTimeString() << endl;
|
---|
| 667 | outputLog.close();
|
---|
| 668 |
|
---|
[d352805] | 669 | return 0;
|
---|
| 670 | }
|
---|
| 671 |
|
---|
[0dde5da] | 672 | void initWinSock()
|
---|
| 673 | {
|
---|
| 674 | #if defined WINDOWS
|
---|
| 675 | WORD wVersionRequested;
|
---|
| 676 | WSADATA wsaData;
|
---|
| 677 | int wsaerr;
|
---|
| 678 |
|
---|
| 679 | wVersionRequested = MAKEWORD(2, 2);
|
---|
| 680 | wsaerr = WSAStartup(wVersionRequested, &wsaData);
|
---|
[803566d] | 681 |
|
---|
[0dde5da] | 682 | if (wsaerr != 0) {
|
---|
| 683 | cout << "The Winsock dll not found." << endl;
|
---|
| 684 | exit(1);
|
---|
| 685 | }else
|
---|
| 686 | cout << "The Winsock dll was found." << endl;
|
---|
| 687 | #endif
|
---|
| 688 | }
|
---|
| 689 |
|
---|
| 690 | void shutdownWinSock()
|
---|
| 691 | {
|
---|
| 692 | #if defined WINDOWS
|
---|
| 693 | WSACleanup();
|
---|
| 694 | #endif
|
---|
[1912323] | 695 | }
|
---|
| 696 |
|
---|
[b29ff6b] | 697 | void createGui(ALLEGRO_FONT* font) {
|
---|
[fd9cdb5] | 698 |
|
---|
[b29ff6b] | 699 | // wndLogin
|
---|
| 700 |
|
---|
| 701 | wndLogin = new Window(0, 0, SCREEN_W, SCREEN_H);
|
---|
| 702 | vctComponents.push_back(wndLogin->addComponent(new Textbox(516, 40, 100, 20, font)));
|
---|
| 703 | vctComponents.push_back(wndLogin->addComponent(new Textbox(516, 70, 100, 20, font)));
|
---|
| 704 | vctComponents.push_back(wndLogin->addComponent(new TextLabel(410, 40, 100, 20, font, "Username:", ALLEGRO_ALIGN_RIGHT)));
|
---|
| 705 | vctComponents.push_back(wndLogin->addComponent(new TextLabel(410, 70, 100, 20, font, "Password:", ALLEGRO_ALIGN_RIGHT)));
|
---|
| 706 | vctComponents.push_back(wndLogin->addComponent(new TextLabel((SCREEN_W-600)/2, 100, 600, 20, font, "", ALLEGRO_ALIGN_CENTRE)));
|
---|
| 707 | vctComponents.push_back(wndLogin->addComponent(new Button(SCREEN_W/2-100, 130, 90, 20, font, "Register", goToRegisterScreen)));
|
---|
| 708 | vctComponents.push_back(wndLogin->addComponent(new Button(SCREEN_W/2+10, 130, 90, 20, font, "Login", login)));
|
---|
| 709 | vctComponents.push_back(wndLogin->addComponent(new Button(920, 10, 80, 20, font, "Quit", quit)));
|
---|
| 710 | vctComponents.push_back(wndLogin->addComponent(new Button(20, 10, 160, 20, font, "Toggle Debugging", toggleDebugging)));
|
---|
| 711 |
|
---|
| 712 | txtUsername = (Textbox*)wndLogin->getComponent(0);
|
---|
| 713 | txtPassword = (Textbox*)wndLogin->getComponent(1);
|
---|
| 714 | lblLoginStatus = (TextLabel*)wndLogin->getComponent(4);
|
---|
| 715 |
|
---|
| 716 | cout << "Created login screen" << endl;
|
---|
| 717 |
|
---|
| 718 |
|
---|
| 719 | // wndRegister
|
---|
| 720 |
|
---|
| 721 | wndRegister = new Window(0, 0, SCREEN_W, SCREEN_H);
|
---|
| 722 | vctComponents.push_back(wndRegister->addComponent(new Textbox(516, 40, 100, 20, font)));
|
---|
| 723 | vctComponents.push_back(wndRegister->addComponent(new Textbox(516, 70, 100, 20, font)));
|
---|
| 724 | vctComponents.push_back(wndRegister->addComponent(new TextLabel(410, 40, 100, 20, font, "Username:", ALLEGRO_ALIGN_RIGHT)));
|
---|
| 725 | vctComponents.push_back(wndRegister->addComponent(new TextLabel(410, 70, 100, 20, font, "Password:", ALLEGRO_ALIGN_RIGHT)));
|
---|
| 726 | vctComponents.push_back(wndRegister->addComponent(new RadioButtonList(432, 100, "Pick a class", font)));
|
---|
| 727 | vctComponents.push_back(wndRegister->addComponent(new TextLabel((SCREEN_W-600)/2, 190, 600, 20, font, "", ALLEGRO_ALIGN_CENTRE)));
|
---|
| 728 | vctComponents.push_back(wndRegister->addComponent(new Button(SCREEN_W/2-100, 220, 90, 20, font, "Back", goToLoginScreen)));
|
---|
| 729 | vctComponents.push_back(wndRegister->addComponent(new Button(SCREEN_W/2+10, 220, 90, 20, font, "Submit", registerAccount)));
|
---|
| 730 | vctComponents.push_back(wndRegister->addComponent(new Button(920, 10, 80, 20, font, "Quit", quit)));
|
---|
| 731 | vctComponents.push_back(wndRegister->addComponent(new Button(20, 10, 160, 20, font, "Toggle Debugging", toggleDebugging)));
|
---|
| 732 |
|
---|
| 733 | txtUsernameRegister = (Textbox*)wndRegister->getComponent(0);
|
---|
| 734 | txtPasswordRegister = (Textbox*)wndRegister->getComponent(1);
|
---|
| 735 |
|
---|
| 736 | rblClasses = (RadioButtonList*)wndRegister->getComponent(4);
|
---|
| 737 | rblClasses->addRadioButton("Warrior");
|
---|
| 738 | rblClasses->addRadioButton("Ranger");
|
---|
| 739 |
|
---|
| 740 | lblRegisterStatus = (TextLabel*)wndRegister->getComponent(5);
|
---|
| 741 |
|
---|
| 742 | cout << "Created register screen" << endl;
|
---|
| 743 |
|
---|
| 744 |
|
---|
| 745 | // wndLobby
|
---|
| 746 |
|
---|
| 747 | txtJoinGame = new Textbox(SCREEN_W*1/2+15+4, 40, 100, 20, font);
|
---|
| 748 | vctComponents.push_back(txtJoinGame);
|
---|
| 749 |
|
---|
| 750 | txtCreateGame = new Textbox(SCREEN_W*3/4+4, 40, 100, 20, font);
|
---|
| 751 | vctComponents.push_back(txtCreateGame);
|
---|
| 752 |
|
---|
| 753 | wndLobby = new Window(0, 0, SCREEN_W, SCREEN_H);
|
---|
[fd9cdb5] | 754 | vctComponents.push_back(wndLobby->addComponent(new Button(920, 10, 80, 20, font, "Profile", goToProfileScreen)));
|
---|
| 755 | vctComponents.push_back(wndLobby->addComponent(new Button(920, 738, 80, 20, font, "Logout", logout)));
|
---|
[b29ff6b] | 756 | vctComponents.push_back(wndLobby->addComponent(new TextLabel(SCREEN_W*1/2+15-112, 40, 110, 20, font, "Game Name:", ALLEGRO_ALIGN_RIGHT)));
|
---|
| 757 | wndLobby->addComponent(txtJoinGame);
|
---|
| 758 | vctComponents.push_back(wndLobby->addComponent(new Button(SCREEN_W*1/2+15-100, 80, 200, 20, font, "Join Existing Game", joinGame)));
|
---|
| 759 | vctComponents.push_back(wndLobby->addComponent(new TextLabel(SCREEN_W*3/4-112, 40, 110, 20, font, "Game Name:", ALLEGRO_ALIGN_RIGHT)));
|
---|
| 760 | wndLobby->addComponent(txtCreateGame);
|
---|
| 761 | vctComponents.push_back(wndLobby->addComponent(new Button(SCREEN_W*3/4-100, 80, 200, 20, font, "Create New Game", createGame)));
|
---|
| 762 | vctComponents.push_back(wndLobby->addComponent(new Textbox(95, 40, 300, 20, font)));
|
---|
| 763 | vctComponents.push_back(wndLobby->addComponent(new Button(95, 70, 60, 20, font, "Send", sendChatMessage)));
|
---|
| 764 | vctComponents.push_back(wndLobby->addComponent(new Button(20, 10, 160, 20, font, "Toggle Debugging", toggleDebugging)));
|
---|
| 765 |
|
---|
| 766 | txtChat = (Textbox*)wndLobby->getComponent(7);
|
---|
| 767 |
|
---|
| 768 | cout << "Created lobby screen" << endl;
|
---|
| 769 |
|
---|
| 770 |
|
---|
| 771 | // wndLobbyDebug
|
---|
| 772 |
|
---|
| 773 | wndLobbyDebug = new Window(0, 0, SCREEN_W, SCREEN_H);
|
---|
[fd9cdb5] | 774 | vctComponents.push_back(wndLobbyDebug->addComponent(new Button(920, 10, 80, 20, font, "Profile", goToProfileScreen)));
|
---|
| 775 | vctComponents.push_back(wndLobbyDebug->addComponent(new Button(920, 738, 80, 20, font, "Logout", logout)));
|
---|
[b29ff6b] | 776 | vctComponents.push_back(wndLobbyDebug->addComponent(new TextLabel(SCREEN_W*1/2+15-112, 40, 110, 20, font, "Game Name:", ALLEGRO_ALIGN_RIGHT)));
|
---|
| 777 | wndLobbyDebug->addComponent(txtJoinGame);
|
---|
| 778 | vctComponents.push_back(wndLobbyDebug->addComponent(new Button(SCREEN_W*1/2+15-100, 80, 200, 20, font, "Join Existing Game", joinGame)));
|
---|
| 779 | vctComponents.push_back(wndLobbyDebug->addComponent(new TextLabel(SCREEN_W*3/4-112, 40, 110, 20, font, "Game Name:", ALLEGRO_ALIGN_RIGHT)));
|
---|
| 780 | wndLobbyDebug->addComponent(txtCreateGame);
|
---|
| 781 | vctComponents.push_back(wndLobbyDebug->addComponent(new Button(SCREEN_W*3/4-100, 80, 200, 20, font, "Create New Game", createGame)));
|
---|
| 782 | vctComponents.push_back(wndLobbyDebug->addComponent(new Button(20, 10, 160, 20, font, "Toggle Debugging", toggleDebugging)));
|
---|
| 783 |
|
---|
| 784 | cout << "Created debug lobby screen" << endl;
|
---|
| 785 |
|
---|
| 786 |
|
---|
[fd9cdb5] | 787 | // wndProfile
|
---|
| 788 |
|
---|
| 789 | wndProfile = new Window(0, 0, SCREEN_W, SCREEN_H);
|
---|
| 790 | vctComponents.push_back(wndProfile->addComponent(new TextLabel(450, 40, 124, 20, font, "Profile", ALLEGRO_ALIGN_CENTRE)));
|
---|
[4c00935] | 791 | vctComponents.push_back(wndProfile->addComponent(new TextLabel(160, 150, 124, 20, font, "Game History", ALLEGRO_ALIGN_CENTRE)));
|
---|
| 792 | vctComponents.push_back(wndProfile->addComponent(new TextLabel(600, 190, 124, 20, font, "Time", ALLEGRO_ALIGN_CENTRE)));
|
---|
| 793 | vctComponents.push_back(wndProfile->addComponent(new TextLabel(80, 190, 124, 20, font, "Result", ALLEGRO_ALIGN_CENTRE)));
|
---|
| 794 | vctComponents.push_back(wndProfile->addComponent(new TextLabel(240, 190, 124, 20, font, "Blue Score", ALLEGRO_ALIGN_CENTRE)));
|
---|
| 795 | vctComponents.push_back(wndProfile->addComponent(new TextLabel(400, 190, 124, 20, font, "Red Score", ALLEGRO_ALIGN_CENTRE)));
|
---|
| 796 | vctComponents.push_back(wndProfile->addComponent(new TextLabel(560, 190, 124, 20, font, "Time", ALLEGRO_ALIGN_CENTRE)));
|
---|
[fd9cdb5] | 797 | vctComponents.push_back(wndProfile->addComponent(new Button(920, 738, 80, 20, font, "Back", goToLobbyScreen)));
|
---|
| 798 |
|
---|
| 799 |
|
---|
[a0ce8a3] | 800 | // wndGameLobby
|
---|
| 801 |
|
---|
| 802 | wndGameLobby = new Window(0, 0, SCREEN_W, SCREEN_H);
|
---|
| 803 | vctComponents.push_back(wndGameLobby->addComponent(new Button(180, 120, 160, 300, font, "", joinWaitingArea)));
|
---|
| 804 | vctComponents.push_back(wndGameLobby->addComponent(new Button(380, 120, 160, 300, font, "", joinBlueTeam)));
|
---|
| 805 | vctComponents.push_back(wndGameLobby->addComponent(new Button(580, 120, 160, 300, font, "", joinRedTeam)));
|
---|
| 806 | vctComponents.push_back(wndGameLobby->addComponent(new Button(40, 600, 120, 20, font, "Leave Game", leaveGame)));
|
---|
| 807 | vctComponents.push_back(wndGameLobby->addComponent(new Button(800, 600, 120, 20, font, "Start Game", startGame)));
|
---|
| 808 |
|
---|
| 809 |
|
---|
[b29ff6b] | 810 | // wndGame
|
---|
| 811 |
|
---|
| 812 | wndGame = new Window(0, 0, SCREEN_W, SCREEN_H);
|
---|
| 813 | vctComponents.push_back(wndGame->addComponent(new Button(880, 10, 120, 20, font, "Leave Game", leaveGame)));
|
---|
| 814 |
|
---|
| 815 | cout << "Created new game screen" << endl;
|
---|
| 816 |
|
---|
| 817 | wndGameSummary = new Window(0, 0, SCREEN_W, SCREEN_H);
|
---|
| 818 | vctComponents.push_back(wndGameSummary->addComponent(new Button(840, 730, 160, 20, font, "Back to Lobby", closeGameSummary)));
|
---|
| 819 |
|
---|
| 820 | cout << "Created game summary screen" << endl;
|
---|
| 821 | }
|
---|
| 822 |
|
---|
[6f64166] | 823 | void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, map<unsigned int, Player*>& mapPlayers, map<string, int>& mapGames, unsigned int& curPlayerId)
|
---|
[1912323] | 824 | {
|
---|
[dfb9363] | 825 | cout << "Total players in map: " << mapPlayers.size() << endl;
|
---|
| 826 |
|
---|
[53ba300] | 827 | // this is outdated since most messages now don't contain just a text string
|
---|
[4da5aa3] | 828 | string response = string(msg.buffer);
|
---|
| 829 |
|
---|
| 830 | switch(state)
|
---|
| 831 | {
|
---|
| 832 | case STATE_START:
|
---|
| 833 | {
|
---|
[e607c0f] | 834 | cout << "In STATE_START" << endl;
|
---|
| 835 |
|
---|
[87b3ee2] | 836 | switch(msg.type)
|
---|
[4da5aa3] | 837 | {
|
---|
[87b3ee2] | 838 | case MSG_TYPE_REGISTER:
|
---|
| 839 | {
|
---|
[365e156] | 840 | lblRegisterStatus->setText(response);
|
---|
[87b3ee2] | 841 | break;
|
---|
| 842 | }
|
---|
[bc70282] | 843 | default:
|
---|
| 844 | {
|
---|
| 845 | cout << "(STATE_REGISTER) Received invalid message of type " << msg.type << endl;
|
---|
| 846 | break;
|
---|
| 847 | }
|
---|
| 848 | }
|
---|
| 849 |
|
---|
| 850 | break;
|
---|
| 851 | }
|
---|
[1785314] | 852 | case STATE_LOBBY:
|
---|
[bc70282] | 853 | {
|
---|
[e0fd377] | 854 | cout << "In STATE_LOBBY" << endl;
|
---|
[bc70282] | 855 | switch(msg.type)
|
---|
| 856 | {
|
---|
[87b3ee2] | 857 | case MSG_TYPE_LOGIN:
|
---|
| 858 | {
|
---|
| 859 | if (response.compare("Player has already logged in.") == 0)
|
---|
| 860 | {
|
---|
[bc70282] | 861 | goToLoginScreen();
|
---|
| 862 | state = STATE_START;
|
---|
| 863 |
|
---|
[365e156] | 864 | lblLoginStatus->setText(response);
|
---|
[87b3ee2] | 865 | }
|
---|
| 866 | else if (response.compare("Incorrect username or password") == 0)
|
---|
| 867 | {
|
---|
[bc70282] | 868 | goToLoginScreen();
|
---|
| 869 | state = STATE_START;
|
---|
| 870 |
|
---|
[365e156] | 871 | lblLoginStatus->setText(response);
|
---|
[87b3ee2] | 872 | }
|
---|
| 873 | else
|
---|
| 874 | {
|
---|
[1785314] | 875 | wndCurrent = wndLobby;
|
---|
[95ffe57] | 876 |
|
---|
| 877 | // this message should only be sent when a player first logs in so they know their id
|
---|
| 878 |
|
---|
| 879 | Player* p = new Player("", "");
|
---|
| 880 | p->deserialize(msg.buffer);
|
---|
[e6c26b8] | 881 |
|
---|
[5b92307] | 882 | if (mapPlayers.find(p->getId()) != mapPlayers.end())
|
---|
| 883 | delete mapPlayers[p->getId()];
|
---|
| 884 | mapPlayers[p->getId()] = p;
|
---|
| 885 | curPlayerId = p->getId();
|
---|
[a0ce8a3] | 886 | currentPlayer = mapPlayers[curPlayerId];
|
---|
[88cdae2] | 887 |
|
---|
| 888 | cout << "Got a valid login response with the player" << endl;
|
---|
[1f1eb58] | 889 | cout << "Player id: " << curPlayerId << endl;
|
---|
[95ffe57] | 890 | cout << "Player health: " << p->health << endl;
|
---|
[bc70282] | 891 | cout << "player map size: " << mapPlayers.size() << endl;
|
---|
[87b3ee2] | 892 | }
|
---|
[88cdae2] | 893 |
|
---|
[a1a3bd5] | 894 | break;
|
---|
| 895 | }
|
---|
| 896 | case MSG_TYPE_LOGOUT:
|
---|
| 897 | {
|
---|
[054b50b] | 898 | cout << "Got a logout message" << endl;
|
---|
[a1a3bd5] | 899 |
|
---|
[1e250bf] | 900 | unsigned int playerId;
|
---|
[53ba300] | 901 |
|
---|
| 902 | // Check if it's about you or another player
|
---|
| 903 | memcpy(&playerId, msg.buffer, 4);
|
---|
| 904 | response = string(msg.buffer+4);
|
---|
| 905 |
|
---|
| 906 | if (playerId == curPlayerId)
|
---|
[87b3ee2] | 907 | {
|
---|
[dfb9363] | 908 | cout << "Got logout message for self" << endl;
|
---|
| 909 |
|
---|
[53ba300] | 910 | if (response.compare("You have successfully logged out.") == 0)
|
---|
| 911 | {
|
---|
| 912 | cout << "Logged out" << endl;
|
---|
| 913 | state = STATE_START;
|
---|
| 914 | goToLoginScreen();
|
---|
| 915 | }
|
---|
| 916 |
|
---|
| 917 | // if there was an error logging out, nothing happens
|
---|
| 918 | }
|
---|
| 919 | else
|
---|
| 920 | {
|
---|
| 921 | delete mapPlayers[playerId];
|
---|
[dfb9363] | 922 | mapPlayers.erase(playerId);
|
---|
[87b3ee2] | 923 | }
|
---|
[054b50b] | 924 |
|
---|
| 925 | break;
|
---|
| 926 | }
|
---|
[eb8adb1] | 927 | case MSG_TYPE_CHAT:
|
---|
| 928 | {
|
---|
| 929 | chatConsole.addLine(response);
|
---|
[4c202e0] | 930 |
|
---|
[87b3ee2] | 931 | break;
|
---|
| 932 | }
|
---|
[fd9cdb5] | 933 | case MSG_TYPE_PROFILE:
|
---|
| 934 | {
|
---|
[b28e2bf] | 935 | memcpy(&honorPoints, msg.buffer, 4);
|
---|
[4c00935] | 936 | memcpy(&wins, msg.buffer+4, 4);
|
---|
| 937 | memcpy(&losses, msg.buffer+8, 4);
|
---|
| 938 | memcpy(&numGames, msg.buffer+12, 4);
|
---|
[b28e2bf] | 939 |
|
---|
| 940 | cout << "Got records for " << numGames << " games." << endl;
|
---|
| 941 | gameHistory = (int**)malloc(numGames*sizeof(int*));
|
---|
| 942 | for (int i=0; i<numGames; i++) {
|
---|
[ace001a] | 943 | gameHistory[i] = (int*)malloc(5*sizeof(int));
|
---|
[b28e2bf] | 944 | cout << endl << "game record " << (i+1) << endl;
|
---|
| 945 |
|
---|
[ace001a] | 946 | memcpy(&gameHistory[i][0], msg.buffer+16+i*20, 4);
|
---|
| 947 | memcpy(&gameHistory[i][1], msg.buffer+20+i*20, 4);
|
---|
| 948 | memcpy(&gameHistory[i][2], msg.buffer+24+i*20, 4);
|
---|
| 949 | memcpy(&gameHistory[i][3], msg.buffer+28+i*20, 4);
|
---|
| 950 | memcpy(&gameHistory[i][4], msg.buffer+32+i*20, 4);
|
---|
[b28e2bf] | 951 |
|
---|
| 952 | cout << "result: " << gameHistory[i][0] << endl;
|
---|
| 953 | cout << "team: " << gameHistory[i][1] << endl;
|
---|
| 954 | cout << "blue score: " << gameHistory[i][2] << endl;
|
---|
| 955 | cout << "red score: " << gameHistory[i][3] << endl;
|
---|
[ace001a] | 956 |
|
---|
| 957 | time_t time_finished = gameHistory[i][4];
|
---|
| 958 | struct tm* now = localtime(&time_finished);
|
---|
| 959 |
|
---|
| 960 | cout << "time game finished: ";
|
---|
| 961 | cout << (now->tm_year + 1900) << '-'
|
---|
| 962 | << (now->tm_mon + 1) << '-'
|
---|
| 963 | << now->tm_mday << " "
|
---|
| 964 | << now->tm_hour << ":"
|
---|
| 965 | << now->tm_min
|
---|
| 966 | << endl;
|
---|
[b28e2bf] | 967 | }
|
---|
| 968 |
|
---|
[fd9cdb5] | 969 | wndCurrent = wndProfile;
|
---|
| 970 |
|
---|
| 971 | break;
|
---|
| 972 | }
|
---|
[d519032] | 973 | case MSG_TYPE_JOIN_GAME_SUCCESS:
|
---|
| 974 | {
|
---|
| 975 | cout << "Received a JOIN_GAME_SUCCESS message" << endl;
|
---|
| 976 |
|
---|
[8aed9c0] | 977 | string gameName(msg.buffer);
|
---|
| 978 |
|
---|
| 979 | #if defined WINDOWS
|
---|
[1f6233e] | 980 | game = new Game(gameName, "../../data/map.txt", &msgProcessor);
|
---|
[8aed9c0] | 981 | #elif defined LINUX
|
---|
[1f6233e] | 982 | game = new Game(gameName, "../data/map.txt", &msgProcessor);
|
---|
[34bd549] | 983 | #elif defined MAC
|
---|
| 984 | game = new Game(gameName, "../data/map.txt", &msgProcessor);
|
---|
[8aed9c0] | 985 | #endif
|
---|
| 986 |
|
---|
[03ba5e3] | 987 | cout << "Game name: " << gameName << endl;
|
---|
[d519032] | 988 |
|
---|
[a0ce8a3] | 989 | state = STATE_GAME_LOBBY;
|
---|
| 990 | wndCurrent = wndGameLobby;
|
---|
[d519032] | 991 |
|
---|
| 992 | msgTo.type = MSG_TYPE_JOIN_GAME_ACK;
|
---|
| 993 | strcpy(msgTo.buffer, gameName.c_str());
|
---|
| 994 |
|
---|
[68d94de] | 995 | msgProcessor.sendMessage(&msgTo, &server);
|
---|
[d519032] | 996 |
|
---|
| 997 | break;
|
---|
| 998 | }
|
---|
| 999 | case MSG_TYPE_JOIN_GAME_FAILURE:
|
---|
| 1000 | {
|
---|
| 1001 | cout << "Received a JOIN_GAME_FAILURE message" << endl;
|
---|
| 1002 |
|
---|
| 1003 | break;
|
---|
| 1004 | }
|
---|
[6f64166] | 1005 | case MSG_TYPE_PLAYER:
|
---|
| 1006 | {
|
---|
| 1007 | handleMsgPlayer(msg, mapPlayers, mapGames);
|
---|
| 1008 |
|
---|
| 1009 | break;
|
---|
| 1010 | }
|
---|
| 1011 | case MSG_TYPE_GAME_INFO:
|
---|
| 1012 | {
|
---|
| 1013 | handleMsgGameInfo(msg, mapPlayers, mapGames);
|
---|
| 1014 |
|
---|
| 1015 | break;
|
---|
| 1016 | }
|
---|
[45b2750] | 1017 | default:
|
---|
| 1018 | {
|
---|
[1785314] | 1019 | cout << "(STATE_LOBBY) Received invlaid message of type " << msg.type << endl;
|
---|
[50e6c7a] | 1020 |
|
---|
[365e156] | 1021 | break;
|
---|
[45b2750] | 1022 | }
|
---|
[4da5aa3] | 1023 | }
|
---|
[eb8adb1] | 1024 |
|
---|
[4da5aa3] | 1025 | break;
|
---|
| 1026 | }
|
---|
[a0ce8a3] | 1027 | case STATE_GAME_LOBBY:
|
---|
[cf05729] | 1028 | {
|
---|
[a0ce8a3] | 1029 | cout << "(STATE_GAME_LOBBY) ";
|
---|
[cf05729] | 1030 | switch(msg.type)
|
---|
| 1031 | {
|
---|
| 1032 | case MSG_TYPE_START_GAME:
|
---|
| 1033 | {
|
---|
| 1034 | state = STATE_GAME;
|
---|
| 1035 | wndCurrent = wndGame;
|
---|
| 1036 |
|
---|
| 1037 | break;
|
---|
| 1038 | }
|
---|
| 1039 | default:
|
---|
| 1040 | {
|
---|
| 1041 | // keep these lines commented until until the correct messages are moved into the STATE_GAME_LOBBY section
|
---|
| 1042 | //cout << "Received invalid message of type " << msg.type << endl;
|
---|
| 1043 |
|
---|
| 1044 | //break;
|
---|
| 1045 | }
|
---|
| 1046 | }
|
---|
| 1047 | }
|
---|
[e0fd377] | 1048 | case STATE_GAME:
|
---|
[803566d] | 1049 | {
|
---|
[e0fd377] | 1050 | cout << "(STATE_GAME) ";
|
---|
[803566d] | 1051 | switch(msg.type)
|
---|
| 1052 | {
|
---|
[d6b5f74] | 1053 | case MSG_TYPE_SCORE:
|
---|
| 1054 | {
|
---|
| 1055 | cout << "Received SCORE message!" << endl;
|
---|
| 1056 |
|
---|
| 1057 | int blueScore;
|
---|
| 1058 | memcpy(&blueScore, msg.buffer, 4);
|
---|
| 1059 | cout << "blue score: " << blueScore << endl;
|
---|
| 1060 | game->setBlueScore(blueScore);
|
---|
| 1061 |
|
---|
| 1062 | int redScore;
|
---|
| 1063 | memcpy(&redScore, msg.buffer+4, 4);
|
---|
| 1064 | cout << "red score: " << redScore << endl;
|
---|
| 1065 | game->setRedScore(redScore);
|
---|
| 1066 |
|
---|
| 1067 | cout << "Processed SCORE message!" << endl;
|
---|
| 1068 |
|
---|
| 1069 | break;
|
---|
| 1070 | }
|
---|
[3e44a59] | 1071 | case MSG_TYPE_FINISH_GAME:
|
---|
| 1072 | {
|
---|
| 1073 | cout << "Got a finish game message" << endl;
|
---|
| 1074 | cout << "Should switch to STATE_LOBBY and show the final score" << endl;
|
---|
| 1075 |
|
---|
| 1076 | unsigned int winner, blueScore, redScore;
|
---|
[635ad9b] | 1077 | memcpy(&winner, msg.buffer, 4);
|
---|
| 1078 | memcpy(&blueScore, msg.buffer+4, 4);
|
---|
| 1079 | memcpy(&redScore, msg.buffer+8, 4);
|
---|
| 1080 |
|
---|
| 1081 | string gameName(msg.buffer+12);
|
---|
| 1082 |
|
---|
[3e44a59] | 1083 | gameSummary = new GameSummary(gameName, winner, blueScore, redScore);
|
---|
| 1084 |
|
---|
| 1085 | delete game;
|
---|
| 1086 | game = NULL;
|
---|
| 1087 | state = STATE_LOBBY;
|
---|
| 1088 | wndCurrent = wndGameSummary;
|
---|
| 1089 |
|
---|
[31b347a] | 1090 | break;
|
---|
[6012178] | 1091 | }
|
---|
[dfb9363] | 1092 | case MSG_TYPE_LOGOUT:
|
---|
[5c7f28d] | 1093 | {
|
---|
| 1094 | cout << "Got a logout message" << endl;
|
---|
| 1095 |
|
---|
[8df0c49] | 1096 | unsigned int playerId;
|
---|
[5c7f28d] | 1097 |
|
---|
| 1098 | // Check if it's about you or another player
|
---|
| 1099 | memcpy(&playerId, msg.buffer, 4);
|
---|
| 1100 | response = string(msg.buffer+4);
|
---|
| 1101 |
|
---|
| 1102 | if (playerId == curPlayerId)
|
---|
| 1103 | cout << "Received MSG_TYPE_LOGOUT for self in STATE_GAME. This shouldn't happen." << endl;
|
---|
[dfb9363] | 1104 | else {
|
---|
[5c7f28d] | 1105 | delete mapPlayers[playerId];
|
---|
[dfb9363] | 1106 | mapPlayers.erase(playerId);
|
---|
| 1107 | }
|
---|
[5c7f28d] | 1108 |
|
---|
| 1109 | break;
|
---|
| 1110 | }
|
---|
[6012178] | 1111 | case MSG_TYPE_PLAYER_JOIN_GAME:
|
---|
| 1112 | {
|
---|
| 1113 | cout << "Received MSG_TYPE_PLAYER_JOIN_GAME" << endl;
|
---|
| 1114 |
|
---|
| 1115 | Player p("", "");
|
---|
| 1116 | p.deserialize(msg.buffer);
|
---|
[5b92307] | 1117 | cout << "Deserialized player" << endl;
|
---|
[3476207] | 1118 | cout << "player team: " << p.team << endl;
|
---|
| 1119 | cout << "current player team: " << currentPlayer->team << endl;
|
---|
[6012178] | 1120 | p.timeLastUpdated = getCurrentMillis();
|
---|
| 1121 | p.isChasing = false;
|
---|
| 1122 | if (p.health <= 0)
|
---|
| 1123 | p.isDead = true;
|
---|
| 1124 | else
|
---|
| 1125 | p.isDead = false;
|
---|
| 1126 |
|
---|
[5b92307] | 1127 | if (mapPlayers.find(p.getId()) != mapPlayers.end())
|
---|
| 1128 | *(mapPlayers[p.getId()]) = p;
|
---|
[6012178] | 1129 | else
|
---|
[5b92307] | 1130 | mapPlayers[p.getId()] = new Player(p);
|
---|
[b4c5b6a] | 1131 |
|
---|
[306758e] | 1132 | game->addPlayer(mapPlayers[p.getId()]);
|
---|
[b4c5b6a] | 1133 |
|
---|
| 1134 | break;
|
---|
| 1135 | }
|
---|
[cd80d63] | 1136 | case MSG_TYPE_LEAVE_GAME:
|
---|
| 1137 | {
|
---|
| 1138 | cout << "Received a LEAVE_GAME message" << endl;
|
---|
| 1139 |
|
---|
| 1140 | string gameName(msg.buffer+4);
|
---|
| 1141 | unsigned int playerId;
|
---|
| 1142 |
|
---|
| 1143 | memcpy(&playerId, msg.buffer, 4);
|
---|
| 1144 |
|
---|
| 1145 | game->removePlayer(playerId);
|
---|
| 1146 |
|
---|
| 1147 | break;
|
---|
| 1148 | }
|
---|
[fef7c69] | 1149 | case MSG_TYPE_PLAYER_MOVE:
|
---|
| 1150 | {
|
---|
| 1151 | cout << "Received PLAYER_MOVE message" << endl;
|
---|
| 1152 |
|
---|
| 1153 | unsigned int id;
|
---|
| 1154 | int x, y;
|
---|
| 1155 |
|
---|
| 1156 | memcpy(&id, msg.buffer, 4);
|
---|
| 1157 | memcpy(&x, msg.buffer+4, 4);
|
---|
| 1158 | memcpy(&y, msg.buffer+8, 4);
|
---|
| 1159 |
|
---|
| 1160 | cout << "id: " << id << endl;
|
---|
| 1161 |
|
---|
| 1162 | mapPlayers[id]->target.x = x;
|
---|
| 1163 | mapPlayers[id]->target.y = y;
|
---|
| 1164 |
|
---|
[1ee0ffa] | 1165 | mapPlayers[id]->isChasing = false;
|
---|
| 1166 | mapPlayers[id]->setTargetPlayer(0);
|
---|
| 1167 |
|
---|
[fef7c69] | 1168 | break;
|
---|
| 1169 | }
|
---|
[803566d] | 1170 | case MSG_TYPE_OBJECT:
|
---|
| 1171 | {
|
---|
[e0fd377] | 1172 | cout << "Received object message in STATE_GAME" << endl;
|
---|
[803566d] | 1173 |
|
---|
[f66d04f] | 1174 | WorldMap::Object o(0, OBJECT_NONE, 0, 0);
|
---|
[803566d] | 1175 | o.deserialize(msg.buffer);
|
---|
| 1176 | cout << "object id: " << o.id << endl;
|
---|
| 1177 | game->getMap()->updateObject(o.id, o.type, o.pos.x, o.pos.y);
|
---|
| 1178 |
|
---|
| 1179 | break;
|
---|
| 1180 | }
|
---|
| 1181 | case MSG_TYPE_REMOVE_OBJECT:
|
---|
| 1182 | {
|
---|
[d519032] | 1183 | cout << "Received REMOVE_OBJECT message!" << endl;
|
---|
[803566d] | 1184 |
|
---|
| 1185 | int id;
|
---|
| 1186 | memcpy(&id, msg.buffer, 4);
|
---|
| 1187 |
|
---|
| 1188 | cout << "Removing object with id " << id << endl;
|
---|
| 1189 |
|
---|
| 1190 | if (!game->getMap()->removeObject(id))
|
---|
| 1191 | cout << "Did not remove the object" << endl;
|
---|
| 1192 |
|
---|
| 1193 | break;
|
---|
| 1194 | }
|
---|
[b8abc90] | 1195 | case MSG_TYPE_ATTACK:
|
---|
| 1196 | {
|
---|
| 1197 | cout << "Received START_ATTACK message" << endl;
|
---|
| 1198 |
|
---|
| 1199 | unsigned int id, targetId;
|
---|
| 1200 | memcpy(&id, msg.buffer, 4);
|
---|
| 1201 | memcpy(&targetId, msg.buffer+4, 4);
|
---|
| 1202 |
|
---|
| 1203 | cout << "source id: " << id << endl;
|
---|
| 1204 | cout << "target id: " << targetId << endl;
|
---|
| 1205 |
|
---|
| 1206 | // need to check the target exists in the current game
|
---|
| 1207 | Player* source = game->getPlayers()[id];
|
---|
[5b92307] | 1208 | source->setTargetPlayer(targetId);
|
---|
[b8abc90] | 1209 | source->isChasing = true;
|
---|
| 1210 |
|
---|
| 1211 | break;
|
---|
| 1212 | }
|
---|
[58ca135] | 1213 | case MSG_TYPE_PROJECTILE:
|
---|
| 1214 | {
|
---|
| 1215 | cout << "Received a PROJECTILE message" << endl;
|
---|
| 1216 |
|
---|
| 1217 | unsigned int projId, x, y, targetId;
|
---|
| 1218 |
|
---|
| 1219 | memcpy(&projId, msg.buffer, 4);
|
---|
| 1220 | memcpy(&x, msg.buffer+4, 4);
|
---|
| 1221 | memcpy(&y, msg.buffer+8, 4);
|
---|
| 1222 | memcpy(&targetId, msg.buffer+12, 4);
|
---|
| 1223 |
|
---|
| 1224 | cout << "projId: " << projId << endl;
|
---|
| 1225 | cout << "x: " << x << endl;
|
---|
| 1226 | cout << "y: " << y << endl;
|
---|
| 1227 | cout << "Target: " << targetId << endl;
|
---|
| 1228 |
|
---|
| 1229 | Projectile proj(x, y, targetId, 0);
|
---|
| 1230 | proj.setId(projId);
|
---|
| 1231 |
|
---|
| 1232 | game->addProjectile(proj);
|
---|
| 1233 |
|
---|
| 1234 | break;
|
---|
| 1235 | }
|
---|
| 1236 | case MSG_TYPE_REMOVE_PROJECTILE:
|
---|
| 1237 | {
|
---|
| 1238 | cout << "Received a REMOVE_PROJECTILE message" << endl;
|
---|
| 1239 |
|
---|
| 1240 | unsigned int id;
|
---|
| 1241 | memcpy(&id, msg.buffer, 4);
|
---|
| 1242 |
|
---|
| 1243 | game->removeProjectile(id);
|
---|
| 1244 |
|
---|
| 1245 | break;
|
---|
| 1246 | }
|
---|
[6f64166] | 1247 | case MSG_TYPE_PLAYER:
|
---|
| 1248 | {
|
---|
| 1249 | handleMsgPlayer(msg, mapPlayers, mapGames);
|
---|
| 1250 |
|
---|
| 1251 | break;
|
---|
| 1252 | }
|
---|
| 1253 | case MSG_TYPE_GAME_INFO:
|
---|
| 1254 | {
|
---|
| 1255 | handleMsgGameInfo(msg, mapPlayers, mapGames);
|
---|
| 1256 |
|
---|
| 1257 | break;
|
---|
| 1258 | }
|
---|
[803566d] | 1259 | default:
|
---|
| 1260 | {
|
---|
[d519032] | 1261 | cout << "Received invalid message of type " << msg.type << endl;
|
---|
[803566d] | 1262 |
|
---|
| 1263 | break;
|
---|
| 1264 | }
|
---|
| 1265 | }
|
---|
| 1266 |
|
---|
| 1267 | break;
|
---|
| 1268 | }
|
---|
[4da5aa3] | 1269 | default:
|
---|
| 1270 | {
|
---|
| 1271 | cout << "The state has an invalid value: " << state << endl;
|
---|
| 1272 |
|
---|
| 1273 | break;
|
---|
| 1274 | }
|
---|
| 1275 | }
|
---|
[0dde5da] | 1276 | }
|
---|
[87b3ee2] | 1277 |
|
---|
[929b4e0] | 1278 | int getRefreshRate(int width, int height)
|
---|
| 1279 | {
|
---|
| 1280 | int numRefreshRates = al_get_num_display_modes();
|
---|
| 1281 | ALLEGRO_DISPLAY_MODE displayMode;
|
---|
| 1282 |
|
---|
| 1283 | for(int i=0; i<numRefreshRates; i++) {
|
---|
| 1284 | al_get_display_mode(i, &displayMode);
|
---|
| 1285 |
|
---|
| 1286 | if (displayMode.width == width && displayMode.height == height)
|
---|
| 1287 | return displayMode.refresh_rate;
|
---|
| 1288 | }
|
---|
| 1289 |
|
---|
| 1290 | return 0;
|
---|
| 1291 | }
|
---|
| 1292 |
|
---|
| 1293 | void drawMessageStatus(ALLEGRO_FONT* font)
|
---|
| 1294 | {
|
---|
| 1295 | int clientMsgOffset = 5;
|
---|
| 1296 | int serverMsgOffset = 950;
|
---|
| 1297 |
|
---|
| 1298 | al_draw_text(font, al_map_rgb(0, 255, 255), 0+clientMsgOffset, 43, ALLEGRO_ALIGN_LEFT, "ID");
|
---|
| 1299 | al_draw_text(font, al_map_rgb(0, 255, 255), 20+clientMsgOffset, 43, ALLEGRO_ALIGN_LEFT, "Type");
|
---|
| 1300 | al_draw_text(font, al_map_rgb(0, 255, 255), 240+clientMsgOffset, 43, ALLEGRO_ALIGN_LEFT, "Acked?");
|
---|
| 1301 |
|
---|
[3ff2bd7] | 1302 | //al_draw_text(font, al_map_rgb(0, 255, 255), serverMsgOffset, 43, ALLEGRO_ALIGN_LEFT, "ID");
|
---|
[929b4e0] | 1303 |
|
---|
| 1304 | map<unsigned int, map<unsigned long, MessageContainer> >& sentMessages = msgProcessor.getSentMessages();
|
---|
| 1305 | int id, type;
|
---|
| 1306 | bool acked;
|
---|
| 1307 | ostringstream ossId, ossAcked;
|
---|
| 1308 |
|
---|
| 1309 | map<unsigned int, map<unsigned long, MessageContainer> >::iterator it;
|
---|
| 1310 |
|
---|
| 1311 | int msgCount = 0;
|
---|
| 1312 | for (it = sentMessages.begin(); it != sentMessages.end(); it++) {
|
---|
| 1313 | map<unsigned long, MessageContainer> playerMessage = it->second;
|
---|
| 1314 | map<unsigned long, MessageContainer>::iterator it2;
|
---|
| 1315 | for (it2 = playerMessage.begin(); it2 != playerMessage.end(); it2++) {
|
---|
| 1316 |
|
---|
| 1317 | id = it->first;
|
---|
| 1318 | ossId.str("");;
|
---|
| 1319 | ossId << id;
|
---|
| 1320 |
|
---|
| 1321 | type = it2->second.getMessage()->type;
|
---|
| 1322 | string typeStr = MessageContainer::getMsgTypeString(type);
|
---|
| 1323 |
|
---|
| 1324 | acked = it2->second.getAcked();
|
---|
| 1325 | ossAcked.str("");;
|
---|
| 1326 | ossAcked << boolalpha << acked;
|
---|
| 1327 |
|
---|
| 1328 | al_draw_text(font, al_map_rgb(0, 255, 0), clientMsgOffset, 60+15*msgCount, ALLEGRO_ALIGN_LEFT, ossId.str().c_str());
|
---|
| 1329 | al_draw_text(font, al_map_rgb(0, 255, 0), 20+clientMsgOffset, 60+15*msgCount, ALLEGRO_ALIGN_LEFT, typeStr.c_str());
|
---|
| 1330 | al_draw_text(font, al_map_rgb(0, 255, 0), 240+clientMsgOffset, 60+15*msgCount, ALLEGRO_ALIGN_LEFT, ossAcked.str().c_str());
|
---|
| 1331 |
|
---|
| 1332 | msgCount++;
|
---|
| 1333 | }
|
---|
| 1334 | }
|
---|
| 1335 |
|
---|
| 1336 | if (msgProcessor.getAckedMessages().size() > 0) {
|
---|
| 1337 | map<unsigned int, unsigned long long> ackedMessages = msgProcessor.getAckedMessages()[0];
|
---|
| 1338 | map<unsigned int, unsigned long long>::iterator it3;
|
---|
| 1339 |
|
---|
| 1340 | msgCount = 0;
|
---|
| 1341 | for (it3 = ackedMessages.begin(); it3 != ackedMessages.end(); it3++) {
|
---|
| 1342 | ossId.str("");;
|
---|
| 1343 | ossId << it3->first;
|
---|
| 1344 |
|
---|
| 1345 | al_draw_text(font, al_map_rgb(255, 0, 0), 25+serverMsgOffset, 60+15*msgCount, ALLEGRO_ALIGN_LEFT, ossId.str().c_str());
|
---|
| 1346 |
|
---|
| 1347 | msgCount++;
|
---|
| 1348 | }
|
---|
| 1349 | }
|
---|
| 1350 | }
|
---|
| 1351 |
|
---|
[6f64166] | 1352 | // message handling functions
|
---|
| 1353 |
|
---|
| 1354 | void handleMsgPlayer(NETWORK_MSG &msg, map<unsigned int, Player*>& mapPlayers, map<string, int>& mapGames) {
|
---|
| 1355 | cout << "Received MSG_TYPE_PLAYER" << endl;
|
---|
| 1356 |
|
---|
| 1357 | Player p("", "");
|
---|
| 1358 | p.deserialize(msg.buffer);
|
---|
| 1359 | p.timeLastUpdated = getCurrentMillis();
|
---|
| 1360 | p.isChasing = false;
|
---|
| 1361 | if (p.health <= 0)
|
---|
| 1362 | p.isDead = true;
|
---|
| 1363 | else
|
---|
| 1364 | p.isDead = false;
|
---|
| 1365 |
|
---|
| 1366 | if (mapPlayers.find(p.getId()) != mapPlayers.end())
|
---|
| 1367 | *(mapPlayers[p.getId()]) = p;
|
---|
| 1368 | else
|
---|
| 1369 | mapPlayers[p.getId()] = new Player(p);
|
---|
| 1370 | }
|
---|
| 1371 |
|
---|
| 1372 | void handleMsgGameInfo(NETWORK_MSG &msg, map<unsigned int, Player*>& mapPlayers, map<string, int>& mapGames) {
|
---|
| 1373 | cout << "Received a GAME_INFO message" << endl;
|
---|
| 1374 |
|
---|
| 1375 | string gameName(msg.buffer+4);
|
---|
| 1376 | int numPlayers;
|
---|
| 1377 |
|
---|
| 1378 | memcpy(&numPlayers, msg.buffer, 4);
|
---|
| 1379 |
|
---|
| 1380 | cout << "Received game info for " << gameName << " (num players: " << numPlayers << ")" << endl;
|
---|
| 1381 |
|
---|
| 1382 | if (numPlayers > 0)
|
---|
| 1383 | mapGames[gameName] = numPlayers;
|
---|
| 1384 | else
|
---|
| 1385 | mapGames.erase(gameName);
|
---|
| 1386 | }
|
---|
| 1387 |
|
---|
[929b4e0] | 1388 | // Callback definitions
|
---|
| 1389 |
|
---|
[5c95436] | 1390 | void goToRegisterScreen()
|
---|
| 1391 | {
|
---|
| 1392 | txtUsernameRegister->clear();
|
---|
| 1393 | txtPasswordRegister->clear();
|
---|
[49da01a] | 1394 | lblRegisterStatus->setText("");
|
---|
| 1395 | rblClasses->setSelectedButton(-1);
|
---|
| 1396 |
|
---|
| 1397 | wndCurrent = wndRegister;
|
---|
[5c95436] | 1398 | }
|
---|
| 1399 |
|
---|
| 1400 | void goToLoginScreen()
|
---|
[87b3ee2] | 1401 | {
|
---|
| 1402 | txtUsername->clear();
|
---|
| 1403 | txtPassword->clear();
|
---|
[49da01a] | 1404 | lblLoginStatus->setText("");
|
---|
| 1405 |
|
---|
| 1406 | wndCurrent = wndLogin;
|
---|
[5c95436] | 1407 | }
|
---|
| 1408 |
|
---|
[bc70282] | 1409 | // maybe need a goToGameScreen function as well and add state changes to these functions as well
|
---|
| 1410 |
|
---|
[5c95436] | 1411 | void registerAccount()
|
---|
| 1412 | {
|
---|
| 1413 | string username = txtUsernameRegister->getStr();
|
---|
| 1414 | string password = txtPasswordRegister->getStr();
|
---|
| 1415 |
|
---|
| 1416 | txtUsernameRegister->clear();
|
---|
| 1417 | txtPasswordRegister->clear();
|
---|
| 1418 | // maybe clear rblClasses as well (add a method to RadioButtonList to enable this)
|
---|
| 1419 |
|
---|
| 1420 | Player::PlayerClass playerClass;
|
---|
| 1421 |
|
---|
| 1422 | switch (rblClasses->getSelectedButton()) {
|
---|
| 1423 | case 0:
|
---|
| 1424 | playerClass = Player::CLASS_WARRIOR;
|
---|
| 1425 | break;
|
---|
| 1426 | case 1:
|
---|
| 1427 | playerClass = Player::CLASS_RANGER;
|
---|
| 1428 | break;
|
---|
| 1429 | default:
|
---|
| 1430 | cout << "Invalid class selection" << endl;
|
---|
| 1431 | playerClass = Player::CLASS_NONE;
|
---|
| 1432 | break;
|
---|
| 1433 | }
|
---|
[87b3ee2] | 1434 |
|
---|
| 1435 | msgTo.type = MSG_TYPE_REGISTER;
|
---|
| 1436 |
|
---|
| 1437 | strcpy(msgTo.buffer, username.c_str());
|
---|
| 1438 | strcpy(msgTo.buffer+username.size()+1, password.c_str());
|
---|
[5c95436] | 1439 | memcpy(msgTo.buffer+username.size()+password.size()+2, &playerClass, 4);
|
---|
[87b3ee2] | 1440 |
|
---|
[68d94de] | 1441 | msgProcessor.sendMessage(&msgTo, &server);
|
---|
[87b3ee2] | 1442 | }
|
---|
| 1443 |
|
---|
| 1444 | void login()
|
---|
| 1445 | {
|
---|
| 1446 | string strUsername = txtUsername->getStr();
|
---|
| 1447 | string strPassword = txtPassword->getStr();
|
---|
| 1448 | username = strUsername;
|
---|
| 1449 |
|
---|
| 1450 | txtUsername->clear();
|
---|
| 1451 | txtPassword->clear();
|
---|
| 1452 |
|
---|
| 1453 | msgTo.type = MSG_TYPE_LOGIN;
|
---|
| 1454 |
|
---|
| 1455 | strcpy(msgTo.buffer, strUsername.c_str());
|
---|
| 1456 | strcpy(msgTo.buffer+username.size()+1, strPassword.c_str());
|
---|
| 1457 |
|
---|
[68d94de] | 1458 | msgProcessor.sendMessage(&msgTo, &server);
|
---|
[bc70282] | 1459 |
|
---|
[1785314] | 1460 | state = STATE_LOBBY;
|
---|
[87b3ee2] | 1461 | }
|
---|
| 1462 |
|
---|
| 1463 | void logout()
|
---|
| 1464 | {
|
---|
[929b4e0] | 1465 | switch(state) {
|
---|
| 1466 | case STATE_LOBBY:
|
---|
| 1467 | txtJoinGame->clear();
|
---|
| 1468 | txtCreateGame->clear();
|
---|
| 1469 | break;
|
---|
| 1470 | default:
|
---|
| 1471 | cout << "Logout called from invalid state: " << state << endl;
|
---|
| 1472 | break;
|
---|
| 1473 | }
|
---|
[87b3ee2] | 1474 |
|
---|
| 1475 | msgTo.type = MSG_TYPE_LOGOUT;
|
---|
| 1476 |
|
---|
| 1477 | strcpy(msgTo.buffer, username.c_str());
|
---|
| 1478 |
|
---|
[68d94de] | 1479 | msgProcessor.sendMessage(&msgTo, &server);
|
---|
[87b3ee2] | 1480 | }
|
---|
| 1481 |
|
---|
| 1482 | void quit()
|
---|
| 1483 | {
|
---|
| 1484 | doexit = true;
|
---|
| 1485 | }
|
---|
| 1486 |
|
---|
| 1487 | void sendChatMessage()
|
---|
| 1488 | {
|
---|
| 1489 | string msg = txtChat->getStr();
|
---|
| 1490 | txtChat->clear();
|
---|
| 1491 |
|
---|
| 1492 | msgTo.type = MSG_TYPE_CHAT;
|
---|
| 1493 | strcpy(msgTo.buffer, msg.c_str());
|
---|
| 1494 |
|
---|
[68d94de] | 1495 | msgProcessor.sendMessage(&msgTo, &server);
|
---|
[87b3ee2] | 1496 | }
|
---|
[1f1eb58] | 1497 |
|
---|
[b35b2b2] | 1498 | void toggleDebugging()
|
---|
| 1499 | {
|
---|
| 1500 | debugging = !debugging;
|
---|
| 1501 | }
|
---|
| 1502 |
|
---|
[fd9cdb5] | 1503 | void goToProfileScreen()
|
---|
| 1504 | {
|
---|
| 1505 | msgTo.type = MSG_TYPE_PROFILE;
|
---|
| 1506 |
|
---|
[4c00935] | 1507 | unsigned int playerId = currentPlayer->getId();
|
---|
| 1508 | memcpy(msgTo.buffer, &playerId, 4);
|
---|
[fd9cdb5] | 1509 | msgProcessor.sendMessage(&msgTo, &server);
|
---|
| 1510 | }
|
---|
| 1511 |
|
---|
| 1512 | void goToLobbyScreen()
|
---|
| 1513 | {
|
---|
| 1514 | wndCurrent = wndLobby;
|
---|
| 1515 | }
|
---|
| 1516 |
|
---|
[929b4e0] | 1517 | void joinGame()
|
---|
[b35b2b2] | 1518 | {
|
---|
[929b4e0] | 1519 | cout << "Joining game" << endl;
|
---|
[bbebe9c] | 1520 |
|
---|
| 1521 | string msg = txtJoinGame->getStr();
|
---|
| 1522 | txtJoinGame->clear();
|
---|
| 1523 |
|
---|
| 1524 | msgTo.type = MSG_TYPE_JOIN_GAME;
|
---|
| 1525 | strcpy(msgTo.buffer, msg.c_str());
|
---|
| 1526 |
|
---|
[68d94de] | 1527 | msgProcessor.sendMessage(&msgTo, &server);
|
---|
[dee75cc] | 1528 | }
|
---|
[b35b2b2] | 1529 |
|
---|
[929b4e0] | 1530 | void createGame()
|
---|
[b35b2b2] | 1531 | {
|
---|
[929b4e0] | 1532 | cout << "Creating game" << endl;
|
---|
[bbebe9c] | 1533 |
|
---|
| 1534 | string msg = txtCreateGame->getStr();
|
---|
| 1535 | txtCreateGame->clear();
|
---|
| 1536 |
|
---|
[d519032] | 1537 | cout << "Sending message: " << msg.c_str() << endl;
|
---|
| 1538 |
|
---|
[bbebe9c] | 1539 | msgTo.type = MSG_TYPE_CREATE_GAME;
|
---|
| 1540 | strcpy(msgTo.buffer, msg.c_str());
|
---|
| 1541 |
|
---|
[68d94de] | 1542 | msgProcessor.sendMessage(&msgTo, &server);
|
---|
[34bd549] | 1543 | cout << "Sent CREATE_GAME message" << endl;
|
---|
[03ba5e3] | 1544 | }
|
---|
| 1545 |
|
---|
[a0ce8a3] | 1546 | void joinWaitingArea() {
|
---|
| 1547 | cout << "joining waiting area" << endl;
|
---|
[85da778] | 1548 | currentPlayer->team = Player::TEAM_NONE;
|
---|
[3476207] | 1549 |
|
---|
| 1550 | msgTo.type = MSG_TYPE_JOIN_TEAM;
|
---|
| 1551 | memcpy(msgTo.buffer, &(currentPlayer->team), 4);
|
---|
| 1552 |
|
---|
| 1553 | msgProcessor.sendMessage(&msgTo, &server);
|
---|
[a0ce8a3] | 1554 | }
|
---|
| 1555 |
|
---|
| 1556 | void joinBlueTeam() {
|
---|
| 1557 | cout << "joining blue team" << endl;
|
---|
[85da778] | 1558 | currentPlayer->team = Player::TEAM_BLUE;
|
---|
[3476207] | 1559 |
|
---|
| 1560 | msgTo.type = MSG_TYPE_JOIN_TEAM;
|
---|
| 1561 | memcpy(msgTo.buffer, &(currentPlayer->team), 4);
|
---|
| 1562 |
|
---|
| 1563 | msgProcessor.sendMessage(&msgTo, &server);
|
---|
[a0ce8a3] | 1564 | }
|
---|
| 1565 |
|
---|
| 1566 | void joinRedTeam() {
|
---|
| 1567 | cout << "joining red team" << endl;
|
---|
[85da778] | 1568 | currentPlayer->team = Player::TEAM_RED;
|
---|
[3476207] | 1569 |
|
---|
| 1570 | msgTo.type = MSG_TYPE_JOIN_TEAM;
|
---|
| 1571 | memcpy(msgTo.buffer, &(currentPlayer->team), 4);
|
---|
| 1572 |
|
---|
| 1573 | msgProcessor.sendMessage(&msgTo, &server);
|
---|
[a0ce8a3] | 1574 | }
|
---|
| 1575 |
|
---|
| 1576 | void startGame() {
|
---|
[cf05729] | 1577 | msgTo.type = MSG_TYPE_START_GAME;
|
---|
[cb5a021] | 1578 |
|
---|
| 1579 | msgProcessor.sendMessage(&msgTo, &server);
|
---|
[a0ce8a3] | 1580 | }
|
---|
| 1581 |
|
---|
[03ba5e3] | 1582 | void leaveGame()
|
---|
| 1583 | {
|
---|
| 1584 | cout << "Leaving game" << endl;
|
---|
| 1585 |
|
---|
[8826eed] | 1586 | delete game;
|
---|
[03ba5e3] | 1587 | game = NULL;
|
---|
| 1588 |
|
---|
| 1589 | state = STATE_LOBBY;
|
---|
| 1590 | wndCurrent = wndLobby;
|
---|
| 1591 |
|
---|
| 1592 | msgTo.type = MSG_TYPE_LEAVE_GAME;
|
---|
| 1593 |
|
---|
[68d94de] | 1594 | msgProcessor.sendMessage(&msgTo, &server);
|
---|
[95ffe57] | 1595 | }
|
---|
[3e44a59] | 1596 |
|
---|
| 1597 | void closeGameSummary()
|
---|
| 1598 | {
|
---|
| 1599 | delete gameSummary;
|
---|
[635ad9b] | 1600 | gameSummary = NULL;
|
---|
[3e44a59] | 1601 | wndCurrent = wndLobby;
|
---|
[635ad9b] | 1602 | cout << "Processed button actions" << endl;
|
---|
[8aed9c0] | 1603 | }
|
---|