本文整理汇总了C++中Place::getBeingsByName方法的典型用法代码示例。如果您正苦于以下问题:C++ Place::getBeingsByName方法的具体用法?C++ Place::getBeingsByName怎么用?C++ Place::getBeingsByName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Place
的用法示例。
在下文中一共展示了Place::getBeingsByName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: execute
void AttackAction::execute(Player *player, Command *command, Game *game) {
Place *location = player->getLocation();
BeingListCItPair beings = location->getBeingsByName(command->getDirectObject());
if (beings.begin == beings.end) {
player->out("display") << "There is no " << command->getDirectObject()
<< " here!" << endl;
return;
}
try {
string weaponName = command->getIndirectObject();
Object *weapon = 0;
Being *defender =
Entity::clarifyEntity<BeingListCItPair, BeingListCIt, Being *>(beings,
player);
if (weaponName.length() > 0) {
ObjectListCItPair items = player->getInventoryObjectsByName(weaponName);
if (items.begin == items.end) {
player->out("display") << "You don't have a " << weaponName << "!" << endl;
return;
}
try {
weapon =
Entity::clarifyEntity<ObjectListCItPair, ObjectListCIt, Object *>(items,
player);
// TODO: this check should be made inside Being (we'd have an
// exception to catch)
if (!weapon->isWeapon()) {
player->out("display") << "The " << weaponName << " isn't a weapon!" << endl;
return;
}
}
catch (string name) {
player->out("display") << "You don't have a " << weaponName << "!" << endl;
return;
}
}
player->attack(defender, weapon);
}
catch (string name) {
player->out("display") << "There is no " << name << " here!" << endl;
}
}