コード例 #1
0
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;
}
コード例 #2
0
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();
    }
}