Changeset 64a1f4e in network-game
- Timestamp:
- Jan 29, 2014, 2:06:36 AM (11 years ago)
- Branches:
- master
- Children:
- 8826eed
- Parents:
- d6b5f74
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
common/Game.cpp
rd6b5f74 r64a1f4e 3 3 #include <iostream> 4 4 #include <cstring> 5 #include <cstdlib> 5 6 6 7 #include "Common.h" … … 45 46 if (players.find(p->getId()) == players.end()) { 46 47 players[p->getId()] = p; 48 49 // reset player stats, location, etc. 50 p->pos.x = p->target.x = 200; 51 p->pos.y = p->target.y = 200; 52 p->setTargetPlayer(0); 53 p->isChasing = false; 54 p->isAttacking = false; 55 p->isDead = false; 56 p->health = p->maxHealth; 57 p->hasBlueFlag = false; 58 p->hasRedFlag = false; 59 60 // choose a random team (either 0 or 1) 61 p->team = rand() % 2; 62 63 p->currentGame = this; 64 47 65 return true; 48 66 } -
server/server.cpp
rd6b5f74 r64a1f4e 7 7 #include <fstream> 8 8 #include <cstring> 9 #include <cmath>10 9 11 10 #include <vector> … … 336 335 cout << "new player id: " << p->getId() << endl; 337 336 p->setAddr(from); 338 p->currentGame = NULL;339 340 // choose a random team (either 0 or 1)341 p->team = rand() % 2;342 337 343 338 serverMsg.type = MSG_TYPE_PLAYER; … … 696 691 697 692 Player* p = findPlayerByAddr(mapPlayers, from); 698 p->team = rand() % 2; // choose a random team (either 0 or 1)699 p->currentGame = g;700 693 701 694 // tell the new player about all map objects … … 723 716 msgProcessor.sendMessage(&serverMsg, &from); 724 717 718 719 map<unsigned int, Player*>& oldPlayers = g->getPlayers(); 720 g->addPlayer(p); 721 725 722 // send info to other players 726 723 serverMsg.type = MSG_TYPE_PLAYER_JOIN_GAME; 727 724 p->serialize(serverMsg.buffer); 728 725 cout << "Should be broadcasting the message" << endl; 729 msgProcessor.broadcastMessage(serverMsg, g->getPlayers()); 730 731 g->addPlayer(p); 726 msgProcessor.broadcastMessage(serverMsg, oldPlayers); 732 727 733 728 … … 735 730 cout << "Sending other players to new player" << endl; 736 731 serverMsg.type = MSG_TYPE_PLAYER_JOIN_GAME; 737 738 732 739 733 map<unsigned int, Player*>& allPlayers = g->getPlayers(); … … 747 741 msgProcessor.sendMessage(&serverMsg, &from); 748 742 } 743 749 744 750 745 int numPlayers = g->getNumPlayers();
Note:
See TracChangeset
for help on using the changeset viewer.