Changeset 2ee386d in network-game
- Timestamp:
- Sep 26, 2013, 3:33:18 AM (11 years ago)
- Branches:
- master
- Children:
- 2992b1a
- Parents:
- 99afbb8
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
client/Client/main.cpp
r99afbb8 r2ee386d 34 34 #include "../../common/Player.h" 35 35 #include "../../common/Projectile.h" 36 #include "../../common/Game.h" 36 37 37 38 #include "Window.h" … … 118 119 chat chatConsole, debugConsole; 119 120 bool debugging; 120 vector<string> games;121 map<string, Game> mapGames; 121 122 122 123 MessageProcessor msgProcessor; … … 451 452 452 453 if (wndCurrent == wndLobby) { 453 for (int i=0; i<games.size(); i++) { 454 al_draw_text(font, al_map_rgb(0, 255, 0), SCREEN_W*1/4-100, 120+i*15, ALLEGRO_ALIGN_LEFT, games[i].c_str()); 454 map<string, Game>::iterator it; 455 int i=0; 456 for (it = mapGames.begin(); it != mapGames.end(); it++) { 457 al_draw_text(font, al_map_rgb(0, 255, 0), SCREEN_W*1/4-100, 120+i*15, ALLEGRO_ALIGN_LEFT, it->first.c_str()); 458 i++; 455 459 } 456 460 } … … 821 825 cout << "Received a GAME_INFO message" << endl; 822 826 823 string name(msg.buffer+4);827 string gameName(msg.buffer+4); 824 828 int numPlayers; 825 829 826 830 memcpy(&numPlayers, msg.buffer, 4); 827 831 828 cout << "Received game info for " << name << " (num players: " << numPlayers << ")" << endl; 829 games.push_back(name); 832 cout << "Received game info for " << gameName << " (num players: " << numPlayers << ")" << endl; 833 834 if (mapGames.find(gameName) == mapGames.end()) 835 mapGames[gameName] = Game(gameName); 836 mapGames[gameName].setNumPlayers(numPlayers); 830 837 831 838 break; -
common/Game.cpp
r99afbb8 r2ee386d 20 20 } 21 21 22 int Game::getNumPlayers() { 23 return players.size(); 24 } 25 26 void Game::setNumPlayers(int numPlayers) { 27 int numCurPlayers = this->getNumPlayers(); 28 int numNewPlayers = numPlayers-numCurPlayers; 29 30 for (int i=0; i<numNewPlayers; i++) 31 this->players[numCurPlayers+i] = NULL; 32 } 33 22 34 bool Game::addPlayer(Player* p) { 23 35 if (players.count(p->id) == 0) { … … 35 47 return false; 36 48 } 37 38 int Game::getNumPlayers() {39 return players.size();40 } -
common/Game.h
r99afbb8 r2ee386d 30 30 ~Game(); 31 31 32 int getNumPlayers(); 33 32 34 void setId(int id); 33 35 void setNumPlayers(int numPlayers); 34 36 bool addPlayer(Player* p); 35 37 bool removePlayer(int id); 36 int getNumPlayers();37 38 }; 38 39
Note:
See TracChangeset
for help on using the changeset viewer.