Changeset 803566d in network-game for client/Client/main.cpp
- Timestamp:
- Sep 26, 2013, 11:30:37 PM (11 years ago)
- Branches:
- master
- Children:
- b48ef09
- Parents:
- f203c5c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
client/Client/main.cpp
rf203c5c r803566d 80 80 STATE_START, 81 81 STATE_LOBBY, 82 STATE_GAME 82 STATE_GAME, 83 STATE_NEW_GAME 83 84 }; 84 85 … … 120 121 bool debugging; 121 122 map<string, int> mapGames; 123 Game* game; 122 124 123 125 MessageProcessor msgProcessor; … … 130 132 ALLEGRO_TIMER *timer = NULL; 131 133 bool key[4] = { false, false, false, false }; 132 bool redraw = true;133 doexit = false;134 134 map<unsigned int, Player> mapPlayers; 135 135 map<unsigned int, Projectile> mapProjectiles; 136 136 unsigned int curPlayerId = -1; 137 137 int scoreBlue, scoreRed; 138 139 doexit = false; 140 debugging = false; 141 bool redraw = true; 138 142 bool fullscreen = false; 139 debugging = false;143 game = NULL; 140 144 141 145 scoreBlue = 0; … … 169 173 fprintf(stderr, "Could not load 'pirulen.ttf'.\n"); 170 174 getchar(); 171 175 return -1; 172 176 } 173 177 … … 303 307 304 308 initWinSock(); 305 309 306 310 sock = socket(AF_INET, SOCK_DGRAM, 0); 307 311 if (sock < 0) … … 545 549 546 550 delete gameMap; 551 delete game; 547 552 548 553 al_destroy_event_queue(event_queue); … … 575 580 wVersionRequested = MAKEWORD(2, 2); 576 581 wsaerr = WSAStartup(wVersionRequested, &wsaData); 577 582 578 583 if (wsaerr != 0) { 579 584 cout << "The Winsock dll not found." << endl; … … 827 832 case MSG_TYPE_GAME_INFO: 828 833 { 829 834 cout << "Received a GAME_INFO message" << endl; 830 835 831 836 string gameName(msg.buffer+4); … … 843 848 { 844 849 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; 845 924 846 925 break; … … 1181 1260 cout << "Creating game" << endl; 1182 1261 1262 // hack to help transitions to multiple games 1263 state = STATE_NEW_GAME; 1264 game = new Game( txtCreateGame->getStr()); 1265 1183 1266 string msg = txtCreateGame->getStr(); 1184 1267 txtCreateGame->clear();
Note:
See TracChangeset
for help on using the changeset viewer.