0
votes

I have a quiz type of game. One question and 4 possible answers. The answers are dynamically pulled from JSON file from web services. I have 1 question displayed as CCLabelTTF and 4 answers (a, b, c and d) also as CCLabelTTF. Now, I need to show an alert for confirming the answers whichever the user has selected/tapped. - First question: How can I detect the answers a, b, c and d? I mean which answer the user has touched? - Second, How can I assigned a unique property to each of these answers? I mean I want to do like this:

CCLabelTTF *answerA = [CCLabelTTF labelWithString:@"This will be dynamically set" fontName:@"verdana" fontSize:25];

answerA.tag = @"Here goes the unique Identifier for answerA"; /* Is it okay with tag or is there some more good process? I am thinking to do answerA.tag = 0; 0 for incorrect and 1 for correct answers. */

This tag identifier will be used to compare the correct answer and the selected answer like this:

When the user tap "YES" in Alert, the following comparison will occur:

 if(answerA.tag == @["movies"][i]@["answer"][i]@["status"]) // @["movies"][i]@["answer"][i]@["status"] will either have 0 or 1.

Is there another great solutions for this game? Like what if buttons used instead of text label? Please help.

1

1 Answers

1
votes

Use CCMenu would be better,

bool ControlsLayer::init() 
{
    CCTTFLabel *ttflabel = [CCLabelTTF labelWithString:@"This will be dynamically set" fontName:@"verdana" fontSize:25]
    CCMenuItemLabel *label = [CCMenuItemLabel initWithLabel: ttflabel];

    CCMenu *menu = CCMenu::menuWithItems(label, NULL);
    menu->setPosition(ccp(windowSize.width/2, controlsLabel->getPosition().y - controlsLabel->getContentSize().height));

    this->addChild(menu, 2);

    return true;
}

void ControlsLayer::backButtonAction(CCObject* pSender)
{
}

https://github.com/clawoo/AsteroidsCocos2D-x/blob/master/Classes/ControlsLayer.cpp