当前位置: 首页>>代码示例>>C++>>正文


C++ Place::getBeingsByName方法代码示例

本文整理汇总了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;
      }
   }
开发者ID:Ockin,项目名称:trogdor-pp,代码行数:56,代码来源:actions.cpp


注:本文中的Place::getBeingsByName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。