- Timestamp:
- Dec 27, 2012, 7:04:49 PM (12 years ago)
- Branches:
- master
- Children:
- 0333211, 3a79253
- Parents:
- 5066e27
- Location:
- common
- Files:
-
- 2 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 -
common/Player.h
r5066e27 r01d0d00 19 19 class Player { 20 20 public: 21 Player(); 22 Player(const Player& p); 21 23 Player(string name, string password); 22 24 Player(string name, sockaddr_in addr); // this will be deleted 25 23 26 ~Player(); 24 27 … … 26 29 void deserialize(char* buffer); 27 30 31 void setId(int id); 28 32 void setAddr(sockaddr_in addr); 29 33 34 int id; 30 35 string name; 31 36 string password;
Note:
See TracChangeset
for help on using the changeset viewer.