初学者cocos2dx 写2048 为了和大家一起分享

第一个是在头文件 

部分的代码是学习不变  大多数写自己。

class HelloWorld : public cocos2d::CCLayer
{
public:

    virtual bool init();  
    static cocos2d::CCScene* scene();
    void menuCloseCallback(CCObject* pSender);
    CREATE_FUNC(HelloWorld); //以上为自己主动生成的代码
    bool doUp(); //实现上下左右移动功能
    bool doDown();
    bool doLeft();
    bool doRight();
    void createCardSprite(cocos2d::CCSize size);  //创建出一个4*4的精灵矩阵
    void HelloWorld:: Random_createCardSprite(); //随机生成数字 随机位置生成

    
    bool HelloWorld:: FullScreen(); //推断是否全屏充满了数字 而且不能移动
    bool HelloWorld:: GameOver();// 游戏结束
    void random_num(int x,int y);// 随机生成2跟4 
    
    void Random_createCardSprite_easy(int flag); // 设置这个函数的目的本来是想设置游戏难度 因为并未实现选难度的功能 所以 这个函数仅仅有仅仅有调用 Random_createCardSprite(int flag);的功能
    void HelloWorld:: Random_createCardSprite(int flag); //随机生成数字   有规律的生成  向上移动则在以下生成

private:int firstX,firstY,endX,endY; //触摸点的坐标 CardSprite *CardNum[4][4]; //创建 数字精力的数组对象 4*4};



class CardSprite: public cocos2d::CCSprite
{
public:
    virtual bool init();  
    static CardSprite* createCardSprite(int numbers,int width,int height,float CardSpriteX,float CardSpriteY); 
    CREATE_FUNC(CardSprite);
    int GetNumber();//取得这个精灵所代表的数字

    void SetNumber(int NewNumbers); //改动这个精灵所代表的数字
    void change_num_view(); //改变数字的外观 依据 数字大小转换颜色
private:
	int number; //这个精灵所代表的数字
	void NumberInit(int numbers,int width,int height,float X,float Y);  //初始化“数字”


    //定义显示数字的控件  
    cocos2d::CCLabelTTF *labelTTFCardNumber;  
  
    //显示背景  
    cocos2d::CCLayerColor *layerColorBG;
};







    
        

版权声明:本文博主原创文章,博客,未经同意不得转载。

原文地址:https://www.cnblogs.com/lcchuguo/p/4853374.html