Beginner COCOS2DX Write 2048 to share with everyone

Source: Internet
Author: User

The first one is in the header file

Part of the code is learning the same as most write yourself.

class      Helloworld:public cocos2d::cclayer{public:virtual BOOL Init ();    Static cocos2d::ccscene* scene ();    void Menuclosecallback (ccobject* psender); Create_func (HelloWorld); The above for their own initiative generated code bool Doup ();    Implement up and down move function bool Dodown ();    BOOL Doleft ();    BOOL Doright ();  void Createcardsprite (cocos2d::ccsize size); Create a 4*4 elf matrix void HelloWorld:: Random_createcardsprite (); Randomly generated digital random position generated bool HelloWorld:: Fullscreen (); Infer if full screen is full of numbers and cannot move bool HelloWorld:: Gameover ();//Game over void random_num (int x,int y);//randomly generate 2 and 4 void Rando M_createcardsprite_easy (int flag); The purpose of setting this function is to set the difficulty of the game because it does not implement the ability to choose the difficulty, so this function only has to call Random_createcardsprite (int flag); function void HelloWorld:: Random_crea Tecardsprite (int flag); Random generation of the regular generation of numbers to move upward is generated in the following Private:int Firstx,firsty,endx,endy; Touch point coordinates cardsprite *CARDNUM[4][4]; Create an array object with digital energy 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 ();//Get the number represented by this Genie    void Setnumber (int newnumbers);//change the number represented by this Genie    void Change_num_view (); Change the appearance of a number by the number size to convert the color private:int numbers; The figure represented by this genie is void numberinit (int numbers,int width,int height,float x,float Y);  Initializes the "number"    //definition control that displays the number      Cocos2d::cclabelttf *labelttfcardnumber;        Show background      cocos2d::cclayercolor *LAYERCOLORBG;};


 
 
 
 
 
 

copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.

Beginner COCOS2DX write 2048 to share with everyone

Related Article

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.