Changeset 64a1f4e in network-game


Ignore:
Timestamp:
Jan 29, 2014, 2:06:36 AM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
8826eed
Parents:
d6b5f74
Message:

Game.addPlayer reset all the player's stats as well

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • common/Game.cpp

    rd6b5f74 r64a1f4e  
    33#include <iostream>
    44#include <cstring>
     5#include <cstdlib>
    56
    67#include "Common.h"
     
    4546   if (players.find(p->getId()) == players.end()) {
    4647      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
    4765      return true;
    4866   }
  • server/server.cpp

    rd6b5f74 r64a1f4e  
    77#include <fstream>
    88#include <cstring>
    9 #include <cmath>
    109
    1110#include <vector>
     
    336335            cout << "new player id: " << p->getId() << endl;
    337336            p->setAddr(from);
    338             p->currentGame = NULL;
    339 
    340             // choose a random team (either 0 or 1)
    341             p->team = rand() % 2;
    342337
    343338            serverMsg.type = MSG_TYPE_PLAYER;
     
    696691
    697692         Player* p = findPlayerByAddr(mapPlayers, from);
    698          p->team = rand() % 2; // choose a random team (either 0 or 1)
    699          p->currentGame = g;
    700693
    701694         // tell the new player about all map objects
     
    723716         msgProcessor.sendMessage(&serverMsg, &from);
    724717
     718
     719         map<unsigned int, Player*>& oldPlayers = g->getPlayers();
     720         g->addPlayer(p);
     721
    725722         // send info to other players
    726723         serverMsg.type = MSG_TYPE_PLAYER_JOIN_GAME;
    727724         p->serialize(serverMsg.buffer);
    728725         cout << "Should be broadcasting the message" << endl;
    729          msgProcessor.broadcastMessage(serverMsg, g->getPlayers());
    730 
    731          g->addPlayer(p);
     726         msgProcessor.broadcastMessage(serverMsg, oldPlayers);
    732727
    733728
     
    735730         cout << "Sending other players to new player" << endl;
    736731         serverMsg.type = MSG_TYPE_PLAYER_JOIN_GAME;
    737 
    738732         
    739733         map<unsigned int, Player*>& allPlayers = g->getPlayers();
     
    747741            msgProcessor.sendMessage(&serverMsg, &from);
    748742         }
     743
    749744
    750745         int numPlayers = g->getNumPlayers();
Note: See TracChangeset for help on using the changeset viewer.