本文整理汇总了C++中CCArray::randomObject方法的典型用法代码示例。如果您正苦于以下问题:C++ CCArray::randomObject方法的具体用法?C++ CCArray::randomObject怎么用?C++ CCArray::randomObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCArray
的用法示例。
在下文中一共展示了CCArray::randomObject方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
bool Troop::init() {
do {
CC_BREAK_IF(!CCLayer::init());
this->autorelease();
removeQueue = CCArray::create();
removeQueue->retain();
petTypes = Utils::getPetTypes();
//init pets array
pets = CCArray::createWithCapacity(2 * cap);
vlinks = CCArray::createWithCapacity(cap);
hlinks = CCArray::createWithCapacity(cap);
pets->retain();
vlinks->retain();
hlinks->retain();
//todo: 可能出现某一个节点没有可用类型的情况,这种情况重新初始化
for (int i = 0; i < cap; i++) {
vlinks->addObject(CCArray::create());
hlinks->addObject(CCArray::create());
CCArray* availTypes = CCArray::createWithArray(petTypes);
int v = i;
int h = i;
for (int j = i - col; j >= 0 && j >= i - 2*col; j -= col) {
CCArray* vlink = (CCArray*)vlinks->objectAtIndex(j);
int size = vlink->count();
if (size == 0) {
continue;
} else if (size >= 2) {
Utils::removeStringFromArray(availTypes, ((Pet*)vlink->objectAtIndex(0))->getType());
break;
}
}
if (i%col != 0) {
for (int j = i - 1; j >= 0 && j >= i - 2; j--) {
CCArray* hlink = (CCArray*)hlinks->objectAtIndex(j);
int size = hlink->count();
if (size == 0) {
continue;
} else if (size >= 2) {
Utils::removeStringFromArray(availTypes, ((Pet*)hlink->objectAtIndex(0))->getType());
break;
}
}
}
CCString* petType = (CCString*)availTypes->randomObject();
if (i >= col && petType->isEqual(getPetAtIndex(i - col)->getType())) {
v -= col;
}
if (i > 0 && i % 7 != 0 && petType->isEqual(getPetAtIndex(i - 1)->getType())) {
h--;
}
Pet* pet = new Pet(petType, i);
pet->setVLink(v);
pet->setHLink(h);
((CCArray*)vlinks->objectAtIndex(v))->addObject(pet);
((CCArray*)hlinks->objectAtIndex(h))->addObject(pet);
pets->addObject(pet);
int c = i % 7;
int r = 3 - i / 7;
pet->setPosition(ccp(Unit::GRID_SIZE * c + Unit::GRID_SIZE/2, Unit::GRID_SIZE * r + Unit::GRID_SIZE/2));
addChild(pet);
}
for (int i = cap; i < 2 * cap; i++) {
pets->addObject(Pet::createFakePet());
}
selectedPet = NULL;
return true;
} while (0);
return false;
}