Ejemplo n.º 1
0
void GamePan::refreshWorldPad()
{
	CCNode* pBaseNode = m_pCcbNode->getChildByTag(kTagGamePanWordPan);
	CCNode* tabNode = pBaseNode->getChildByTag(kTagGamePanWordPanTabBase);
	CCNode* itemNode = pBaseNode->getChildByTag(kTagGamePanWordPanItemBase);
	CCLabelTTF* itemTemp = dynamic_cast<CCLabelTTF*>(itemNode->getChildByTag(kTagGamePanWordPanItemTitle));
	CCControlButton* tabItem = dynamic_cast<CCControlButton*>(tabNode->getChildByTag(kTagGamePanWordPanTabBaseItem));
	float itemWidth = tabItem->getContentSize().width+ITEM_SPACE;
	float itemHeight = tabItem->getContentSize().height+ITEM_SPACE;
	for(int i =0;i<MAX_LINE;i++)
	{
		for(int j =0;j<MAX_ROW;j++)
		{
			CCControlButton* item = CCControlButton::create();
			Utils::copyCCControlButton(item,tabItem);
			item->setPosition(ccp(tabItem->getPositionX()+j*itemWidth,tabItem->getPositionY()-i*itemHeight));
			item->setTag(j+i*MAX_ROW);
			tabNode->addChild(item);

			CCLabelTTF* title = Utils::copyCCLabelTTF(itemTemp);
			title->setPosition(item->getPosition());
			title->setTag(j+i*MAX_ROW);
			itemNode->addChild(title);
			CCString* str = (CCString*)_wordList->randomObject();
			title->setString(str->getCString());
			_wordList->removeObject(str);
		}
	}

	for(int i =0;i<MAX_LINE;i++)
	{
		for(int j =0;j<MAX_ROW;j++)
		{
			CCControlButton* item = dynamic_cast<CCControlButton*>(tabNode->getChildByTag(j+i*MAX_ROW));
			XCheckBox* pCheckBox = XCheckBox::create(item);
			pCheckBox->setTag(item->getTag());
			pCheckBox->setToggle(false);
			pCheckBox->setTarget(this, cccontrol_selector(GamePan::wordSelectCallbackCCControl));
			tabNode->addChild(pCheckBox);
			item->removeFromParent();
		}
	}
	itemTemp->removeFromParent();
	tabItem->removeFromParent();
	refreshLetter();
}
Ejemplo n.º 2
0
bool CCControlButtonTest_HelloVariableSize::init()
{
    if (CCControlScene::init())
    {
        CCSize screenSize = CCDirector::sharedDirector()->getWinSize();
        
        // Defines an array of title to create buttons dynamically
        CCArray *stringArray = CCArray::create(
            ccs("Hello"),
            ccs("Variable"),
            ccs("Size"),
            ccs("!"),
            NULL);
        
        CCNode *layer = CCNode::create();
        addChild(layer, 1);
        
        double total_width = 0, height = 0;
        
        // For each title in the array
        CCObject* pObj = NULL;
        CCARRAY_FOREACH(stringArray, pObj)
        {
            CCString* title = (CCString*)pObj;
            // Creates a button with this string as title
            CCControlButton *button = standardButtonWithTitle(title->getCString());
            button->setPosition(ccp (total_width + button->getContentSize().width / 2, button->getContentSize().height / 2));
            layer->addChild(button);
            
            // Compute the size of the layer
            height = button->getContentSize().height;
            total_width += button->getContentSize().width;
        }

        layer->setAnchorPoint(ccp (0.5, 0.5));
        layer->setContentSize(CCSizeMake(total_width, height));
        layer->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f));
        
        // Add the black background
        CCScale9Sprite *background = CCScale9Sprite::create("extensions/buttonBackground.png");
        background->setContentSize(CCSizeMake(total_width + 14, height + 14));
        background->setPosition(ccp(screenSize.width / 2.0f, screenSize.height / 2.0f));
        addChild(background);
        return true;
    }
