模拟cocos2d-x 代理模式

前端之家收集整理的这篇文章主要介绍了模拟cocos2d-x 代理模式前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

根据cocos2d-x的代理模式,仿写一遍。


class CCApplicationProtocol
{
public:
      virtual bool applicationDidFinishLaunching() = 0;
};

class CCApplication :public CCApplicationProtocol
{
public:
    static CCApplication* instance ;
    CCApplication()
    {
        //这里的this是CCApplication子类里面的对象
        instance =  this;
    }
    ~CCApplication()
    {

    }
    void run()
    {
        applicationDidFinishLaunching();
    }
    static CCApplication* getInstance()
    {
        return instance;
    }
};
CCApplication* CCApplication::instance = NULL;

/**
 * @brief The Android class
 * android 平台实现
 */
class Android:private CCApplication
{
public:
    bool applicationDidFinishLaunching()
    {
        cout<<"this is android"<<endl;
        return true;
    }
};

/**
 * @brief The Linux class
 * Linux 平台的实现
 */
class Linux:private CCApplication
{
public:
    bool applicationDidFinishLaunching()
    {
        cout<<"this is Linux"<<endl;
        return true;
    }
};

/**
 * @brief The Ios class
 * IOS 平台的实现
 */
class Ios:private CCApplication
{
public:
    bool applicationDidFinishLaunching()
    {
        cout<<"this is IOS"<<endl;
        return true;
    }
};

/**
 * @brief The Ios class
 * win32 平台的实现
 */
class Windows:private CCApplication
{
public:
    bool applicationDidFinishLaunching()
    {
        cout<<"this is windows"<<endl;
        return true;
    }
};


@H_502_10@Android平台实现的调用





@H_502_10@Linux平台实现的调用(后面创建的对象会覆盖前面创建的对象)。




@H_502_10@IOS平台





@H_502_10@win32平台

猜你在找的Cocos2d-x相关文章