Changeset 803566d in network-game


Ignore:
Timestamp:
Sep 26, 2013, 11:30:37 PM (11 years ago)
Author:
Dmitry Portnoy <dportnoy@…>
Branches:
master
Children:
b48ef09
Parents:
f203c5c
Message:

The client has a new state to handle separate game instances

File:
1 edited

Legend:

Unmodified
Added
Removed
  • client/Client/main.cpp

    rf203c5c r803566d  
    8080   STATE_START,
    8181   STATE_LOBBY,
    82    STATE_GAME
     82   STATE_GAME,
     83   STATE_NEW_GAME
    8384};
    8485
     
    120121bool debugging;
    121122map<string, int> mapGames;
     123Game* game;
    122124
    123125MessageProcessor msgProcessor;
     
    130132   ALLEGRO_TIMER *timer = NULL;
    131133   bool key[4] = { false, false, false, false };
    132    bool redraw = true;
    133    doexit = false;
    134134   map<unsigned int, Player> mapPlayers;
    135135   map<unsigned int, Projectile> mapProjectiles;
    136136   unsigned int curPlayerId = -1;
    137137   int scoreBlue, scoreRed;
     138
     139   doexit = false;
     140   debugging = false;
     141   bool redraw = true;
    138142   bool fullscreen = false;
    139    debugging = false;
     143   game = NULL;
    140144
    141145   scoreBlue = 0;
     
    169173      fprintf(stderr, "Could not load 'pirulen.ttf'.\n");
    170174      getchar();
    171           return -1;
     175      return -1;
    172176   }
    173177 
     
    303307
    304308   initWinSock();
    305        
     309
    306310   sock = socket(AF_INET, SOCK_DGRAM, 0);
    307311   if (sock < 0)
     
    545549
    546550   delete gameMap;
     551   delete game;
    547552
    548553   al_destroy_event_queue(event_queue);
     
    575580   wVersionRequested = MAKEWORD(2, 2);
    576581   wsaerr = WSAStartup(wVersionRequested, &wsaData);
    577        
     582
    578583   if (wsaerr != 0) {
    579584      cout << "The Winsock dll not found." << endl;
     
    827832            case MSG_TYPE_GAME_INFO:
    828833            {
    829                 cout << "Received a GAME_INFO message" << endl;
     834               cout << "Received a GAME_INFO message" << endl;
    830835
    831836               string gameName(msg.buffer+4);
     
    843848            {
    844849               cout << "(STATE_LOBBY) Received invlaid message of type " << msg.type << endl;
     850
     851               break;
     852            }
     853         }
     854
     855         break;
     856      }
     857      case STATE_NEW_GAME:
     858      {
     859         switch(msg.type)
     860         {
     861            case MSG_TYPE_GAME_INFO:
     862            {
     863               cout << "(STATE_NEW_GAME) Received a GAME_INFO message" << endl;
     864
     865               string gameName(msg.buffer+4);
     866               int numPlayers;
     867
     868               //game = new Game(gameName);
     869
     870               memcpy(&numPlayers, msg.buffer, 4);
     871               
     872               cout << "Received game info for " << gameName << " (num players: " << numPlayers << ")" << endl;
     873               
     874               mapGames[gameName] = numPlayers;
     875
     876               break;
     877            }
     878            case MSG_TYPE_OBJECT:
     879            {
     880               cout << "(STATE_NEW_GAME) Received object message in STATE_LOBBY." << endl;
     881
     882               WorldMap::Object o(0, WorldMap::OBJECT_NONE, 0, 0);
     883               o.deserialize(msg.buffer);
     884               cout << "object id: " << o.id << endl;
     885               game->getMap()->updateObject(o.id, o.type, o.pos.x, o.pos.y);
     886
     887               break;
     888            }
     889            case MSG_TYPE_REMOVE_OBJECT:
     890            {
     891               cout << "(STATE_NEW_GAME) Received REMOVE_OBJECT message!" << endl;
     892
     893               int id;
     894               memcpy(&id, msg.buffer, 4);
     895
     896               cout << "Removing object with id " << id << endl;
     897
     898               if (!game->getMap()->removeObject(id))
     899                  cout << "Did not remove the object" << endl;
     900
     901               break;
     902            }
     903            case MSG_TYPE_SCORE:
     904            {
     905               cout << "Received SCORE message!" << endl;
     906
     907               int blueScore;
     908               memcpy(&blueScore, msg.buffer, 4);
     909               cout << "blue score: " << blueScore << endl;
     910               game->setBlueScore(blueScore);
     911
     912               int redScore;
     913               memcpy(&redScore, msg.buffer+4, 4);
     914               cout << "red score: " << redScore << endl;
     915               game->setRedScore(redScore);
     916
     917               cout << "Processed SCORE message!" << endl;
     918 
     919               break;
     920            }
     921            default:
     922            {
     923               cout << "(STATE_NEW_GAME) Received invalid message of type " << msg.type << endl;
    845924
    846925               break;
     
    11811260   cout << "Creating game" << endl;
    11821261
     1262   // hack to help transitions to multiple games
     1263   state = STATE_NEW_GAME;
     1264   game = new Game( txtCreateGame->getStr());
     1265
    11831266   string msg = txtCreateGame->getStr();
    11841267   txtCreateGame->clear();
Note: See TracChangeset for help on using the changeset viewer.