[Cocos2dx] generate random licensing interface for landlords

Source: Internet
Author: User

Based on the first two algorithms, we then integrated the test and successfully tested the random licensing Effect of landlords. Here I tested several operations and it was quite random! Haha

:

Code:

 

# Include HelloWorldScene. h # include SimpleAudioEngine. h # include
 
  
# Include
  
   
Using namespace cocos2d; using namespace CocosDenshion; CCScene * HelloWorld: scene () {// 'Scene 'is an autorelease object CCScene * scene = CCScene: create (); // 'player' is an autorelisted object HelloWorld * layer = HelloWorld: create (); // add layer as a child to scene-> addChild (layer ); // return the scene return scene;} int socketHandle = 0; // create a BSD connection // ip and portint HelloWorld: connect (const cha R * ip, unsigned short port) {struct sockaddr_in sa; struct hostent * hp; hp = gethostbyname (ip); if (! Hp) {return-1;} memset (& sa, 0, sizeof (sa); memcpy (char *) & sa. sin_addr, hp-> h_addr, hp-> h_length); sa. sin_family = hp-> h_addrtype; sa. sin_port = HTONS (port); socketHandle = socket (sa. sin_family, SOCK_STREAM, 0); if (socketHandle <0) {printf (failed to create socket); return-1;} if (: connect (socketHandle, (sockaddr *) & sa, sizeof (sa) {printf (failed to connect socket); return-1;} CCLog (Client co Nnect OK! IP: % s: % d, ip, port); return 0 ;}// create thread int HelloWorld: threadStart () {int errCode = 0; do {pthread_attr_t tAttr; errCode = pthread_attr_init (& tAttr); CC_BREAK_IF (errCode! = 0); errCode = pthread_attr_setdetachstate (& tAttr, PTHREAD_CREATE_DETACHED); if (errCode! = 0) {pthread_attr_destroy (& tAttr); break;} // errCode = pthread_create (& threadHimi, & tAttr, thread_function, this);} while (0); return errCode ;} // on init you need to initialize your instancebool HelloWorld: init () {// 1. super init first if (! CCLayer: init () {return false;} // char * ip = 192.168.1.24; // unsigned short port = 5005; // int con = HelloWorld :: connect (ip, port); // if (con> 0) {// printf (error ); //} // else // {// printf (LOGIN successful); // ask director the window size CCSize size = CCDirector: shareddire () -> getWinSize (); CCSprite * bg = CCSprite: create(bg.jpg); bg-> setAnchorPoint (CCPointMake (0, 1); bg-> setPosition (CCP OintMake (0, size. height); bg-> setScaleX (0.58); this-> addChild (bg); CCSpriteFrameCache: sharedSpriteFrameCache ()-> addSpriteFramesWithFile (card. plist); CCSpriteBatchNode * batchNode = CCSpriteBatchNode: create (card. pvr. ccz); batchNode-> setPosition (CCPointZero); this-> addChild (batchNode); // for (int I = 1; I <= 13; I ++) // {// CCString * name = CCString: createwithformat(hong+d.png, I); // CCSprite * card1 = C CSprite: createWithSpriteFrameName (name-> getCString (); // card1-> setScale (0.7); // card1-> setPosition (CCPointMake (140 + I * 15, size. height/2-95); // batchNode-> addChild (card1); //} CCSprite * role = CCSprite: createWithSpriteFrameName(role.png); role-> setScale (0.6 ); role-> setPosition (CCPointMake (60, 80); batchNode-> addChild (role); CCSprite * role1 = CCSprite: createWithSpriteFrameName(role1.png); ro Le1-> setScale (0.5); role1-> setPosition (CCPointMake (60,220); batchNode-> addChild (role1); CCSprite * role2 = CCSprite: createWithSpriteFrameName(role1.png ); role2-> setScale (0.5); role2-> setPosition (CCPointMake (420,220); batchNode-> addChild (role2); // left card for (int I = 2; I <= 13; I ++) {CCSprite * card1 = CCSprite: createWithSpriteFrameName(SmallCardBack1.png); card1-> setScale (0.6); card1-> setRotation (-82); Card1-> setPosition (CCPointMake (115 + I, size. height/2-13 + I * 11); batchNode-> addChild (card1);} // right card for (int I = 2; I <= 13; I ++) {CCSprite * card1 = CCSprite: worker); card1-> setScale (0.6); card1-> setRotation (82); card1-> setPosition (CCPointMake (365-i, size. height/2-13 + I * 11); batchNode-> addChild (card1);} // play music CCMenuItemImage * pCloseItem = CCMenuItemImage: create (CloseNormal.png, CloseSelected.png, this, menu_selector (HelloWorld: menuCloseCallback); pCloseItem-> setPosition (ccp (CCDirector: shareddire()-> getWinSize (). width/2, size. height-20); CCMenu * pMenu = CCMenu: create (pCloseItem, NULL); pMenu-> setPosition (CCPointZero); this-> addChild (pMenu, 1 ); // draw the card xipai (); // call the shuffling algorithm // card for (int I = 0; I <17; I ++) {pai [I] = data [I];} printf (------); for (int I = 0; I <17; I ++) {printf (% d, pai [I]);} int * p = pai; Sort (p, 17 ); printf (------); for (int I = 0; I <17; I ++) {printf (% d, pai [I]);} // draw the card for (int I = 0; I <17; I ++) {// if (pai [I] = 53) {// printf (111); CCString * name = CCString: createWithFormat(BigJoker.png); CCSprite * card1 = CCSprite: createWithSpriteFrameName (name-> getCString ()); card1-> setScale (0.7); card1-> setPosition (CCPointMake (140 + I * 15, Size. height/2-95); batchNode-> addChild (card1);} // John else if (pai [I] = 52) {// printf (222 ); CCString * name = CCString: createWithFormat(smlJoker.png); CCSprite * card1 = CCSprite: createWithSpriteFrameName (name-> getCString (); card1-> setScale (0.7 ); card1-> setPosition (CCPointMake (140 + I * 15, size. height/2-95); batchNode-> addChild (card1);} else {int huase = pai [I]/13 + 1; int value = pai [I] % 13 + 1; // card Value: char * s = NULL; switch (huase) {case 1: // CCString * name = CCString: createwithformat(hong+d.png, I); s = Hong; break; case 2: // CCString * name = CCString: createwithformat(fan1_d.png, I); s = Fan; break; case 3: // CCString * name = CCString: createwithformat(mei1_d.png, I ); s = Mei; break; case 4: // CCString * name = CCString: createwithformat(hei+d.png, I); s = Hei; break; default: break;} printf (% S‑d.png, s, value); // printf (% d, % d, huase, value); CCString * name = CCString: createwithformat(‑s‑d.png, s, value ); CCSprite * card1 = CCSprite: createWithSpriteFrameName (name-> getCString (); card1-> setScale (0.7); card1-> setPosition (CCPointMake (140 + I * 15, size. height/2-95); batchNode-> addChild (card1) ;}} bgMusic = true; return true ;}// play music void HelloWorld: menuCloseCallback (CCObject * pSender) {// CCDirector: SharedDirector ()-> end (); // # if (CC_TARGET_PLATFORM = CC_PLATFORM_IOS) // exit (0); // # endif bgMusic =! BgMusic; if (bgMusic) {SimpleAudioEngine: sharedEngine ()-> pauseBackgroundMusic ();} else {// play scene music SimpleAudioEngine: sharedEngine ()-> playBackgroundMusic(bg.mp3, true) ;}} void HelloWorld: xipai () {for (int I = 0; I <54; I ++) {data [I] = I ;} // random number // shuffling for (int I = 0; I <154; I ++) {int t1 = arc4random () % 54; int t2 = arc4random () % 54; int temp = data [t1]; int data1 = data [t1]; int data2 = data [t2]; data [t1] = data2; data [t2] = temp ;} printf (after shuffling :); for (int I = 0; I <54; I ++) {printf (% d, data [I]) ;}} void HelloWorld :: sort (int * array, int length) {int temp; bool hasExchangeAction; for (int I = 0; I
   
    

 

 

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.