Changeset 2ee386d in network-game for client/Client/main.cpp


Ignore:
Timestamp:
Sep 26, 2013, 3:33:18 AM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
2992b1a
Parents:
99afbb8
Message:

Clients store the total number of players in each game

File:
1 edited

Legend:

Unmodified
Added
Removed
  • client/Client/main.cpp

    r99afbb8 r2ee386d  
    3434#include "../../common/Player.h"
    3535#include "../../common/Projectile.h"
     36#include "../../common/Game.h"
    3637
    3738#include "Window.h"
     
    118119chat chatConsole, debugConsole;
    119120bool debugging;
    120 vector<string> games;
     121map<string, Game> mapGames;
    121122
    122123MessageProcessor msgProcessor;
     
    451452
    452453         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++;
    455459            }
    456460         }
     
    821825                cout << "Received a GAME_INFO message" << endl;
    822826
    823                string name(msg.buffer+4);
     827               string gameName(msg.buffer+4);
    824828               int numPlayers;
    825829
    826830               memcpy(&numPlayers, msg.buffer, 4);
    827831               
    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);
    830837
    831838               break;
Note: See TracChangeset for help on using the changeset viewer.