Changeset a0ce8a3 in network-game for client/Client


Ignore:
Timestamp:
Jun 30, 2014, 11:51:12 PM (10 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
ea17281
Parents:
e708305
Message:

Begin creation of the lobby screen for an individual game

File:
1 edited

Legend:

Unmodified
Added
Removed
  • client/Client/main.cpp

    re708305 ra0ce8a3  
    7777void sendChatMessage();
    7878void toggleDebugging();
    79 void joinGame();
    80 void createGame();
     79void joinGame(); // for joining the game lobby
     80void createGame(); // for joining the game lobby
     81void joinWaitingArea();
     82void joinRedTeam();
     83void joinBlueTeam();
     84void startGame(); // for leaving game lobby and starting the actual game
    8185void leaveGame();
    8286void closeGameSummary();
     
    8993   STATE_START,
    9094   STATE_LOBBY,
     95   STATE_GAME_LOBBY,
    9196   STATE_GAME
    9297};
     
    102107Window* wndLobby;
    103108Window* wndLobbyDebug;
     109Window* wndGameLobby;
    104110Window* wndGame;
    105111Window* wndGameSummary;
     
    131137Game* game;
    132138GameSummary* gameSummary;
     139Player* currentPlayer;
    133140
    134141MessageProcessor msgProcessor;
     
    320327      }
    321328      else if(ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP) {
    322          if(wndCurrent == wndGame) {
     329         if (wndCurrent == wndGame) {
    323330            if (ev.mouse.button == 1) {   // left click
    324331               msgTo.type = MSG_TYPE_PLAYER_MOVE;
     
    351358               Player* target;
    352359
    353                for(it = playersInGame.begin(); it != playersInGame.end(); it++)
     360               for (it = playersInGame.begin(); it != playersInGame.end(); it++)
    354361               {
    355362                  target = it->second;
     
    424431            }
    425432         }
     433         else if (wndCurrent == wndGameLobby)
     434         {
     435            al_draw_text(font, al_map_rgb(0, 255, 0), 200, 100, ALLEGRO_ALIGN_LEFT, "Waiting Area");
     436            al_draw_text(font, al_map_rgb(0, 255, 0), 400, 100, ALLEGRO_ALIGN_LEFT, "Blue Team");
     437            al_draw_text(font, al_map_rgb(0, 255, 0), 600, 100, ALLEGRO_ALIGN_LEFT, "Red Team");
     438
     439            int drawPosition = 0;
     440
     441            switch (currentPlayer->team) {
     442            case -1:
     443               drawPosition = 200;
     444               break;
     445            case 0:
     446               drawPosition = 400;
     447               break;
     448            case 1:
     449               drawPosition = 600;
     450               break;
     451            }
     452
     453            map<unsigned int, Player*> gamePlayers = game->getPlayers();
     454            map<unsigned int, Player*>::iterator itPlayers;
     455            ostringstream oss;
     456            int i=0;
     457            for (itPlayers = gamePlayers.begin(); itPlayers != gamePlayers.end(); itPlayers++) {
     458               oss << itPlayers->second->name << endl;
     459               al_draw_text(font, al_map_rgb(0, 255, 0), drawPosition, 135+i*15, ALLEGRO_ALIGN_LEFT, oss.str().c_str());
     460               oss.clear();
     461               oss.str("");
     462               i++;
     463            }
     464         }
    426465         else if (wndCurrent == wndGame)
    427466         {
     
    516555   delete wndLobby;
    517556   delete wndLobbyDebug;
     557   delete wndGameLobby;
    518558   delete wndGame;
    519559   delete wndGameSummary;
     
    654694
    655695
     696   // wndGameLobby
     697
     698   wndGameLobby = new Window(0, 0, SCREEN_W, SCREEN_H);
     699   vctComponents.push_back(wndGameLobby->addComponent(new Button(180, 120, 160, 300, font, "", joinWaitingArea)));
     700   vctComponents.push_back(wndGameLobby->addComponent(new Button(380, 120, 160, 300, font, "", joinBlueTeam)));
     701   vctComponents.push_back(wndGameLobby->addComponent(new Button(580, 120, 160, 300, font, "", joinRedTeam)));
     702   vctComponents.push_back(wndGameLobby->addComponent(new Button(40, 600, 120, 20, font, "Leave Game", leaveGame)));
     703   vctComponents.push_back(wndGameLobby->addComponent(new Button(800, 600, 120, 20, font, "Start Game", startGame)));
     704
     705
    656706   // wndGame
    657707
     
    730780                  mapPlayers[p->getId()] = p;
    731781                  curPlayerId = p->getId();
     782                  currentPlayer = mapPlayers[curPlayerId];
    732783
    733784                  cout << "Got a valid login response with the player" << endl;
     
    792843               cout << "Game name: " << gameName << endl;
    793844
    794                state = STATE_GAME;
    795                wndCurrent = wndGame;
     845               state = STATE_GAME_LOBBY;
     846               wndCurrent = wndGameLobby;
     847               mapPlayers[curPlayerId]->team = -1;
    796848
    797849               msgTo.type = MSG_TYPE_JOIN_GAME_ACK;
     
    830882         break;
    831883      }
     884      case STATE_GAME_LOBBY:
     885         cout << "(STATE_GAME_LOBBY) ";
    832886      case STATE_GAME:
    833887      {
     
    13121366}
    13131367
     1368void joinWaitingArea() {
     1369   cout << "joining waiting area" << endl;
     1370   currentPlayer->team = -1;
     1371}
     1372
     1373void joinBlueTeam() {
     1374   cout << "joining blue team" << endl;
     1375   currentPlayer->team = 0;
     1376}
     1377
     1378void joinRedTeam() {
     1379   cout << "joining red team" << endl;
     1380   currentPlayer->team = 1;
     1381}
     1382
     1383void startGame() {
     1384   state = STATE_GAME;
     1385   wndCurrent = wndGame;
     1386}
     1387
    13141388void leaveGame()
    13151389{
Note: See TracChangeset for help on using the changeset viewer.