Changeset 07c73fa in network-game for common


Ignore:
Timestamp:
May 26, 2013, 6:26:15 PM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
d09fe76
Parents:
446dc65
Message:

Added class, health, attackType, and damage to the Player class

Location:
common
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • common/Player.cpp

    r446dc65 r07c73fa  
    1616   this->pos.y = this->target.y = 0;
    1717   this->timeLastUpdated = 0;
     18
     19   this->playerClass = CLASS_NONE;
     20   this->maxHealth = 0;
     21   this->health = 0;
     22   this->attackType = ATTACK_NONE;
     23   this->damage = 0;
    1824   this->team = 0;   // blue team by default
    1925   this->hasBlueFlag = false;
     
    2632   this->name = p.name;
    2733   this->password = p.password;
     34   this->addr = p.addr;
    2835   this->pos.x = p.pos.x;
    2936   this->pos.y = p.pos.y;
    3037   this->target.x = p.target.x;
    3138   this->target.y = p.target.y;
    32    this->addr = p.addr;
     39   this->timeLastUpdated = p.timeLastUpdated;
     40
     41   this->playerClass = p.playerClass;
     42   this->maxHealth = p.maxHealth;
     43   this->health = p.health;
     44   this->attackType = p.attackType;
     45   this->damage = p.damage;
    3346   this->team = p.team;
    3447   this->hasBlueFlag = p.hasBlueFlag;
     
    3649}
    3750
     51// eventually make this take a PlayerClass argument as well
    3852Player::Player(string name, string password)
    3953{
     
    4357   this->pos.x = this->target.x = 200;
    4458   this->pos.y = this->target.y = 200;
     59
     60   this->playerClass = CLASS_NONE;
     61   this->maxHealth = 0;
     62   this->health = 0;
     63   this->attackType = ATTACK_NONE;
     64   this->damage = 0;
    4565   this->team = 0;   // blue team by default
    4666   this->hasBlueFlag = false;
     
    5979   memcpy(buffer+12, &this->target.x, 4);
    6080   memcpy(buffer+16, &this->target.y, 4);
    61    memcpy(buffer+20, &this->team, 4);
    62    memcpy(buffer+24, &this->hasBlueFlag, 1);
    63    memcpy(buffer+25, &this->hasRedFlag, 1);
    64    strcpy(buffer+26, this->name.c_str());
     81
     82   memcpy(buffer+20, &this->playerClass, 4);
     83   memcpy(buffer+24, &this->maxHealth, 4);
     84   memcpy(buffer+28, &this->health, 4);
     85   memcpy(buffer+32, &this->attackType, 4);
     86   memcpy(buffer+36, &this->damage, 4);
     87   memcpy(buffer+40, &this->team, 4);
     88   memcpy(buffer+44, &this->hasBlueFlag, 1);
     89   memcpy(buffer+45, &this->hasRedFlag, 1);
     90
     91   strcpy(buffer+46, this->name.c_str());
    6592}
    6693
     
    7299   memcpy(&this->target.x, buffer+12, 4);
    73100   memcpy(&this->target.y, buffer+16, 4);
    74    memcpy(&this->team, buffer+20, 4);
    75    memcpy(&this->hasBlueFlag, buffer+24, 1);
    76    memcpy(&this->hasRedFlag, buffer+25, 1);
    77    this->name.assign(buffer+26);
     101
     102   memcpy(&this->playerClass, buffer+20, 4);
     103   memcpy(&this->maxHealth, buffer+24, 4);
     104   memcpy(&this->health, buffer+28, 4);
     105   memcpy(&this->attackType, buffer+32, 4);
     106   memcpy(&this->damage, buffer+36, 4);
     107   memcpy(&this->team, buffer+40, 4);
     108   memcpy(&this->hasBlueFlag, buffer+44, 1);
     109   memcpy(&this->hasRedFlag, buffer+45, 1);
     110
     111   this->name.assign(buffer+46);
    78112}
    79113
     
    86120{
    87121   this->addr = addr;
     122}
     123
     124void Player::setClass(PlayerClass c)
     125{
     126   switch (c) {
     127      case CLASS_WARRIOR:
     128         this->playerClass = CLASS_WARRIOR;
     129         this->maxHealth = this->health = 100;
     130         this->attackType = ATTACK_MELEE;
     131         this->damage = 10;
     132         break;
     133      case CLASS_RANGER:
     134         this->playerClass = CLASS_RANGER;
     135         this->maxHealth = this->health = 60;
     136         this->attackType = ATTACK_RANGED;
     137         this->damage = 6;
     138         break;
     139      case CLASS_NONE:
     140         cout << "No clas" << endl;
     141         break;
     142      dafault:
     143         cout << "nvalid class" << endl;
     144         break;
     145   }
    88146}
    89147
  • common/Player.h

    r446dc65 r07c73fa  
    2020class Player {
    2121public:
     22
     23   enum PlayerClass {
     24      CLASS_NONE,
     25      CLASS_WARRIOR,
     26      CLASS_RANGER
     27   };
     28
     29   enum AttackType {
     30      ATTACK_NONE,
     31      ATTACK_MELEE,
     32      ATTACK_RANGED
     33   };
     34
    2235   Player();
    2336   Player(const Player& p);
     
    2841   void serialize(char* buffer);
    2942   void deserialize(char* buffer);
     43   void setClass(PlayerClass c);
    3044
    3145   void setId(int id);
     
    4559   unsigned long long timeLastUpdated;
    4660
     61   int playerClass;
     62   int maxHealth;
     63   int health;
     64   int attackType;
     65   int damage;
    4766   int team; // 0 is blue, 1 is red
    4867   bool hasBlueFlag;
Note: See TracChangeset for help on using the changeset viewer.