Cocos2d-x Development of Chinese Chess "12" game results show and hide

Source: Internet
Author: User
Tags addchild

Implemented in the previous section of the game to achieve playing background music, this section will achieve the game results display and hide

Check it out first.

When the player wins, it will show the player's winning dialog box.


dialog boxes and checkers are hidden when you click on the dialog box


Change the color of the player's pieces after clicking Start


When the player loses, it will show the player loses the dialog box


The idea of the game result realization:

1, when the player wins, display a dialog box, the content of the dialog box is "Congratulations, you won."

2, when the player loses, display a dialog box, the contents of the dialog box is "Sorry, you lost."

3. When the dialog box is clicked, the dialog box is hidden and the pawn is hidden.

4. When you click Start, you will find the color of the player's pieces changed.


Implementation code:

In the Scenegame class, in member function init (), add the following code to implement the Create game results box

    Create sprite Display game result    Sprite  = ccsprite::create ("Yingjiemian.png");    Sprite1 = Ccsprite::create ("Shuijiemian.png");    AddChild (sprite);    AddChild (sprite1);    Sprite->setposition (CCP (WINSIZE.WIDTH/2, Winsize.height));    Sprite1->setposition (CCP (WINSIZE.WIDTH/2, Winsize.height));        Hide result    sprite->setvisible (false);    Sprite1->setvisible (false);    Indicates that the game result is not displayed    visible = false;


Create a member function Howresult (ccsprite* Sprite, Ccsize winsize) in Scenegame to display the game results box

Show game results void Scenegame::showresult (ccsprite* Sprite, ccsize winsize) {     //Show game result prompt box    sprite->setvisible ( true);    Sprite->setzorder (+);    Visible = true;    ccmoveto*  move = ccmoveto::create (1, CCP (Sprite->getpositionx (), WINSIZE.HEIGHT/2));    Sprite->runaction (move);    }

Create a member function Hideresult (ccsprite* s, ccobject* obj) in Scenegame to hide the game result box

Hide game results void Scenegame::hideresult (ccsprite* s, ccobject* obj) {     //Get the dimensions of the window    ccsize winsize = ccdirector:: Shareddirector ()->getwinsize ();    Hide Game Results    s->setvisible (false);    Set the pawn to the initial position    S->setposition (CCP (WINSIZE.WIDTH/2, Winsize.height));    Visible = false;             Change the color of the player's pawn    _redside =! _redside;        Set red to go first    _redtrun = true;    Re-get a    new inning (obj);

In the Scenegame member function void Scenegame::movecomplete (ccnode* movetone, void* _killid) Add the following code to implement when the red handsome or black will be killed, the game Results dialog box is displayed

  When the kill will be the        if (stone::jiang  = = _s[killid]->gettype ())        {            //When the opponent's pawn is killed if            (_redside! = _s[ Killid]->getred ())            {                //Show Game Results                Showresult (Sprite, winsize);            }            else//when killed is the player's pawn            {                //Show Game Results                Showresult (sprite1, winsize);}        }


Add the following code in the bool Scenegame::cctouchbegan (cctouch* Ptouch, ccevent* pevent) to hide the result box after clicking on the game result box, hide the pawn, change the player's piece color

   When you touch the game Results box    if (Sprite->boundingbox (). Containspoint (ptinwin) && Visible = = True)      {        // Hide Results        hideresult (sprite, obj);    }        if (Sprite1->boundingbox (). Containspoint (ptinwin) && Visible = = True)    {          //Hide Results        hideresult (sprite1, obj);    }



Cocos2d-x Development of Chinese Chess "12" game results show and hide

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.