Changeset 3e44a59 in network-game
- Timestamp:
- Dec 23, 2013, 8:45:55 PM (11 years ago)
- Branches:
- master
- Children:
- 778d0c9
- Parents:
- c9f6a1c
- Location:
- client/Client
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
client/Client/Client.vcxproj
rc9f6a1c r3e44a59 69 69 <ClCompile Include="..\..\common\Common.cpp" /> 70 70 <ClCompile Include="..\..\common\Game.cpp" /> 71 <ClCompile Include="..\..\common\GameSummary.cpp" /> 71 72 <ClCompile Include="..\..\common\MessageContainer.cpp" /> 72 73 <ClCompile Include="..\..\common\MessageProcessor.cpp" /> … … 88 89 <ClInclude Include="..\..\common\Compiler.h" /> 89 90 <ClInclude Include="..\..\common\Game.h" /> 91 <ClInclude Include="..\..\common\GameSummary.h" /> 90 92 <ClInclude Include="..\..\common\MessageContainer.h" /> 91 93 <ClInclude Include="..\..\common\MessageProcessor.h" /> -
client/Client/Client.vcxproj.filters
rc9f6a1c r3e44a59 76 76 <Filter>Source Files</Filter> 77 77 </ClCompile> 78 <ClCompile Include="..\..\common\GameSummary.cpp"> 79 <Filter>Source Files\common</Filter> 80 </ClCompile> 78 81 </ItemGroup> 79 82 <ItemGroup> … … 126 129 <Filter>Header Files</Filter> 127 130 </ClInclude> 131 <ClInclude Include="..\..\common\GameSummary.h"> 132 <Filter>Header Files\common</Filter> 133 </ClInclude> 128 134 </ItemGroup> 129 135 <ItemGroup> -
client/Client/main.cpp
rc9f6a1c r3e44a59 35 35 #include "../../common/Projectile.h" 36 36 #include "../../common/Game.h" 37 #include "../../common/GameSummary.h" 37 38 38 39 #include "Window.h" … … 54 55 void initWinSock(); 55 56 void 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); 57 void 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); 57 60 int getRefreshRate(int width, int height); 58 61 void drawMessageStatus(ALLEGRO_FONT* font); … … 70 73 void createGame(); 71 74 void leaveGame(); 75 void closeGameSummary(); 72 76 73 77 void error(const char *); … … 94 98 Window* wndNewGame; 95 99 Window* wndGameDebug; 100 Window* wndGameSummary; 96 101 Window* wndCurrent; 97 102 … … 123 128 map<string, int> mapGames; 124 129 Game* game; 130 GameSummary* gameSummary; 125 131 126 132 MessageProcessor msgProcessor; … … 143 149 bool fullscreen = false; 144 150 game = NULL; 151 gameSummary = NULL; 145 152 146 153 scoreBlue = 0; … … 288 295 289 296 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; 290 302 291 303 goToLoginScreen(); … … 388 400 } 389 401 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) { 400 403 if (ev.mouse.button == 1) { // left click 401 404 msgTo.type = MSG_TYPE_PLAYER_MOVE; … … 455 458 456 459 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); 458 461 459 462 if (redraw) … … 602 605 al_draw_line(start.x, start.y, end.x, end.y, al_map_rgb(0, 0, 0), 4); 603 606 } 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()); 604 622 } 605 623 … … 632 650 delete game; 633 651 652 if (gameSummary != NULL) 653 delete gameSummary; 654 634 655 map<unsigned int, Player*>::iterator it; 635 656 … … 683 704 } 684 705 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) 706 void 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) 686 709 { 687 710 // this is outdated since most messages now don't contain just a text string … … 986 1009 break; 987 1010 } 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 } 988 1050 case MSG_TYPE_PLAYER: 989 1051 { … … 1069 1131 cout << "Did not remove the object" << endl; 1070 1132 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 1089 1133 break; 1090 1134 } … … 1400 1444 msgProcessor.sendMessage(&msgTo, sock, &server, &outputLog); 1401 1445 } 1446 1447 void closeGameSummary() 1448 { 1449 delete gameSummary; 1450 wndCurrent = wndLobby; 1451 }
Note:
See TracChangeset
for help on using the changeset viewer.