Exemplo n.º 1
0
std::string GBSqlite::getStringForKey(const char* key, const std::string & defaultValue)
{
	std::string outItem;
	if (localStorageGetItem(key, &outItem))
		return outItem;

	return defaultValue;
}
Exemplo n.º 2
0
float GBSqlite::getFloatForKey(const char* key, float defaultValue)
{
	std::string outItem;
	if (localStorageGetItem(key, &outItem))
	{
		if (!outItem.empty())
			return atof(outItem.c_str());
	}

	return defaultValue;
}
Exemplo n.º 3
0
bool GBSqlite::getBoolForKey(const char* key, bool defaultValue)
{
	std::string outItem;
	if (localStorageGetItem(key, &outItem))
	{
		if (outItem == "true")
			return true;
		else if (outItem == "false")
			return false;
	}
	
	return defaultValue;
}
// Arguments: char*
// Ret value: const char*
JSBool JSB_localStorageGetItem(JSContext *cx, uint32_t argc, jsval *vp) {
	JSB_PRECONDITION2( argc == 1, cx, JS_FALSE, "Invalid number of arguments" );
	jsval *argvp = JS_ARGV(cx,vp);
	JSBool ok = JS_TRUE;
	const char* arg0; 

	ok &= jsval_to_charptr( cx, *argvp++, &arg0 );
	JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
	const char* ret_val;

	ret_val = localStorageGetItem((char*)arg0  );

	jsval ret_jsval = charptr_to_jsval( cx, ret_val);
	JS_SET_RVAL(cx, vp, ret_jsval );

	return JS_TRUE;
}
void SaveLoad::Load()
{
    const char *value = localStorageGetItem("SaveGame");
    if(value)
    {
        memcpy(&m_SaveData,value, sizeof(SaveLoad::SaveData));
        //delete value;
    }
    else
    {
        memset(&m_SaveData,0,sizeof(SaveLoad::SaveData));
        
        memset(&m_SaveData,0,sizeof(m_SaveData));
        m_SaveData.currency = 0;
        m_SaveData.commercialIndex = 5;
        m_SaveData.currentLevel = 1;
        m_SaveData.trampLockLevel = 1;
        //m_SaveData.turboLockLevel = 2;
        m_SaveData.characters[0] |= UNLOCKED;
        m_SaveData.characters[0] |= SELECTED;
        m_SaveData.bikes[0] |= UNLOCKED;
        m_SaveData.bikes[0] |= SELECTED;
        m_SaveData.levelflags[TUTORIAL_LEVELSTART] |= UNLOCKED;
        //m_SaveData.levelflags[ISLAND_LEVELSTART] |= UNLOCKED;
        m_SaveData.levelflags[CITY_LEVELSTART] |= UNLOCKED;
        m_SaveData.levelflags[NIGHT_LEVELSTART] |= UNLOCKED;
        m_SaveData.levelflags[SPACE_LEVELSTART] |= UNLOCKED;
        
        for(int i = TUTORIAL_LEVELSTART; i < SPACE_LEVELSTART+8; i++)
        {
            m_SaveData.levelflags[i] |= UNLOCKED;
            m_SaveData.levelflags[i] |= ONE_COCONUT;
        }
        
        m_SaveData.musicVolume = 1.0f;
        m_SaveData.sfxVolume = 1.0f;
        
    }
    AudioManager::g_MasterMusicAudio = m_SaveData.musicVolume;
    AudioManager::g_MasterSFXAudio = m_SaveData.sfxVolume;
    AudioManager::AudioOn();
}
// Arguments: char*
// Ret value: const char*
bool JSB_localStorageGetItem(JSContext *cx, uint32_t argc, jsval *vp) {
    JSB_PRECONDITION2( argc == 1, cx, false, "Invalid number of arguments" );
    JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
    bool ok = true;
    std::string arg0; 

    ok &= jsval_to_std_string( cx, args.get(0), &arg0 );
    JSB_PRECONDITION2(ok, cx, false, "Error processing arguments");
    std::string ret_val;

    ok = localStorageGetItem(arg0, &ret_val);
    if (ok) {
        jsval ret_jsval = std_string_to_jsval(cx, ret_val);
        args.rval().set(ret_jsval);
    }
    else {
        args.rval().set(JSVAL_NULL);
    }
    
    return true;
}
Exemplo n.º 7
0
void CommonHttpResponseCallBack::onResponseJson(CAHttpClient* client, CAHttpResponse* response)
{
    CommonHttpManager::getInstance()->stopActivityIndicatorView();
    
    CC_RETURN_IF(!m_pSelectorJson);
    if (response->isSucceed())
    {
        std::string data(response->getResponseData()->begin(), response->getResponseData()->end());
        if (!data.empty())
        {
            localStorageSetItem(MD5(m_sUrl).md5().c_str(), data.c_str());
            
            if (CAViewController* viewController = dynamic_cast<CAViewController*>(m_pTarget))
            {
                CC_RETURN_IF(viewController->isViewRunning() == false);
            }
            
            //CCLog("\n \n \n---------HttpResponse--json---------\n<<<\n%s\n>>>\n--------------END--------------\n \n \n",data.c_str());
            
            CSJson::Reader read;
            CSJson::Value root;
            bool succ = read.parse(data, root);
            if (succ == false)
            {
                CCLog("GetParseError \n");
            }
            
            if (m_pTarget)
            {
                (m_pTarget->*m_pSelectorJson)(HttpResponseSucceed, root);
            }
        }
        else
        {
            if (CAViewController* viewController = dynamic_cast<CAViewController*>(m_pTarget))
            {
                CC_RETURN_IF(viewController->isViewRunning() == false);
            }
            
            CSJson::Value root;
            if (m_pTarget)
            {
                (m_pTarget->*m_pSelectorJson)(HttpResponseFaild, root);
            }
        }
        
    }
    else
    {
        if (CAViewController* viewController = dynamic_cast<CAViewController*>(m_pTarget))
        {
            CC_RETURN_IF(viewController->isViewRunning() == false);
        }
        
        const char* data = localStorageGetItem(MD5(m_sUrl).md5().c_str());

        do
        {
            CC_BREAK_IF(data == NULL);
            CSJson::Reader read;
            CSJson::Value root;
            bool succ = read.parse(data, root);
            if (succ == false)
            {
                CCLog("GetParseError \n");
                break;
            }
            
            if (m_pTarget)
            {
                (m_pTarget->*m_pSelectorJson)(HttpResponseSucceed, root);
            }
            return;
        }
        while (0);
        
        CSJson::Value root;
        if (m_pTarget)
        {
            (m_pTarget->*m_pSelectorJson)(HttpResponseFaild, root);
        }
    }
}
Exemplo n.º 8
0
		bool LocalStore::isExist(char* szKey)
		{
			std::string strRet;
			localStorageGetItem(szKey,&strRet);
			return !strRet.empty();
		}
