Example #1
0
void Random::select(Ref *ref)
{

    auto thor = Sprite::create("thor_.png");
    auto conver = Sprite::create("conver.png");
    thor->setPosition(visibleSize.width / 6 * 5, 100);
    conver->setPosition(visibleSize.width / 2 + 130, 230);
    this->addChild(thor, 1);
    this->addChild(conver, 1);

    auto label = Label::createWithTTF("", "fonts/comic.ttf", 24);
    label->setColor(Color3B::BLACK);
    label->setPosition(visibleSize.width / 2 + 130, 245);
    this->addChild(label, 2);

    Global * global = Global::getInstance();
    int life = global->getLife();
    int attack = global->getAttack();
    int experience = global->getExperience();

    //life -= 60;

    int i = rand() % 3;
    if (i == 0) {
        // 内部成员背叛,血量减少60
        life -= 60;
        global->setLife(life);
        label->setString("  Oops!Your health\n    value decreases\n          by 60!");
    }
    else if (i == 1) {
        // 拾获太空水晶,攻击力增加5
        attack += 5;
        global->setAttack(attack);
        label->setString("  Hey,man!Your\n   attack value\n     increase\n        by 5!");
    }
    else if (i == 2) {
        // 经验值加20
        experience += 20;
        global->setExperience(experience);
        label->setString("     Wow,your\n experience value\n increase by 20!");
    }
    schedule(schedule_selector(Random::time), 3);

}