Changeset 46fa35a in network-game
- Timestamp:
- May 26, 2013, 8:27:54 PM (12 years ago)
- Branches:
- master
- Children:
- e1f78f5
- Parents:
- d09fe76
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
common/Player.cpp
rd09fe76 r46fa35a 72 72 } 73 73 74 void Player::setId(int id) 75 { 76 this->id = id; 77 } 78 79 void Player::setAddr(sockaddr_in addr) 80 { 81 this->addr = addr; 82 } 83 84 void 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 74 108 void Player::serialize(char* buffer) 75 109 { … … 112 146 } 113 147 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 148 148 bool Player::move(WorldMap *map) { 149 149 int speed = 100; // pixels per second. should probably be in the constructor -
common/Player.h
rd09fe76 r46fa35a 39 39 ~Player(); 40 40 41 void setId(int id); 42 void setAddr(sockaddr_in addr); 43 void setClass(PlayerClass c); 44 41 45 void serialize(char* buffer); 42 46 void deserialize(char* buffer); 43 void setClass(PlayerClass c);44 45 void setId(int id);46 void setAddr(sockaddr_in addr);47 47 48 48 bool move(WorldMap *map); -
server/server.cpp
rd09fe76 r46fa35a 417 417 // choose a random team (either 0 or 1) 418 418 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 } 419 430 420 431 // tell the new player about all the existing players
Note:
See TracChangeset
for help on using the changeset viewer.