本文整理汇总了C++中Human::getID方法的典型用法代码示例。如果您正苦于以下问题:C++ Human::getID方法的具体用法?C++ Human::getID怎么用?C++ Human::getID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Human
的用法示例。
在下文中一共展示了Human::getID方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onPlayersData
void Game::onPlayersData(sf::Packet & packet)
{
std::cout << "players data received!\n";
Entity::Type myType;
packet >> myType;
if (myType == Entity::Type::Zombie)
{
Entity::ID myID;
packet >> myID;
Zombie * me = mGameWorld.createEntity<Zombie>(myID, myType);
mGameWorld.setPlayerEntity(me->getID());
mPlayer.setEntity(me);
sf::Int32 humanCount;
packet >> humanCount;
std::cout << "You are the zombie! human count: " << humanCount << std::endl;
for (sf::Int32 i = 0; i < humanCount; ++i)
{
Entity::ID id;
packet >> id;
Human * h = mGameWorld.createEntity<Human>(id, Entity::Type::Human);
mGameWorld.addEntity(h->getID());
}
}
示例2: initializePlayers
void Game::initializePlayers()
{
//send game map data
//send players data
sf::Packet * packet = new sf::Packet;
*packet << Sv::GameMapData << mGameWorld.mGameMap.getName();
const std::vector<Entity *> & walls = mGameWorld.getEntitiesOfType(Entity::Type::Wall);
*packet << sf::Int32(walls.size());
for (Entity * e : walls)
{
*packet << e->getID();
*packet << e->getPosition().x << e->getPosition().y << e->getSize().x << e->getSize().y;
}
pushPacket(nullptr, packet, true);
//========================================//
std::vector<Peer *> players;
for (auto & player : mPlayers)
players.push_back(player.first);
//choose a zombie
Zombie * z = mGameWorld.createEntity<Zombie>(Entity::Type::Zombie);
Peer * zombiePlayer = players[thor::random(0u, players.size() - 1)];
mGameWorld.addEntity(z->getID());
mGameWorld.mEntitiesByPeer[zombiePlayer] = z->getID();
//remove the zombie player from players vector
players.erase(std::remove(players.begin(), players.end(), zombiePlayer), players.end());
//rest are human
for (Peer * human : players)
{
Human * h = mGameWorld.createEntity<Human>(Entity::Type::Human);
mGameWorld.mEntitiesByPeer[human] = h->getID();
mGameWorld.addEntity(h->getID());
}
//@zombie
sf::Packet * packet2 = new sf::Packet; //zombie id, other human player size
*packet2 << Sv::PlayersData << Entity::Type::Zombie << z->getID() << sf::Int32(players.size());
for (Peer * human : players)
{
//id,
*packet2 << mGameWorld.mEntitiesByPeer[human];
}
pushPacket(zombiePlayer, packet2);
std::cout << "Zombie ID: " << z->getID() << "Human count: " << players.size() << std::endl;
//@human
for (Peer * human : players)
{
sf::Packet * packet3 = new sf::Packet; // zombie id player id other human player size
*packet3 << Sv::PlayersData << Entity::Type::Human << z->getID() << mGameWorld.mEntitiesByPeer[human] << sf::Int32(players.size() - 1);
//insert other's players info
for (Peer * human2 : players)
{ //other player's id
if (human2 != human)
*packet3 << mGameWorld.mEntitiesByPeer[human2];
}
pushPacket(human, packet3);
}
sf::Packet * packet4 = new sf::Packet;
*packet4 << Sv::StartGame;
pushPacket(nullptr, packet4, true);
}