void QuestionLayer::simulateAnswerRight()
{
    this->unschedule(schedule_selector(QuestionLayer::timerCB));

    CCDictionary* results = questionObj->rightAnswer;
    for (int i=0; i<results->allKeys()->count(); i++) {
        CCString* key = (CCString *)(results->allKeys()->objectAtIndex(i));
        results->setObject(CCString::createWithFormat("%d", 1), key->getCString());
    }

    //回答完成所有正确答案
    for (int i=0; i<results->allKeys()->count(); i++) {
        CCString* key = (CCString *)(results->allKeys()->objectAtIndex(i));
        CCControlButton* btn = (CCControlButton *)(this->getChildByTag(key->intValue()));
        CCSprite* spr = CCSprite::create("star000.png");
        spr->setAnchorPoint(ccp(0.5f, 0.5f));
        spr->setPosition(ccp(btn->getContentSize().width/2, btn->getContentSize().height/2));
        btn->addChild(spr);
        CCBlink* blink = CCBlink::create(1.0f, 3);
        if (i < results->allKeys()->count()-1) {
            spr->runAction(blink);
        } else {
            CCAction* pAction = CCCallFuncND::create(this, callfuncND_selector(QuestionLayer::noticeDelegate), NULL);
            spr->runAction(CCSequence::create(blink, pAction, NULL));
        }
    }

    rightAnswer++;
    if (timerCount >= timerTotal*2/3) {
        rightLimit += 1;
        //播放快速答题音效
        GameSoundManager::shareManager()->playAnswerCool();
    } else {
        //播放普通答题正确音效
        GameSoundManager::shareManager()->playAnswerRight();
    }

    isAnswerFinished = true;
}
void QuestionLayer::touchDownAction(CCObject *sender, CCControlEvent controlEvent)
{
    CCLOG("QuestionLayer::touchDownAction");

    if (isAnswerFinished) {
        return;
    }
    this->unschedule(schedule_selector(QuestionLayer::timerCB));

    CCControlButton* button = (CCControlButton *)sender;
    CCLOG("%d", button->getTag());
    button->setEnabled(false);

    bool bFind = false;
    CCDictionary* results = questionObj->rightAnswer;
    for (int i=0; i<results->allKeys()->count(); i++) {
        CCString* key = (CCString *)(results->allKeys()->objectAtIndex(i));
        if (key->intValue() == button->getTag()) {
            results->setObject(CCString::createWithFormat("%d", 1), key->getCString());
            bFind = true;
            break;
        }
    }

    if (bFind) {
        //统计已经回答正确答案的数量
        int rCount = 0;
        for (int i=0; i<results->allKeys()->count(); i++) {
            CCString* key = (CCString *)(results->allKeys()->objectAtIndex(i));
            CCString* value = (CCString *)(results->objectForKey(key->getCString()));
            if (value->intValue() == 1) {
                rCount++;
            }
        }
        CCLOG("rCount:%d", rCount);

        if (rCount == results->allKeys()->count()) {
            //回答完成所有正确答案
            for (int i=0; i<results->allKeys()->count(); i++) {
                CCString* key = (CCString *)(results->allKeys()->objectAtIndex(i));
                CCControlButton* btn = (CCControlButton *)(this->getChildByTag(key->intValue()));
                CCSprite* spr = CCSprite::create("star000.png");
                spr->setAnchorPoint(ccp(0.5f, 0.5f));
                spr->setPosition(ccp(button->getContentSize().width/2, button->getContentSize().height/2));
                btn->addChild(spr);
                CCBlink* blink = CCBlink::create(1.0f, 3);
                if (i < results->allKeys()->count()-1) {
                    spr->runAction(blink);
                } else {
                    CCAction* pAction = CCCallFuncND::create(this, callfuncND_selector(QuestionLayer::noticeDelegate), NULL);
                    spr->runAction(CCSequence::create(blink, pAction, NULL));
                }
            }

            rightAnswer++;
            if (timerCount >= timerTotal*2/3) {
                rightLimit += 1;
                //播放快速答题音效
                GameSoundManager::shareManager()->playAnswerCool();
            } else {
                //播放普通答题正确音效
                GameSoundManager::shareManager()->playAnswerRight();
            }

            isAnswerFinished = true;

        } else {
            CCLOG("正确答案没选完");
        }
    } else {
        //回答错误
        CCSprite* spr = CCSprite::create("arrow000.png");
        spr->setAnchorPoint(ccp(0.5f, 0.5f));
        spr->setPosition(ccp(button->getContentSize().width/2, button->getContentSize().height/2));
        button->addChild(spr);
        CCFadeIn* fadeIn = CCFadeIn::create(1.0f);
        CCAction* pAction = CCCallFuncND::create(this, callfuncND_selector(QuestionLayer::noticeDelegate), NULL);
        spr->runAction(CCSequence::create(fadeIn, pAction, NULL));

        errorAnswer++;
        isAnswerFinished = true;

        //播放错误音效
        GameSoundManager::shareManager()->playAnswerError();
    }
}