Cocos2dx is a beginner. I wrote 2048 to share with you.

Source: Internet
Author: User

First, the header file

Most of the Code is self-written for reference and modification.


Class HelloWorld: public cocos2d: CCLayer {public: virtual bool init (); static cocos2d: CCScene * scene (); void menuCloseCallback (CCObject * pSender); CREATE_FUNC (HelloWorld ); // The above is the automatically generated code
Bool doUp (); // implement the function of moving up, down, left, right, and right (); bool doLeft (); bool doRight ();
Void createCardSprite (cocos2d: CCSize size); // create a 4*4 genie Matrix
Void HelloWorld: Random_createCardSprite (); // randomly generated numbers are randomly generated.
Bool HelloWorld: FullScreen (); // determines whether the full screen is full of numbers and cannot be moved.
Bool HelloWorld: GameOver (); // void random_num (int x, int y) after game completion; // randomly generate 2 and 4
Void Random_createCardSprite_easy (int flag); // The purpose of this function is to set the difficulty of the game. Because the difficulty selection function is not implemented, this function only calls Random_createCardSprite (int flag ); functions
Void HelloWorld: Random_createCardSprite (int flag); // randomly generated numbers are regularly generated and moved up.

Private: int firstX, firstY, endX, endY; // coordinate of the touch point CardSprite * CardNum [4] [4]; // create an array object 4*4} of numerical energy };



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 (); // obtain the void SetNumber (int NewNumbers) represented by this genie; // modify the number represented by this genie
Void change_num_view (); // Changes the appearance of a number. The color is private: int number. // void NumberInit (int numbers, int width, int height, float X, float Y); // initialize the "Number" // cocos2d: CCLabelTTF * labelTTFCardNumber; // Display Background cocos2d :: CCLayerColor * layerColorBG ;};


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.