Changeset 6054f1e in network-game


Ignore:
Timestamp:
Jan 7, 2014, 1:07:36 AM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
d05c484
Parents:
eb2ad4f
Message:

Moved damagePlayer to the Player class

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • common/Player.cpp

    reb2ad4f r6054f1e  
    206206}
    207207
     208void Player::takeDamage(int damage) {
     209   this->health -= damage;
     210   if (this->health < 0)
     211      this->health = 0;
     212   if (this->health == 0) {
     213      cout << "Player died" << endl;
     214      this->isDead = true;
     215      this->timeDied = getCurrentMillis();
     216   }
     217}
     218
    208219bool Player::updateTarget(map<unsigned int, Player*>& mapPlayers) {
    209220   if (this->isChasing) {
  • common/Player.h

    reb2ad4f r6054f1e  
    5050   bool updateTarget(map<unsigned int, Player*>& mapPlayers);
    5151   bool move(WorldMap *map);
     52   void takeDamage(int damage);
    5253
    5354   void takeFlag(int flag, WorldMap* map);
  • server/server.cpp

    reb2ad4f r6054f1e  
    5353Player *findPlayerByName(map<unsigned int, Player*> &m, string name);
    5454Player *findPlayerByAddr(map<unsigned int, Player*> &m, const sockaddr_in &addr);
    55 void damagePlayer(Player *p, int damage);
    5655
    5756void addObjectToMap(WorldMap::ObjectType objectType, int x, int y, WorldMap* gameMap, map<unsigned int, Player*>& mapPlayers, MessageProcessor &msgProcessor);
     
    222221
    223222                  Player* target = game->getPlayers()[itProj->second.target];
    224                   damagePlayer(target, itProj->second.damage);
     223                  target->takeDamage(itProj->second.damage);
    225224
    226225                  if (target->isDead)
     
    10291028
    10301029         Player* target = playersInGame[p->targetPlayer];
    1031          damagePlayer(target, p->damage);
     1030         target->takeDamage(p->damage);
    10321031
    10331032         if (target->isDead)
     
    11131112}
    11141113
    1115 void damagePlayer(Player *p, int damage) {
    1116    p->health -= damage;
    1117    if (p->health < 0)
    1118       p->health = 0;
    1119    if (p->health == 0) {
    1120       cout << "Player died" << endl;
    1121       p->isDead = true;
    1122       p->timeDied = getCurrentMillis();
    1123    }
    1124 }
    1125 
    11261114void addObjectToMap(WorldMap::ObjectType objectType, int x, int y, WorldMap* gameMap, map<unsigned int, Player*>& mapPlayers, MessageProcessor &msgProcessor) {
    11271115   NETWORK_MSG serverMsg;
Note: See TracChangeset for help on using the changeset viewer.