Changeset 01d0d00 in network-game for common/Player.cpp
- Timestamp:
- Dec 27, 2012, 7:04:49 PM (12 years ago)
- Branches:
- master
- Children:
- 0333211, 3a79253
- Parents:
- 5066e27
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
common/Player.cpp
r5066e27 r01d0d00 7 7 using namespace std; 8 8 9 Player::Player() 10 { 11 this->id = 0; 12 this->name = ""; 13 this->password = ""; 14 this->pos.x = 0; 15 this->pos.y = 0; 16 } 17 18 Player::Player(const Player& p) 19 { 20 this->id = p.id; 21 this->name = p.name; 22 this->password = p.password; 23 this->pos.x = p.pos.x; 24 this->pos.y = p.pos.y; 25 this->addr = p.addr; 26 } 27 9 28 Player::Player(string name, string password) 10 29 { 30 this->id = 0; 11 31 this->name = name; 12 32 this->password = password; 13 33 this->pos.x = 200; 14 34 this->pos.y = 200; 15 16 cout << "Created new player: " << this->name << endl;17 35 } 18 36 19 37 Player::Player(string name, sockaddr_in addr) 20 38 { 39 this->id = 0; 21 40 this->name = name; 22 41 this->password = ""; … … 24 43 this->pos.y = 200; 25 44 this->addr = addr; 26 27 cout << "Created new played: " << this->name << endl;28 45 } 29 46 … … 36 53 ostringstream oss; 37 54 55 oss.write((char*)&(this->id), sizeof(int)); 38 56 oss << this->name; 39 57 oss.write("\0", 1); … … 49 67 iss.str(buffer); 50 68 69 iss.read((char*)&(this->id), sizeof(int)); 51 70 iss >> this->name; 52 71 iss.read((char*)&(this->pos.x), sizeof(int)); 53 72 iss.read((char*)&(this->pos.y), sizeof(int)); 73 } 74 75 void Player::setId(int id) 76 { 77 this->id = id; 54 78 } 55 79
Note:
See TracChangeset
for help on using the changeset viewer.