Exemplo n.º 9
0
		std::string LocalStore::get( const char* szKey )
		{
			std::string strRet;
			localStorageGetItem(szKey,&strRet);
			return strRet;
		}
Exemplo n.º 10
0
void GameWorld::updategame(float dt){
    //CCLOG("update game");
    
    Vector<Plane*> targets2Delete;
    //CCLOG("111, _targets: %zd.", _targets.size());
    Vector<Plane*>::iterator iter;//;
    for (iter = _targets.begin(); iter != _targets.end(); iter++) {
        // target的碰撞体积
        Plane* target = dynamic_cast<Plane*>(*iter);
        Rect targetRect = target->boundingBox();
        // plane的碰撞矩形
        Rect planeRect = _myPlane->boundingBox();
        // plane与target的碰撞检测
        if(targetRect.intersectsRect(planeRect)){
            if(target->getTag() == 4){
                CCLOG("package\n");
                // if package and plane collide
                //doubleBulletFlag = true;
                this->scheduleOnce(schedule_selector(GameWorld::setDoubleBulletFlagF), 5);
                targets2Delete.pushBack(target);
            } else {
                CCLOG("game end.");
                // if enemy and plane collide
                auto gameOverScene = GameOverScene::create();
                gameOverScene->getLayer()->getLabel()->setString(" ");
                gameOverScene->getLayer()->setCurrentScore(score);
                // converts 'int' to 'string'
                std::stringstream ss;
                std::string str;
                ss<<score;
                ss>>str;
                const char *pHighScore = str.c_str();
                // converts 'const char *' to 'int'
                const char *highScore = localStorageGetItem("high_score").c_str();
                if(highScore != NULL ){
                    int highScoreInt = std::atoi(highScore);
                    // If higher than the highest score ,your score will replace it;
                    if(highScoreInt<score)
                        CCLOG("high_score: %s.", pHighScore);
                        localStorageSetItem("high_score", pHighScore);
                }else{
                    localStorageSetItem("high_score", pHighScore);
                    CCLOG("high_score: %s.", pHighScore);
                }
                gameOverScene->getLayer()->getScore()->setString(pHighScore);
                Director::getInstance()->replaceScene(gameOverScene);
            }
        }
        
        //CCLOG("222, bullet: %zd.", _bullets.size());
        Vector<Sprite*> bullets2Delete;
        Vector<Sprite*>::iterator iterB;
        //bullet与target的碰撞
        for (iterB = _bullets.begin(); iterB != _bullets.end(); iterB++) {
        //CCARRAY_FOREACH(_bullets, bulletsIterator){
            auto bullet = dynamic_cast<Sprite*>(*iterB);
            Rect bulletRect = bullet->boundingBox();
            if(targetRect.intersectsRect(bulletRect)){
                target->attacked++;
                //CCLOG("target attacked: %d.", target->attacked);
                bullets2Delete.pushBack(bullet);
            }
        }
        
        /*
         CCLOG("333");
        for (iterB = bullets2Delete.begin(); iterB != bullets2Delete.end(); iter++) {
        //CCARRAY_FOREACH(bullets2Delete, bulletsIterator){
            auto bullet = dynamic_cast<Sprite*>(*iterB);
            _bullets.eraseObject(bullet);
            this->removeChild(bullet);
        }*/
        
        if(target->attacked >= target->attackedCount){
            targets2Delete.pushBack(target);
        }
        bullets2Delete.clear();
    }
    
    //CCLOG("444, targets2Delete: %zd.", targets2Delete.size());
    for (iter = targets2Delete.begin(); iter != targets2Delete.end(); iter++) {
    //CCARRAY_FOREACH(targets2Delete, targetIterator){
        auto target = dynamic_cast<Plane*>(*iter);
        _targets.eraseObject(target);
        if(target->getTag() == 1){
            score+=10;
        }else if(target->getTag() == 2){
            score+=20;
        }else if(target->getTag() == 3){
            score+=50;
            //CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("explosion.mp3");
        }else if(target->getTag() == 4){
            CCLOG("target is the package");
            this->scheduleOnce(schedule_selector(GameWorld::setDoubleBulletFlagF), 5);
            doubleBulletFlag = true;
        }
        this->removeChild(target);
        std::stringstream ss;
        std::string str;
        ss<<score;
        ss>>str;
        const char *p = str.c_str();
        scoreLabel->setString(p);
        //CCLOG("888");
    }
    targets2Delete.clear();
    //CCLOG("555");
}