Changeset 15efb4e in network-game


Ignore:
Timestamp:
May 26, 2013, 12:11:09 AM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
446dc65
Parents:
b8601ee
Message:

The client processes SCORE messages and displays the score

File:
1 edited

Legend:

Unmodified
Added
Removed
  • client/Client/main.cpp

    rb8601ee r15efb4e  
    4747void initWinSock();
    4848void shutdownWinSock();
    49 void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, WorldMap *gameMap, map<unsigned int, Player>& mapPlayers, unsigned int& curPlayerId);
     49void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, WorldMap *gameMap, map<unsigned int, Player>& mapPlayers, unsigned int& curPlayerId, int &scoreBlue, int &scoreRed);
    5050void drawMap(WorldMap* gameMap);
    5151void drawPlayers(map<unsigned int, Player>& mapPlayers, unsigned int curPlayerId);
     
    100100   map<unsigned int, Player> mapPlayers;
    101101   unsigned int curPlayerId = -1;
     102   int scoreBlue, scoreRed;
     103
     104   scoreBlue = 0;
     105   scoreRed = 0;
    102106
    103107   state = STATE_START;
     
    296300
    297301      if (receiveMessage(&msgFrom, sock, &from) >= 0)
    298          processMessage(msgFrom, state, chatConsole, gameMap, mapPlayers, curPlayerId);
     302         processMessage(msgFrom, state, chatConsole, gameMap, mapPlayers, curPlayerId, scoreBlue, scoreRed);
    299303
    300304      if (redraw)
     
    312316         else if(wndCurrent == wndMain) {
    313317            al_draw_text(font, al_map_rgb(0, 255, 0), 4, 43, ALLEGRO_ALIGN_LEFT, "Message:");
     318
     319            ostringstream ossScoreBlue, ossScoreRed;
     320
     321            ossScoreBlue << "Blue: " << scoreBlue << endl;
     322            ossScoreRed << "Red: " << scoreRed << endl;
     323
     324            al_draw_text(font, al_map_rgb(0, 255, 0), 330, 80, ALLEGRO_ALIGN_LEFT, ossScoreBlue.str().c_str());
     325            al_draw_text(font, al_map_rgb(0, 255, 0), 515, 80, ALLEGRO_ALIGN_LEFT, ossScoreRed.str().c_str());
    314326
    315327            // update player positions
     
    412424}
    413425
    414 void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, WorldMap *gameMap, map<unsigned int, Player>& mapPlayers, unsigned int& curPlayerId)
     426void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, WorldMap *gameMap, map<unsigned int, Player>& mapPlayers, unsigned int& curPlayerId, int &scoreBlue, int &scoreRed)
    415427{
    416428   string response = string(msg.buffer);
     
    575587               break;
    576588            }
     589            case MSG_TYPE_SCORE:
     590            {
     591               memcpy(&scoreBlue, msg.buffer, 4);
     592               memcpy(&scoreRed, msg.buffer+4, 4);
     593 
     594               break;
     595            }
    577596            default:
    578597            {
Note: See TracChangeset for help on using the changeset viewer.