Changeset 3e44a59 in network-game


Ignore:
Timestamp:
Dec 23, 2013, 8:45:55 PM (11 years ago)
Author:
Dmitry Portnoy <dportnoy@…>
Branches:
master
Children:
778d0c9
Parents:
c9f6a1c
Message:

The client shows a game summary screen when the current game cfinishes

Location:
client/Client
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • client/Client/Client.vcxproj

    rc9f6a1c r3e44a59  
    6969    <ClCompile Include="..\..\common\Common.cpp" />
    7070    <ClCompile Include="..\..\common\Game.cpp" />
     71    <ClCompile Include="..\..\common\GameSummary.cpp" />
    7172    <ClCompile Include="..\..\common\MessageContainer.cpp" />
    7273    <ClCompile Include="..\..\common\MessageProcessor.cpp" />
     
    8889    <ClInclude Include="..\..\common\Compiler.h" />
    8990    <ClInclude Include="..\..\common\Game.h" />
     91    <ClInclude Include="..\..\common\GameSummary.h" />
    9092    <ClInclude Include="..\..\common\MessageContainer.h" />
    9193    <ClInclude Include="..\..\common\MessageProcessor.h" />
  • client/Client/Client.vcxproj.filters

    rc9f6a1c r3e44a59  
    7676      <Filter>Source Files</Filter>
    7777    </ClCompile>
     78    <ClCompile Include="..\..\common\GameSummary.cpp">
     79      <Filter>Source Files\common</Filter>
     80    </ClCompile>
    7881  </ItemGroup>
    7982  <ItemGroup>
     
    126129      <Filter>Header Files</Filter>
    127130    </ClInclude>
     131    <ClInclude Include="..\..\common\GameSummary.h">
     132      <Filter>Header Files\common</Filter>
     133    </ClInclude>
    128134  </ItemGroup>
    129135  <ItemGroup>
  • client/Client/main.cpp

    rc9f6a1c r3e44a59  
    3535#include "../../common/Projectile.h"
    3636#include "../../common/Game.h"
     37#include "../../common/GameSummary.h"
    3738
    3839#include "Window.h"
     
    5455void initWinSock();
    5556void shutdownWinSock();
    56 void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, WorldMap *gameMap, map<unsigned int, Player*>& mapPlayers, map<unsigned int, Projectile>& mapProjectiles, unsigned int& curPlayerId, int &scoreBlue, int &scoreRed);
     57void 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,
     59                    GameSummary* gameSummary);
    5760int getRefreshRate(int width, int height);
    5861void drawMessageStatus(ALLEGRO_FONT* font);
     
    7073void createGame();
    7174void leaveGame();
     75void closeGameSummary();
    7276
    7377void error(const char *);
     
    9498Window* wndNewGame;
    9599Window* wndGameDebug;
     100Window* wndGameSummary;
    96101Window* wndCurrent;
    97102
     
    123128map<string, int> mapGames;
    124129Game* game;
     130GameSummary* gameSummary;
    125131
    126132MessageProcessor msgProcessor;
     
    143149   bool fullscreen = false;
    144150   game = NULL;
     151   gameSummary = NULL;
    145152
    146153   scoreBlue = 0;
     
    288295
    289296   cout << "Created new game screen" << endl;
     297
     298   wndGameSummary = new Window(0, 0, SCREEN_W, SCREEN_H);
     299   wndGameSummary->addComponent(new Button(840, 730, 160, 20, font, "Back to Lobby", closeGameSummary));
     300
     301   cout << "Created game summary screen" << endl;
    290302
    291303   goToLoginScreen();
     
    388400      }
    389401      else if(ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP) {
    390          if(wndCurrent == wndLobby) {
    391             /*
    392             if (ev.mouse.button == 1) { // left click
    393                txtJoinGame->clear();
    394                txtCreateGame->clear();
    395                state = STATE_GAME;
    396                wndCurrent = wndGame;
    397             }
    398             */
    399          }else if(wndCurrent == wndGame || wndCurrent == wndNewGame) {
     402         if(wndCurrent == wndGame || wndCurrent == wndNewGame) {
    400403            if (ev.mouse.button == 1) {   // left click
    401404               msgTo.type = MSG_TYPE_PLAYER_MOVE;
     
    455458
    456459      if (msgProcessor.receiveMessage(&msgFrom, sock, &from, &outputLog) >= 0)
    457          processMessage(msgFrom, state, chatConsole, gameMap, mapPlayers, mapProjectiles, curPlayerId, scoreBlue, scoreRed);
     460         processMessage(msgFrom, state, chatConsole, gameMap, mapPlayers, mapProjectiles, curPlayerId, scoreBlue, scoreRed, gameSummary);
    458461
    459462      if (redraw)
     
    602605               al_draw_line(start.x, start.y, end.x, end.y, al_map_rgb(0, 0, 0), 4);
    603606            }
     607         }else if (wndCurrent == wndGameSummary) {
     608            string strBlueScore = "Blue Score: "+gameSummary->getBlueScore();
     609            string strRedScore = "Red Score: "+gameSummary->getRedScore();
     610
     611            string strWinner;
     612
     613            if (gameSummary->getWinner() == 0)
     614                strWinner = "Blue Team Wins";
     615            else if (gameSummary->getWinner() == 1)
     616                strWinner = "Red Team Wins";
     617
     618            al_draw_text(font, al_map_rgb(0, 255, 0), 512, 40, ALLEGRO_ALIGN_CENTRE, gameSummary->getName().c_str());
     619            al_draw_text(font, al_map_rgb(0, 255, 0), 330, 80, ALLEGRO_ALIGN_LEFT, strBlueScore.c_str());
     620            al_draw_text(font, al_map_rgb(0, 255, 0), 515, 80, ALLEGRO_ALIGN_LEFT, strRedScore.c_str());
     621            al_draw_text(font, al_map_rgb(0, 255, 0), 512, 120, ALLEGRO_ALIGN_CENTRE, strWinner.c_str());
    604622         }
    605623
     
    632650      delete game;
    633651
     652   if (gameSummary != NULL)
     653      delete gameSummary;
     654
    634655   map<unsigned int, Player*>::iterator it;
    635656
     
    683704}
    684705
    685 void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, WorldMap *gameMap, map<unsigned int, Player*>& mapPlayers, map<unsigned int, Projectile>& mapProjectiles, unsigned int& curPlayerId, int &scoreBlue, int &scoreRed)
     706void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, WorldMap *gameMap, map<unsigned int, Player*>& mapPlayers,
     707                    map<unsigned int, Projectile>& mapProjectiles, unsigned int& curPlayerId, int &scoreBlue, int &scoreRed,
     708                    GameSummary* gameSummary)
    686709{
    687710   // this is outdated since most messages now don't contain just a text string
     
    9861009               break;
    9871010            }
     1011            case MSG_TYPE_SCORE:
     1012            {
     1013               cout << "Received SCORE message!" << endl;
     1014
     1015               int blueScore;
     1016               memcpy(&blueScore, msg.buffer, 4);
     1017               cout << "blue score: " << blueScore << endl;
     1018               game->setBlueScore(blueScore);
     1019
     1020               int redScore;
     1021               memcpy(&redScore, msg.buffer+4, 4);
     1022               cout << "red score: " << redScore << endl;
     1023               game->setRedScore(redScore);
     1024
     1025               cout << "Processed SCORE message!" << endl;
     1026 
     1027               break;
     1028            }
     1029            case MSG_TYPE_FINISH_GAME:
     1030            {
     1031               cout << "Got a finish game message" << endl;
     1032               cout << "Should switch to STATE_LOBBY and show the final score" << endl;
     1033
     1034               string gameName(msg.buffer);
     1035
     1036               unsigned int winner, blueScore, redScore;
     1037               memcpy(&winner, msg.buffer+4, 4);
     1038               memcpy(&blueScore, msg.buffer+8, 4);
     1039               memcpy(&redScore, msg.buffer+12, 4);
     1040
     1041               gameSummary = new GameSummary(gameName, winner, blueScore, redScore);
     1042
     1043               delete game;
     1044               game = NULL;
     1045               state = STATE_LOBBY;
     1046               wndCurrent = wndGameSummary;
     1047
     1048               break;
     1049            }
    9881050            case MSG_TYPE_PLAYER:
    9891051            {
     
    10691131                  cout << "Did not remove the object" << endl;
    10701132
    1071                break;
    1072             }
    1073             case MSG_TYPE_SCORE:
    1074             {
    1075                cout << "Received SCORE message!" << endl;
    1076 
    1077                int blueScore;
    1078                memcpy(&blueScore, msg.buffer, 4);
    1079                cout << "blue score: " << blueScore << endl;
    1080                game->setBlueScore(blueScore);
    1081 
    1082                int redScore;
    1083                memcpy(&redScore, msg.buffer+4, 4);
    1084                cout << "red score: " << redScore << endl;
    1085                game->setRedScore(redScore);
    1086 
    1087                cout << "Processed SCORE message!" << endl;
    1088  
    10891133               break;
    10901134            }
     
    14001444   msgProcessor.sendMessage(&msgTo, sock, &server, &outputLog);
    14011445}
     1446
     1447void closeGameSummary()
     1448{
     1449    delete gameSummary;
     1450    wndCurrent = wndLobby;
     1451}
Note: See TracChangeset for help on using the changeset viewer.