Changeset eb8adb1 in network-game for client


Ignore:
Timestamp:
Dec 31, 2012, 1:22:06 AM (12 years ago)
Author:
Dmitry Portnoy <dmp1488@…>
Branches:
master
Children:
8a3ef42
Parents:
8f438a5
Message:

Added a map from player ids to players to the client

File:
1 edited

Legend:

Unmodified
Added
Removed
  • client/Client/main.cpp

    r8f438a5 reb8adb1  
    1919#include <iostream>
    2020
     21#include <map>
     22
    2123#include <allegro5/allegro.h>
    2224#include <allegro5/allegro_font.h>
     
    4042void initWinSock();
    4143void shutdownWinSock();
    42 void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole);
     44void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, map<unsigned int, Player>& mapPlayers);
    4345
    4446// callbacks
     
    9597   bool redraw = true;
    9698   doexit = false;
     99   map<unsigned int, Player> mapPlayers;
    97100
    98101   float bouncer_x = SCREEN_W / 2.0 - BOUNCER_SIZE / 2.0;
     
    290293      if (receiveMessage(&msgFrom, sock, &from) >= 0)
    291294      {
    292          processMessage(msgFrom, state, chatConsole);
     295         processMessage(msgFrom, state, chatConsole, mapPlayers);
    293296         cout << "state: " << state << endl;
    294297      }
     
    368371}
    369372
    370 void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole)
     373void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, map<unsigned int, Player>& mapPlayers)
    371374{
    372375   string response = string(msg.buffer);
     
    414417      case STATE_LOGIN:
    415418      {
    416          chatConsole.addLine(response);
    417 
    418           switch(msg.type)
     419         switch(msg.type)
    419420         {
    420421            case MSG_TYPE_REGISTER:
     
    424425            case MSG_TYPE_LOGIN:
    425426            {
     427               chatConsole.addLine(response);
     428
    426429               if (response.compare("You have successfully logged out.") == 0)
    427430               {
     
    442445               p.deserialize(msg.buffer);
    443446
     447               cout << "p.id: " << p.id << endl;
    444448               cout << "p.name: " << p.name << endl;
    445449               cout << "p.pos.x: " << p.pos.x << endl;
    446450               cout << "p.pos.y: " << p.pos.y << endl;
    447451
     452               mapPlayers[p.id] = p;
     453
    448454               break;
    449455            }
    450          }
    451                      
     456            case MSG_TYPE_CHAT:
     457            {
     458               chatConsole.addLine(response);
     459
     460               break;
     461            }
     462         }
     463
    452464         break;
    453465      }
Note: See TracChangeset for help on using the changeset viewer.