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 codeBool 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 ;};