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


C++ MapObject::addObserver方法代码示例

本文整理汇总了C++中MapObject::addObserver方法的典型用法代码示例。如果您正苦于以下问题:C++ MapObject::addObserver方法的具体用法?C++ MapObject::addObserver怎么用?C++ MapObject::addObserver使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MapObject的用法示例。


在下文中一共展示了MapObject::addObserver方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: produceAndRegisterMapObject

void UnitFactory::produceAndRegisterMapObject(const std::string& objectType, int owner, const MPoint& pos) {
    MapObject* object;
    MapObjectView* view;
    std::vector<UnitModel*> units;
    std::vector<int> actions;
    int image = 0;
    int layer = 0;
    
    if (objectType == "village") {
        image = 4; layer = MapLayer::BUILDING;
        object = new MapObject(MapObjectCategory::CITY, pos, owner, actions);
    } else if (objectType == "dungeon") {
        image = 5; layer = MapLayer::BUILDING;
        object = new MapObject(MapObjectCategory::DUNGEON, pos, owner, actions);
    } else if (objectType == "party") {
        layer = MapLayer::UNIT;
        if (owner == 1) {
            image = 1;
        } else {
            image = 6;
        }
        
        actions.push_back(ActionNS::AACTION_MOVE); actions.push_back(ActionNS::AACTION_FIGHT);
        actions.push_back(ActionNS::AACTION_SHOP); actions.push_back(ActionNS::AACTION_ENTERDUNGEON);
        actions.push_back(ActionNS::AACTION_INVENTORY);
        units.push_back(produceUnit("swordsman", owner, MPointMake(1,1)));
        units.push_back(produceUnit("channeler", owner, MPointMake(1,0)));
        object = new PartyModel(MapObjectCategory::PARTY, pos, owner, actions, units);
    } else {
        return;
    }
    
    view = new MapObjectView(object, 64.0f, 64.0f, image, layer);
    object->addObserver(view);
    
    ModelManager::instance()->addMapObject(object);
    ViewControllerManager::instance()->add(view);
}
开发者ID:mickeprag,项目名称:hex-game,代码行数:38,代码来源:UnitFactory.cpp


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