Changeset 46fa35a in network-game


Ignore:
Timestamp:
May 26, 2013, 8:27:54 PM (12 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
e1f78f5
Parents:
d09fe76
Message:

The server randomly chooses a player's class when they log on

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • common/Player.cpp

    rd09fe76 r46fa35a  
    7272}
    7373
     74void Player::setId(int id)
     75{
     76   this->id = id;
     77}
     78
     79void Player::setAddr(sockaddr_in addr)
     80{
     81   this->addr = addr;
     82}
     83
     84void Player::setClass(PlayerClass c)
     85{
     86   switch (c) {
     87      case CLASS_WARRIOR:
     88         this->playerClass = CLASS_WARRIOR;
     89         this->maxHealth = this->health = 100;
     90         this->attackType = ATTACK_MELEE;
     91         this->damage = 10;
     92         break;
     93      case CLASS_RANGER:
     94         this->playerClass = CLASS_RANGER;
     95         this->maxHealth = this->health = 60;
     96         this->attackType = ATTACK_RANGED;
     97         this->damage = 6;
     98         break;
     99      case CLASS_NONE:
     100         cout << "No clas" << endl;
     101         break;
     102      dafault:
     103         cout << "nvalid class" << endl;
     104         break;
     105   }
     106}
     107
    74108void Player::serialize(char* buffer)
    75109{
     
    112146}
    113147
    114 void Player::setId(int id)
    115 {
    116    this->id = id;
    117 }
    118 
    119 void Player::setAddr(sockaddr_in addr)
    120 {
    121    this->addr = addr;
    122 }
    123 
    124 void 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    }
    146 }
    147 
    148148bool Player::move(WorldMap *map) {
    149149   int speed = 100; // pixels per second. should probably be in the constructor
  • common/Player.h

    rd09fe76 r46fa35a  
    3939   ~Player();
    4040
     41   void setId(int id);
     42   void setAddr(sockaddr_in addr);
     43   void setClass(PlayerClass c);
     44
    4145   void serialize(char* buffer);
    4246   void deserialize(char* buffer);
    43    void setClass(PlayerClass c);
    44 
    45    void setId(int id);
    46    void setAddr(sockaddr_in addr);
    4747
    4848   bool move(WorldMap *map);
  • server/server.cpp

    rd09fe76 r46fa35a  
    417417            // choose a random team (either 0 or 1)
    418418            p->team = rand() % 2;
     419
     420            // choose a random class
     421            int intClass = rand() % 2;
     422            switch (intClass) {
     423               case 0:
     424                  p->setClass(Player::CLASS_WARRIOR);
     425                  break;
     426               case 1:
     427                  p->setClass(Player::CLASS_RANGER);
     428                  break;
     429            }
    419430
    420431            // tell the new player about all the existing players
Note: See TracChangeset for help on using the changeset viewer.