void SpriteBatchNodeTestPage::loadUI() { setTouchEnabled(true); setTouchMode(kCCTouchesOneByOne); auto winSize = CocosWindow::size(); auto origin = CocosWindow::origin(); const std::string pic("Images/grossini_dance_01.png"); size_t num(1000); /*for (size_t i=0; i<num; ++i) { auto dance = CCSprite::create(pic.c_str()); CCPoint pos; pos.x = winSize.width * CCRANDOM_0_1(); pos.y = winSize.height * CCRANDOM_0_1(); dance->setPosition(pos); addChildRaw(dance); }*/ CCSpriteBatchNode *batch = CCSpriteBatchNode::create(pic.c_str()); for (size_t i=0; i<num; ++i) { auto dance = CCSprite::createWithTexture(batch->getTexture()); CCPoint pos; pos.x = winSize.width * CCRANDOM_0_1(); pos.y = winSize.height * CCRANDOM_0_1(); dance->setPosition(pos); batch->addChild(dance); } ADD_CHILD(batch); }
void BloodFlashPage::loadUI() { setTouchEnabled(true); setTouchMode(kCCTouchesOneByOne); BloodFlashSprite *rs = BloodFlashSprite::create("DemoIcon/dog_small.png"); rs->setPosition(CocosWindow::center()); ADD_CHILD(rs); }
/****************************************************************************** **函数名称: mon_srch_menu **功 能: 代理服务菜单 **输入参数: ** ctx: 菜单对象 ** args: 附加参数 **输出参数: NONE **返 回: 代理服务菜单 **实现描述: **注意事项: **作 者: # Qifeng.zou # 2014.12.27 # ******************************************************************************/ menu_item_t *mon_srch_menu(menu_cntx_t *ctx, void *args) { menu_item_t *menu; menu = menu_creat(ctx, "Search Engine", NULL, menu_display, NULL, args); if (NULL == menu) { return NULL; } #define ADD_CHILD(ctx, menu, title, entry, func, exit, args) \ if (!menu_child(ctx, menu, title, entry, func, exit, args)) { \ return menu; \ } /* 添加子菜单 */ ADD_CHILD(ctx, menu, "Search word", NULL, mon_srch_word, NULL, args); ADD_CHILD(ctx, menu, "Search word - loop", NULL, mon_srch_word_loop, NULL, args); ADD_CHILD(ctx, menu, "Insert word", NULL, mon_insert_word, NULL, args); ADD_CHILD(ctx, menu, "Test connect", NULL, mon_srch_connect, NULL, args); return menu; }
/* * Solves the puzzle and prints results. * Returns 1 on success and 0 on nonexistence of a solution. */ static int solve(int *start, int *end) { Grid *root, *goal, *cur, *child, *iter, **result; Pqueue *pq; Set *visited; int goal_grid_code, child_code; int i, ch; int path_length; root = (Grid *) malloc(sizeof(Grid)); memcpy(root->g, start, sizeof(int) * 9); root->parent = NULL; root->hole = 1; root->depth = 0; goal = (Grid *) malloc(sizeof(Grid)); memcpy(goal->g, end, sizeof(int) * 9); goal_grid_code = grid_code(goal); get_correct_positions(goal); path_length = 0; i = 0; pq = pqueue_new(); visited = set_new(4); pqueue_insert(pq, root); set_insert(visited, grid_code(root)); while (!empty(pq)) { cur = pqueue_extract_min(pq); if (verbose) { fprintf(output, "%d.\n", ++i); fprintf(output, "Depth: %d\n", cur->depth); fprintf(output, "Grid:\n"); grid_print(output, cur); fprintf(output, "f: %2d\n", weight(cur)); fprintf(output, "\n"); } if (grid_code(cur) == goal_grid_code) break; ch = 0; #define ADD_CHILD() { \ child_code = grid_code(child); \ if (!set_contains(visited, child_code)) { \ set_insert(visited, child_code); \ pqueue_insert(pq, child); \ cur->child[ch++] = child; \ } else \ free(child); \ } /* Hole not on the left wall. */ if (cur->hole % 3 > 0) { child = make_child(cur); grid_move_hole(child, child->hole - 1); ADD_CHILD(); } /* Hole not on the right wall. */ if (cur->hole % 3 < 2) { child = make_child(cur); grid_move_hole(child, child->hole + 1); ADD_CHILD(); } /* Hole not on the top wall. */ if (cur->hole / 3 > 0) { child = make_child(cur); grid_move_hole(child, child->hole - 3); ADD_CHILD(); } /* Hole not on the bottom wall. */ if (cur->hole / 3 < 2) { child = make_child(cur); grid_move_hole(child, child->hole + 3); ADD_CHILD(); } #undef ADD_CHILD /* End of children character. */ cur->child[ch] = NULL; if (verbose) { fprintf(output, "Children:\n"); grid_children(output, cur); fprintf(output, "------------------------\n"); fprintf(output, "\n"); STEP(); } } if (grid_code(cur) != goal_grid_code) return 0; /* Collect result path. */ for (iter = cur; iter != NULL; iter = iter->parent) path_length ++; result = (Grid**) malloc(sizeof(Grid*) * path_length); i = path_length - 1; for (iter = cur; iter != NULL; iter = iter->parent) result[i--] = iter; if (verbose) fprintf(output, "Solution sequence:\n"); for (i = 0; i < path_length; i++) { grid_print(output, result[i]); STEP(); fprintf(output, "\n"); } /* Clean up. */ grid_dispose(root); set_dispose(visited); pqueue_dispose(pq); free(result); free(goal); return 1; }