void TestScene::breadthFirstSearch(cocos2d::CCPoint playerPos, cocos2d::CCPoint npcPos, TileObject **tileArray, cocos2d::CCSize mapSize){ CCPoint npcCoord = tileCoordForPosition(npcPos, tileMap); CCPoint playerCoord = tileCoordForPosition(playerPos, tileMap); std::queue<TileObject*>* listCheckedTiles = new std::queue<TileObject*>; TileObject* u = &tileArray[(int)npcCoord.x][(int)npcCoord.y]; u->setPreTile(NULL); u->setIsCheck(true); CCArray* nextArrayTile = new CCArray; nextArrayTile->autorelease(); listCheckedTiles->push(u); while (!listCheckedTiles->empty()) { TileObject* v = listCheckedTiles->front(); listCheckedTiles->pop(); nextArrayTile = next(v, tileArray, mapSize); CCObject* obj; CCARRAY_FOREACH(nextArrayTile, obj){ TileObject* u = dynamic_cast<TileObject*>(obj); if (u->getIsCheck() == false) { u->setIsCheck(true); u->setPreTile(v); listCheckedTiles->push(u); if (u->getXCoord() == playerCoord.x && u->getYCoord() == playerCoord.y) { return; } } } }
CCArray* CCFileUtils::arrayWithContentsOfFile(const char* pFileName) { //convert to full path std::string fileFullPath; fileFullPath = CCFileUtils::fullPathFromRelativePath(pFileName); CCArray* ret = arrayWithContentsOfFileThreadSafe(fileFullPath.c_str()); ret->autorelease(); return ret; }
CCArray* CCArray::createWithObject(CCObject* pObject) { CCArray* pArray = new CCArray(); if (pArray && pArray->initWithObject(pObject)) { pArray->autorelease(); } else { CC_SAFE_DELETE(pArray); } return pArray; }
CCArray* CCArray::create() { CCArray* pArray = new CCArray(); if (pArray && pArray->init()) { pArray->autorelease(); } else { CC_SAFE_DELETE(pArray); } return pArray; }
CCArray* CCArray::arrayWithArray(CCArray* otherArray) { CCArray* pArray = new CCArray(); if (pArray && pArray->initWithArray(otherArray)) { pArray->autorelease(); } else { CC_SAFE_DELETE(pArray); } return pArray; }
CCArray* CCArray::arrayWithCapacity(unsigned int capacity) { CCArray* pArray = new CCArray(); if (pArray && pArray->initWithCapacity(capacity)) { pArray->autorelease(); } else { CC_SAFE_DELETE(pArray); } return pArray; }
CCArray* createCCArrayWithData(unsigned char* data) { CCAssert((data),"data must not be NULL!!!"); CCDictMaker tMaker; CCArray* array = tMaker.arrayWithData(data); if (array != NULL) { array->autorelease(); } CC_SAFE_DELETE_ARRAY(data); return array; }
CCArray* TestScene::next(TileObject *u, TileObject **tileArray, cocos2d::CCSize mapSize){ CCArray* nextArray = new CCArray; nextArray->autorelease(); int x = u->getXCoord(); int y = u->getYCoord(); // left int x1, y1; x1 = x - 1; y1 = y; if ( (x1 >= 0 && x1 < mapSize.width) && (y1 >= 0 && y1 < mapSize.height) && (tileArray[x1][y1].getWall() % 2) == 0) { TileObject* tile = &tileArray[x1][y1]; nextArray->addObject(tile); } //up x1 = x; y1 = y -1; if ( (x1 >= 0 && x1 < mapSize.width) && (y1 >= 0 && y1 < mapSize.height) && tileArray[x1][y1].getWall() < 2 ) { TileObject* tile = &tileArray[x1][y1]; nextArray->addObject(tile); } //right x1 = x + 1; y1 = y; if ( (x1 >= 0 && x1 < mapSize.width) && (y1 >= 0 && y1 < mapSize.height) && (u->getWall() % 2) == 0 ) { TileObject* tile = &tileArray[x1][y1]; nextArray->addObject(tile); } //down x1 = x; y1 = y + 1; if ( (x1 >= 0 && x1 < mapSize.width) && (y1 >= 0 && y1 < mapSize.height) && (u->getWall() < 2) ) { TileObject* tile = &tileArray[x1][y1]; nextArray->addObject(tile); } return nextArray; }
CCArray* CGridView::getCells() { CCArray* pArray = new CCArray(); pArray->initWithCapacity(10); if( !m_lCellsUsed.empty() ) { list<CGridViewCell*>::iterator iter = m_lCellsUsed.begin(); for(; iter != m_lCellsUsed.end(); ++iter) { pArray->addObject(*iter); } } pArray->autorelease(); return pArray; }
CCArray* CListView::getNodes() { CCArray* pArray = new CCArray(); pArray->initWithCapacity(10); if( !m_vNodeList.empty() ) { vector<CCNode*>::iterator iter = m_vNodeList.begin(); vector<CCNode*>::iterator iend = m_vNodeList.end(); for(; iter != iend; ++iter ) { pArray->addObject(*iter); } } pArray->autorelease(); return pArray; }
void INSPayment_iOS::loadProducts(inewsoft::ol::LoadProductCallback callback) { if(!this->productTable.empty() && productsState == inewsoft::ol::kProductsStateLoaded) { callback(true); return; } else if(this->productsState == inewsoft::ol::kProductsStateLoading) { this->loadProductCallback = callback; return; } /// loald product from developer server firstly this->productsState = inewsoft::ol::kProductsStateLoading; Payment::loadProducts([this, callback](bool succeed){ if(succeed) { INSStore::sharedStore()->registerTransactionObserver(this); CCArray* productsId = new CCArray(); productsId->autorelease(); for(auto iter = this->productTable.begin(); iter != this->productTable.end(); ++iter) { productsId->addObject(newCCString(iter->second.id.c_str())); } this->loadProductCallback = callback; INSStore::sharedStore()->loadProducts(productsId, this); } else { this->productsState = inewsoft::ol::kProductsStateUnload; callback(false); } }); }