I will share a little game of "continuous watching", cocos2dx and cocos2dx.
First:
It is worth studying in designing algorithms! But I have no patience, so I will leave it alone! If not, paste the code first:
# Include "GameScene. h" GameScene: GameScene (void) {this-> selected =-1;} GameScene ::~ GameScene (void) {} bool GameScene: init () {CCSize base_coord = CCSize (570,46); CCLayer: init (); CCSize visibleSize = CCDirector: shareddire () -> getVisibleSize (); this-> background = CCSprite: create ("board.png"); this-> background-> setPosition (CCSize (visibleSize. width/2, visibleSize. height/2); this-> addChild (this-> background); for (int I = 0; I <8; I ++) {for (int j = 0; j <8; j ++) {ItemNode * node = new ItemNo De (this, I * 8 + j); node-> init (); node-> setPosition (CCSize (base_coord.width + (node-> getContentSize (). width + 2) * I, base_coord.height + (node-> getContentSize (). height + 2) * j); this-> addChild (node); this-> item_vect.push_back (node) ;}return true ;} void GameScene: update (float tick) {} void GameScene: set_selected (int id) {if (this-> selected! =-1) {ItemNode * node = this-> item_vect [this-> selected]; if (node! = NULL) {node-> un_select ();} ItemNode * new_node = this-> item_vect [id]; if (node-> get_index () = new_node-> get_index () & this-> is_node_reach (id, selected) {new_node-> setVisible (false); node-> setVisible (false); this-> selected =-1; return ;}} this-> selected = id;} int GameScene: get_selected () {return this-> selected;} bool GameScene: is_node_reach (int start, int end) {if (start = end) {return fals E;} int start_x = start/8; int start_y = start % 8; int end_x = end/8; int end_y = end % 8; int result = 0; result = abs (start_x-end_x) + abs (start_y-end_y); if (result = 1) {return true;} if (start_x = end_x) {if (start_y> end_y) {int temp = start_y; start_y = end_y; end_y = temp;} bool is_reach = true; for (int I = start_y + 1; I <end_y; I ++) {ItemNode * node = this-> item_vect [start_x * 8 + I]; if (node-> isVisible () {is_reach = false ;}} if (is_reach) {return true ;}} if (start_y = end_y) {bool is_reach = true; if (start_x> end_x) {int temp = start_x; start_x = end_x; end_x = temp;} for (int I = start_x + 1; I <end_x; I ++) {ItemNode * node = this-> item_vect [I * 8 + start_y]; if (node-> isVisible () {is_reach = false ;}} if (is_reach) {return true ;}{// corner detection // start_x, s Tart_y // end_x, end_y // start_x, end_y // end_x, start_y if (is_coord_reach (start_x, start_y, end_x, end_y) {return true ;}} return false ;} bool GameScene: is_coord_reach (int start_x, int start_y, int end_x, int end_y) {if (start_x> end_x) {int temp = start_x; start_x = end_x; end_x = temp ;} if (start_y> end_y) {int temp = start_y; start_y = end_y; end_y = temp ;}{ bool is_reach = true; for (int I = start _ X + 1; I <end_x; I ++) {ItemNode * node = this-> item_vect [I * 8 + start_y]; if (node-> isVisible ()) {is_reach = false ;}}for (int I = start_y + 1; I <end_y; I ++) {ItemNode * node = this-> item_vect [end_x * 8 + I]; if (node-> isVisible () {is_reach = false ;}} if (is_reach) {return true ;}{ bool is_reach = true; for (int I = start_y + 1; I <end_y; I ++) {ItemNode * node = this-> item_vect [start_x * 8 + I]; if (node -> IsVisible () {is_reach = false ;}} for (int I = start_x + 1; I <end_x; I ++) {ItemNode * node = this-> item_vect [I * 8 + end_y]; if (node-> isVisible () {is_reach = false;} if (is_reach) {return true ;}} return false;} bool GameScene: is_coord_reach_ I (int start_x, int start_y, int end_x, int end_y) {return true;} # include "ItemNode. h "# include" GameStruct. h "# include" GameScene. h "ItemNode: ItemNode (GameScen E * scene, int id) {this-> scene = scene; this-> index = 0; this-> image = NULL; this-> background = NULL; this-> id = id;} ItemNode ::~ ItemNode (void) {} bool ItemNode: init () {CCNode: init (); this-> index = rand () % 7; this-> image = CCSprite :: create (item_file_name [this-> index]. c_str (); CCSize item_size = this-> image-> getContentSize (); this-> setContentSize (item_size); this-> image-> setPosition (CCSize (item_size.width/2, item_size.height/2); this-> addChild (this-> image); return true;} void ItemNode: onEnter () {CCDirector * pDirector = CCDire Ctor: sharedDirector (); pDirector-> getTouchDispatcher ()-> addTargetedDelegate (this,-128, false); CCNode: onEnter ();} void ItemNode: onExit () {CCDirector * pDirector = CCDirector: sharedDirector (); pDirector-> getTouchDispatcher ()-> removeDelegate (this); CCNode: onExit ();} int ItemNode: get_index () {return this-> index;} void ItemNode: selected () {this-> background = CCSprite: create ("selector.png"); this-> Background-> setPosition (CCSize (background-> getContentSize (). width/2, background-> getContentSize (). height/2); this-> addChild (this-> background);} void ItemNode: un_select () {if (this-> background! = NULL) {this-> removeChild (this-> background) ;}} bool ItemNode: is_in_sprite (CCTouch * touch) {CCPoint touchPoint = touch-> getLocation (); CCPoint reallyPoint = this-> convertToNodeSpace (touchPoint); CCRect rect = this-> boundingBox (); if (rect. containsPoint (touchPoint) {return true;} return false;} bool ItemNode: ccTouchBegan (CCTouch * touch, CCEvent * event) {if (this-> isVisible ()) {if (this-> is_in_sprite (touch) {this-> scene-> set_selected (this-> id); this-> selected () ;}} return true ;} void ItemNode: ccTouchMoved (CCTouch * touch, CCEvent * event) {} void ItemNode: ccTouchEnded (CCTouch * touch, CCEvent * event ){}
I can't write it like this anymore. I'm going to talk about some business! Make money!