Changeset a0ce8a3 in network-game for client/Client/main.cpp
- Timestamp:
- Jun 30, 2014, 11:51:12 PM (10 years ago)
- Branches:
- master
- Children:
- ea17281
- Parents:
- e708305
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
client/Client/main.cpp
re708305 ra0ce8a3 77 77 void sendChatMessage(); 78 78 void toggleDebugging(); 79 void joinGame(); 80 void createGame(); 79 void joinGame(); // for joining the game lobby 80 void createGame(); // for joining the game lobby 81 void joinWaitingArea(); 82 void joinRedTeam(); 83 void joinBlueTeam(); 84 void startGame(); // for leaving game lobby and starting the actual game 81 85 void leaveGame(); 82 86 void closeGameSummary(); … … 89 93 STATE_START, 90 94 STATE_LOBBY, 95 STATE_GAME_LOBBY, 91 96 STATE_GAME 92 97 }; … … 102 107 Window* wndLobby; 103 108 Window* wndLobbyDebug; 109 Window* wndGameLobby; 104 110 Window* wndGame; 105 111 Window* wndGameSummary; … … 131 137 Game* game; 132 138 GameSummary* gameSummary; 139 Player* currentPlayer; 133 140 134 141 MessageProcessor msgProcessor; … … 320 327 } 321 328 else if(ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP) { 322 if (wndCurrent == wndGame) {329 if (wndCurrent == wndGame) { 323 330 if (ev.mouse.button == 1) { // left click 324 331 msgTo.type = MSG_TYPE_PLAYER_MOVE; … … 351 358 Player* target; 352 359 353 for (it = playersInGame.begin(); it != playersInGame.end(); it++)360 for (it = playersInGame.begin(); it != playersInGame.end(); it++) 354 361 { 355 362 target = it->second; … … 424 431 } 425 432 } 433 else if (wndCurrent == wndGameLobby) 434 { 435 al_draw_text(font, al_map_rgb(0, 255, 0), 200, 100, ALLEGRO_ALIGN_LEFT, "Waiting Area"); 436 al_draw_text(font, al_map_rgb(0, 255, 0), 400, 100, ALLEGRO_ALIGN_LEFT, "Blue Team"); 437 al_draw_text(font, al_map_rgb(0, 255, 0), 600, 100, ALLEGRO_ALIGN_LEFT, "Red Team"); 438 439 int drawPosition = 0; 440 441 switch (currentPlayer->team) { 442 case -1: 443 drawPosition = 200; 444 break; 445 case 0: 446 drawPosition = 400; 447 break; 448 case 1: 449 drawPosition = 600; 450 break; 451 } 452 453 map<unsigned int, Player*> gamePlayers = game->getPlayers(); 454 map<unsigned int, Player*>::iterator itPlayers; 455 ostringstream oss; 456 int i=0; 457 for (itPlayers = gamePlayers.begin(); itPlayers != gamePlayers.end(); itPlayers++) { 458 oss << itPlayers->second->name << endl; 459 al_draw_text(font, al_map_rgb(0, 255, 0), drawPosition, 135+i*15, ALLEGRO_ALIGN_LEFT, oss.str().c_str()); 460 oss.clear(); 461 oss.str(""); 462 i++; 463 } 464 } 426 465 else if (wndCurrent == wndGame) 427 466 { … … 516 555 delete wndLobby; 517 556 delete wndLobbyDebug; 557 delete wndGameLobby; 518 558 delete wndGame; 519 559 delete wndGameSummary; … … 654 694 655 695 696 // wndGameLobby 697 698 wndGameLobby = new Window(0, 0, SCREEN_W, SCREEN_H); 699 vctComponents.push_back(wndGameLobby->addComponent(new Button(180, 120, 160, 300, font, "", joinWaitingArea))); 700 vctComponents.push_back(wndGameLobby->addComponent(new Button(380, 120, 160, 300, font, "", joinBlueTeam))); 701 vctComponents.push_back(wndGameLobby->addComponent(new Button(580, 120, 160, 300, font, "", joinRedTeam))); 702 vctComponents.push_back(wndGameLobby->addComponent(new Button(40, 600, 120, 20, font, "Leave Game", leaveGame))); 703 vctComponents.push_back(wndGameLobby->addComponent(new Button(800, 600, 120, 20, font, "Start Game", startGame))); 704 705 656 706 // wndGame 657 707 … … 730 780 mapPlayers[p->getId()] = p; 731 781 curPlayerId = p->getId(); 782 currentPlayer = mapPlayers[curPlayerId]; 732 783 733 784 cout << "Got a valid login response with the player" << endl; … … 792 843 cout << "Game name: " << gameName << endl; 793 844 794 state = STATE_GAME; 795 wndCurrent = wndGame; 845 state = STATE_GAME_LOBBY; 846 wndCurrent = wndGameLobby; 847 mapPlayers[curPlayerId]->team = -1; 796 848 797 849 msgTo.type = MSG_TYPE_JOIN_GAME_ACK; … … 830 882 break; 831 883 } 884 case STATE_GAME_LOBBY: 885 cout << "(STATE_GAME_LOBBY) "; 832 886 case STATE_GAME: 833 887 { … … 1312 1366 } 1313 1367 1368 void joinWaitingArea() { 1369 cout << "joining waiting area" << endl; 1370 currentPlayer->team = -1; 1371 } 1372 1373 void joinBlueTeam() { 1374 cout << "joining blue team" << endl; 1375 currentPlayer->team = 0; 1376 } 1377 1378 void joinRedTeam() { 1379 cout << "joining red team" << endl; 1380 currentPlayer->team = 1; 1381 } 1382 1383 void startGame() { 1384 state = STATE_GAME; 1385 wndCurrent = wndGame; 1386 } 1387 1314 1388 void leaveGame() 1315 1389 {
Note:
See TracChangeset
for help on using the changeset viewer.