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


Ignore:
Timestamp:
Dec 25, 2013, 3:23:09 PM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
df74597
Parents:
f3fb980
Message:

Removed global score variables from client, removed the old STATE_GAME, and renamed STATE_NEW_GAME to STATE_GAME

File:
1 edited

Legend:

Unmodified
Added
Removed
  • client/Client/main.cpp

    rf3fb980 re0fd377  
    5656void shutdownWinSock();
    5757void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, WorldMap *gameMap, map<unsigned int, Player*>& mapPlayers,
    58                     map<unsigned int, Projectile>& mapProjectiles, unsigned int& curPlayerId, int &scoreBlue, int &scoreRed);
     58                    map<unsigned int, Projectile>& mapProjectiles, unsigned int& curPlayerId);
    5959int getRefreshRate(int width, int height);
    6060void drawMessageStatus(ALLEGRO_FONT* font);
     
    8181   STATE_START,
    8282   STATE_LOBBY,
    83    STATE_GAME,
    84    STATE_NEW_GAME
     83   STATE_GAME
    8584};
    8685
     
    140139   ofstream outputLog;
    141140
    142    int scoreBlue, scoreRed;
    143 
    144141   doexit = false;
    145142   debugging = false;
     
    148145   game = NULL;
    149146   gameSummary = NULL;
    150 
    151    scoreBlue = 0;
    152    scoreRed = 0;
    153147
    154148   state = STATE_START;
     
    368362               break;
    369363            case ALLEGRO_KEY_S:  // pickup an item next to you
    370                if (state == STATE_GAME || state == STATE_NEW_GAME) {
     364               if (state == STATE_GAME) {
    371365                  msgTo.type = MSG_TYPE_PICKUP_FLAG;
    372366                  memcpy(msgTo.buffer, &curPlayerId, 4);
     
    375369               break;
    376370            case ALLEGRO_KEY_D:  // drop the current item
    377                if (state == STATE_GAME || state == STATE_NEW_GAME) {
     371               if (state == STATE_GAME) {
    378372                  Player* p = NULL;
    379373                  try {
     
    458452
    459453      if (msgProcessor.receiveMessage(&msgFrom, &from) >= 0)
    460          processMessage(msgFrom, state, chatConsole, gameMap, mapPlayers, mapProjectiles, curPlayerId, scoreBlue, scoreRed);
     454         processMessage(msgFrom, state, chatConsole, gameMap, mapPlayers, mapProjectiles, curPlayerId);
    461455
    462456      if (redraw)
     
    557551            ostringstream ossScoreBlue, ossScoreRed;
    558552
    559             ossScoreBlue << "Blue: " << scoreBlue << endl;
    560             ossScoreRed << "Red: " << scoreRed << endl;
     553            ossScoreBlue << "Blue: " << game->getBlueScore() << endl;
     554            ossScoreRed << "Red: " << game->getRedScore() << endl;
    561555
    562556            al_draw_text(font, al_map_rgb(0, 255, 0), 330, 80, ALLEGRO_ALIGN_LEFT, ossScoreBlue.str().c_str());
     
    711705
    712706void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, WorldMap *gameMap, map<unsigned int, Player*>& mapPlayers,
    713                     map<unsigned int, Projectile>& mapProjectiles, unsigned int& curPlayerId, int &scoreBlue, int &scoreRed)
     707                    map<unsigned int, Projectile>& mapProjectiles, unsigned int& curPlayerId)
    714708{
    715709   // this is outdated since most messages now don't contain just a text string
     
    739733      }
    740734      case STATE_LOBBY:
     735      {
    741736         cout << "In STATE_LOBBY" << endl;
    742       case STATE_GAME:
    743       {
    744737         switch(msg.type)
    745738         {
     
    875868               break;
    876869            }
    877             case MSG_TYPE_SCORE:
    878             {
    879                memcpy(&scoreBlue, msg.buffer, 4);
    880                memcpy(&scoreRed, msg.buffer+4, 4);
    881  
    882                break;
    883             }
    884870            case MSG_TYPE_ATTACK:
    885871            {
     
    965951               cout << "Game name: " << gameName << endl;
    966952
    967                state = STATE_NEW_GAME;
     953               state = STATE_GAME;
    968954               wndCurrent = wndNewGame;
    969955
     
    991977         break;
    992978      }
    993       case STATE_NEW_GAME:
     979      case STATE_GAME:
    994980      {
    995          cout << "(STATE_NEW_GAME) ";
     981         cout << "(STATE_GAME) ";
    996982         switch(msg.type)
    997983         {
     
    11251111            case MSG_TYPE_OBJECT:
    11261112            {
    1127                cout << "Received object message in STATE_NEW_GAME" << endl;
     1113               cout << "Received object message in STATE_GAME" << endl;
    11281114
    11291115               WorldMap::Object o(0, WorldMap::OBJECT_NONE, 0, 0);
     
    13811367      txtCreateGame->clear();
    13821368      break;
    1383    case STATE_GAME:
    1384       txtChat->clear();
    1385       chatConsole.clear();
    1386       break;
    13871369   default:
    13881370      cout << "Logout called from invalid state: " << state << endl;
Note: See TracChangeset for help on using the changeset viewer.