当前位置: 首页>>代码示例>>C++>>正文


C++ UserDefault::setIntegerForKey方法代码示例

本文整理汇总了C++中UserDefault::setIntegerForKey方法的典型用法代码示例。如果您正苦于以下问题:C++ UserDefault::setIntegerForKey方法的具体用法?C++ UserDefault::setIntegerForKey怎么用?C++ UserDefault::setIntegerForKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UserDefault的用法示例。


在下文中一共展示了UserDefault::setIntegerForKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: allCheck

int StageManager::allCheck(int id) {
	//id = 0 BRUE, id = 1 RED
	int brue, red;
	UserDefault* userdef = UserDefault::getInstance();
	brue = 0, red = 0;
	//BRUE
	if (id == 0) {
		for (int i = 0; i < m_Container.size(); ++i) {
			if (m_Container.at(i)->getColor() == Color3B::BLUE) {
				 ++brue;
				 userdef->setIntegerForKey("blue", brue);
			}
		}
		return brue;
	}
	//RED
	if (id == 1) {
		for (int i = 0; i < m_Container.size(); ++i) {
			if (m_Container.at(i)->getColor() == Color3B::RED) {
				++red;
				userdef->setIntegerForKey("red", red);
			}
		}
		return red;
	}
}
开发者ID:Proj-DDM,项目名称:GrimoArena,代码行数:26,代码来源:StageManager.cpp

示例2: MenuBombCallback

void InGameLayer::MenuBombCallback()
{
	SimpleAudioEngine::getInstance()->playEffect("sound/use_bomb.mp3");
	cleanAllEnemys();
	if(bombNum>0)
		bombNum--;

	auto label = static_cast<Label*>(this->getChildByTag(GameSceneNodeTagNumLabel));
	auto menu = static_cast<Menu*>(this->getChildByTag(GameSceneNodeTagMenuBomb));

	if (bombNum == 0)
	{
		label->setVisible(false);
		menu->setVisible(false);
	}
	else
	{
		label->setString(__String::createWithFormat("x%d",bombNum)->getCString());
	}
	score += 100;
	scoreLabel->setString(__String::createWithFormat("%d",score)->getCString());
	UserDefault *defaults = UserDefault::getInstance();
	int highScore = defaults->getIntegerForKey("highscore_key");    
	if (highScore < score) {
		highScore = score;
		defaults->setIntegerForKey("highscore_key", highScore);
	}
	__String *text = __String::createWithFormat("%i", highScore);

	auto lblScoreOfHigh = static_cast<Label*>(this->getChildByTag(GameSceneNodelblHighScore));
	lblScoreOfHigh->setString(text->getCString());
}
开发者ID:HeyUComeOn,项目名称:feijidazhan,代码行数:32,代码来源:InGameLayer.cpp

示例3: init

// on "init" you need to initialize your instance
bool GameOverScene::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();

	auto backgroundSprite = Sprite::create("Background.png");
	backgroundSprite->setPosition(Point(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y));

	this->addChild(backgroundSprite);

	auto retryItem = MenuItemImage::create("Retry Button.png", "Retry Button Clicked.png", CC_CALLBACK_1(GameOverScene::GoToGameScene, this));
	retryItem->setPosition(Point(visibleSize.width /2 + origin.x, visibleSize.height / 4 * 3));

	auto mainMenuItem = MenuItemImage::create("Menu Button.png", "Menu Button Clicked.png", CC_CALLBACK_1(GameOverScene::GoToMainMenuScene, this));
	mainMenuItem->setPosition(Point(visibleSize.width /2 + origin.x, visibleSize.height / 4 ));

	auto menu = Menu::create(retryItem, mainMenuItem, NULL);
	menu->setPosition(Point::ZERO);

	this->addChild(menu);

	UserDefault *def = UserDefault::getInstance();

	auto highScore = def->getIntegerForKey("HIGHSCORE", 0);

	if (score > highScore)
	{
		highScore = score;

		def->setIntegerForKey("HIGHSCORE", highScore);
	}

	def->flush();

	__String *tempScore = __String::createWithFormat("Current : %i", score);

	auto currentScore = LabelTTF::create(tempScore->getCString(), "fonts/Marker Felt.ttf", visibleSize.height * SCORE_FONT_SIZE);
	currentScore->setPosition(Point(visibleSize.width * 0.25 + origin.x, visibleSize.height /2 + origin.y ));

	this->addChild(currentScore);
	
	__String *temHighpScore = __String::createWithFormat("High : %i", highScore);

	auto highScoreLabel = LabelTTF::create(temHighpScore->getCString(), "fonts/Marker Felt.ttf", visibleSize.height * SCORE_FONT_SIZE);

	highScoreLabel->setColor(Color3B::YELLOW);
	highScoreLabel->setPosition(Point(visibleSize.width * 0.75 + origin.x, visibleSize.height / 2 + origin.y));

	this->addChild(highScoreLabel);

	return true;
}
开发者ID:StartNewLife,项目名称:FlappyBird,代码行数:60,代码来源:GameOverScene.cpp

示例4: registerCurrentScore

void HighScoreManager::registerCurrentScore(int score)
{
    UserDefault* userDef = UserDefault::getInstance();
    if (score > userDef->getIntegerForKey(KEY_HIGHSCORE.c_str(), 0))
    {
        userDef->setIntegerForKey(KEY_HIGHSCORE.c_str(), score);
    }
}
开发者ID:IIJAN2016,项目名称:FlappyBird,代码行数:8,代码来源:HighScoreManager.cpp

示例5: resetSaveData

void TutorialScene::resetSaveData()
{
	const int maxNumMonsters = 3;
	const int maxNumKnown = 31;

	//データをリセット
	//Set every SaveDataKey for Monsters and Equipment to 0 (eEmpty)
	UserDefault* def = UserDefault::getInstance();

	for (int i = 0; i < maxNumMonsters; i++)
	{
		def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eMonsterData01 + i].c_str(), n_MonsterData::eEmpty);

	}
	for (int i = 0; i < maxNumKnown; i++)
	{
		def->setBoolForKey(SaveDataKey[n_DataKeyNum::eKnownData01 + i].c_str(), false);
	}
	def->setBoolForKey(SaveDataKey[n_DataKeyNum::eKnownData01].c_str(), true);

	def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eMonster1Exp].c_str(), 0);
	def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eMonster2Exp].c_str(), 0);
	def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eMonster3Exp].c_str(), 0);

	def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eWinNum01].c_str(), 0);
	def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eWinNum02].c_str(), 0);
	def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eWinNum03].c_str(), 0);

	def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eLossNum01].c_str(), 0);
	def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eLossNum02].c_str(), 0);
	def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eLossNum03].c_str(), 0);


	def->flush();
}
开发者ID:riverreal,项目名称:MillionCode,代码行数:35,代码来源:TutorialScene.cpp

示例6: showReviewAlertWhenOpenTime

void ThirdPartyHelper::showReviewAlertWhenOpenTime(int opentime){
    UserDefault *ud = UserDefault::getInstance();
    int cu = ud->getIntegerForKey(LHOPENTIME, 0);
    cu ++;
    ud->setIntegerForKey(LHOPENTIME, cu);
    if (cu == opentime) {
        ThirdPartyHelper::showReviewAlert();
    }
}
开发者ID:LuckyGameCn,项目名称:LHCocosGame,代码行数:9,代码来源:ThirdPartyHelper.cpp

示例7: setGameOverData

void BBGameDataManager::setGameOverData(int star, int leftTime)
{
    int themeId = m_themeId;
    int levelId = m_levelId + 1;
    
    UserDefault* ud = UserDefault::getInstance();
    // 更新星级
    __String *starkey = __String::createWithFormat("star_%d_%d", m_themeId, m_levelId);
    int curStar = ud->getIntegerForKey(starkey->getCString(), 0);
    if (curStar < star) {
        ud->setIntegerForKey(starkey->getCString(), star);
    }
    
    __String *bestkey = __String::createWithFormat("best_%d_%d", m_themeId, m_levelId);
    int bestTime = ud->getIntegerForKey(bestkey->getCString(), 0);
    if (bestTime == 0 || bestTime > leftTime) {
        ud->setIntegerForKey(bestkey->getCString(), leftTime);
    }
    
    // 更新关卡进度
    int themeIdFramCache = ud->getIntegerForKey("themeId", 1);
    int levelIdFramCache = ud->getIntegerForKey("levelId", 1);
    
    if (themeIdFramCache > themeId) {
        return;
    } else if (themeIdFramCache == themeId) {
        if (levelIdFramCache >= levelId) {
            return;
        }
    }
    
    if (levelId > 9) {
        // 进入下一个主题
        themeId++;
        levelId = 1;
    }
    
    ud->setIntegerForKey("themeId", themeId);
    ud->setIntegerForKey("levelId", levelId);
    
    ud->flush();

}
开发者ID:fengzila,项目名称:bbPintu,代码行数:43,代码来源:BBGameDataManager.cpp

示例8: menuSceneTransition

void TitleScene::menuSceneTransition(cocos2d::Ref *pSender, bool newGame)
{
	const int maxNumMonsters = 3;
	const int maxNumEquip = 10;

	if (newGame)
	{
		if (Generic::checkSaveData())
		{
			auto nextScene = TutorialScene::createScene();
			auto pScene = TransitionFade::create(1.0f, nextScene);
			Director::getInstance()->replaceScene(pScene);
		}
		else
		{
			const int maxNumMonsters = 3;
			const int maxNumKnown = 31;

			//データをリセット
			//Set every SaveDataKey for Monsters and Equipment to 0 (eEmpty)
			UserDefault* def = UserDefault::getInstance();

			for (int i = 0; i < maxNumMonsters; i++)
			{
				def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eMonsterData01 + i].c_str(), n_MonsterData::eEmpty);

			}
			for (int i = 0; i < maxNumKnown; i++)
			{
				def->setBoolForKey(SaveDataKey[n_DataKeyNum::eKnownData01 + i].c_str(), false);
			}
			def->setBoolForKey(SaveDataKey[n_DataKeyNum::eKnownData01].c_str(), true);

			def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eMonster1Exp].c_str(), 0);
			def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eMonster2Exp].c_str(), 0);
			def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eMonster3Exp].c_str(), 0);

			def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eWinNum01].c_str(), 0);
			def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eWinNum02].c_str(), 0);
			def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eWinNum03].c_str(), 0);

			def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eLossNum01].c_str(), 0);
			def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eLossNum02].c_str(), 0);
			def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eLossNum03].c_str(), 0);

			def->flush();

			auto nextScene = MenuScene::createScene();
			auto pScene = TransitionFade::create(1.0f, nextScene);
			Director::getInstance()->replaceScene(pScene);
		}
		return;
	}
    
    auto nextScene = MenuScene::createScene();
    auto pScene = TransitionFade::create(0.5f, nextScene);
    Director::getInstance()->replaceScene(pScene);
}
开发者ID:riverreal,项目名称:MillionCode,代码行数:58,代码来源:TitleScene.cpp

示例9: buttonYes

/*--------------------------/
 Yesボタン生成
 /--------------------------*/
void StageSelectActionLayer::buttonYes(cocos2d::Layer* layer,Menu* menu,int tag){
    
    auto buttonYes = MenuItemImage::create("Texture/GamePlay/GameScene/StageSelect/StageSelect_Yes.png",
                                           "Texture/GamePlay/GameScene/StageSelect/StageSelect_Yes.png",
                                           [ = ](Ref* sender)
                                           {
											   UserDefault* useDef = UserDefault::getInstance();
                                               useDef->setIntegerForKey("selectStage",tag);
											   useDef->setIntegerForKey("selectGimmick", tag);
                                               useDef->flush();
                                               
                                               auto nextScene = SceneCreator::createPhysicsScene(GameMainScene::create(), Vect(0, -9.8f), 5.0f);
                                               auto scene	= TransitionFade::create( 1.5f, nextScene, Color3B::BLACK );
                                               auto dir = Director::getInstance();
                                               dir->replaceScene(scene);
                                           });
    buttonYes->setPosition(400,300);
    buttonYes->setScale(1.2f);
    menu->addChild(buttonYes);
    
}
开发者ID:setu15,项目名称:Proj_Note,代码行数:24,代码来源:StageSelectActionLayer.cpp

示例10: init

bool GameOverScene::init()	{
    if(!Layer::init())	{
        return false;
    }

    auto visibleSize = Director::getInstance()->getVisibleSize();
    auto origin = Director::getInstance()->getVisibleOrigin();

    UserDefault* userScore = UserDefault::getInstance();
    if(score >= userScore->getIntegerForKey( "highscore" ))	{
        userScore->setIntegerForKey( "highscore", score );
    }
    userScore->flush();

    //create background for game over scene
    auto background = Sprite::create("FlappyResources/Background.png");
    background->setPosition(origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2);
    this->addChild(background);

    //create retry item
    auto retry = MenuItemImage::create( "FlappyResources/Retry_Button.png", "FlappyResources/Retry_Button_Clicked.png", CC_CALLBACK_1(GameOverScene::goToGameScene, this) );
    retry->setPosition( origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2 );

    //create quit item
    auto quit = MenuItemImage::create( "FlappyResources/Menu_Button.png", "FlappyResources/Menu_Button_Clicked.png", CC_CALLBACK_1(GameOverScene::goToMainMenuScene, this) );
    quit->setPosition( origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2 - quit->getContentSize().height * 2);

    //create menu
    auto menu = Menu::create( retry, quit, NULL );
    menu->setPosition( Vec2(0, 0) );

    //create label score
    auto stringScore = __String::createWithFormat( "Your score: %d", score );
    auto labelScore = LabelTTF::create( stringScore->getCString(), "fonts/Marker Belt.ttf", 50 );
    labelScore->setPosition( origin.x + labelScore->getContentSize().width, origin.y + visibleSize.height / 2 + labelScore->getContentSize().height * 4 );
    labelScore->setFontFillColor( Color3B::YELLOW );

    //create label display best score
    auto stringBestScore = __String::createWithFormat( "High score: %d", userScore->getIntegerForKey( "highscore" ) );
    auto labelHighScore = LabelTTF::create( stringBestScore->getCString(), "fonts/Marker Belt.ttf", 50 );
    labelHighScore->setPosition( origin.x + labelScore->getContentSize().width + visibleSize.width / 2, origin.y + visibleSize.height / 2 + labelHighScore->getContentSize().height * 4);
    labelHighScore->setFontFillColor( Color3B::RED );

    this->addChild( menu );
    this->addChild( labelScore );
    this->addChild( labelHighScore );

    return true;
}
开发者ID:nguyenchiemminhvu,项目名称:Cocos2d-x-FlappyBird-demo-source,代码行数:49,代码来源:GameOverScene.cpp

示例11: updateFlameCollectedCount

void Flame::updateFlameCollectedCount()
{
    StatisticsData* totaldata = StatisticsData::getRunningLayer();
    UserDefault* userDefault = UserDefault::getInstance();
    int FlameWhiteCount = userDefault->getIntegerForKey("collectedWhite",0);
    int FlameBlueCount = userDefault->getIntegerForKey("collectedBlue", 0);
    int FlameVioltCount = userDefault->getIntegerForKey("collectedViolet",0);
    int FlameOrangeCount = userDefault->getIntegerForKey("collectedOrange",0);

    switch(_type){
        case Flame_White:
            FlameWhiteCount++;
            totaldata->totalFlame_White++;
            userDefault->setIntegerForKey("collectedWhite", FlameWhiteCount);
            break;
        case Flame_Blue:
            FlameBlueCount++;
            totaldata->totalFlame_Blue++;
            userDefault->setIntegerForKey("collectedBlue", FlameBlueCount);
            break;
        case Flame_Violet:
            FlameVioltCount++;
            totaldata->totalFlame_Violet++;
            userDefault->setIntegerForKey("collectedViolet", FlameVioltCount);
            break;
        case Flame_Orange:
            FlameOrangeCount++;
            totaldata->totalFlame_Orange++;
            userDefault->setIntegerForKey("collectedOrange", FlameOrangeCount);
            break;
            
        default:
            break;
    }

}
开发者ID:linger2334,项目名称:Grow,代码行数:36,代码来源:Flame.cpp

示例12: saveHighScore

//ハイスコア記録・表示
void GameScene::saveHighScore()
{
    UserDefault* userDefault = UserDefault::getInstance();
    
    //ハイスコアを取得する
    int oldHighScore = userDefault->getIntegerForKey(KEY_HIGHSCORE,0);
    if(oldHighScore < m_score)
    {
        //ハイスコアを保存する
        userDefault->setIntegerForKey(KEY_HIGHSCORE, m_score);
        userDefault->flush();
        
        //ハイスコアを表示する
        showHighScoreLabel();
    }
}
开发者ID:mrt168,项目名称:nyanzame,代码行数:17,代码来源:GameScene.cpp

示例13: setControllerType

void GeneralUtils::setControllerType(ControllerType controllerType)
{
    int controllerTypeInt = 0;
    
    if (controllerType == E_CONTROLLER_TOUCH)
    {
        controllerTypeInt = 1;
    }
    else if (controllerType == E_CONTROLLER_TILT)
    {
        controllerTypeInt = 2;
    }
    else
    {
        return;
    }
    
    UserDefault *ud = UserDefault::getInstance();
    
    ud->setIntegerForKey("control_type", controllerTypeInt);
    ud->flush();
}
开发者ID:eiji11,项目名称:clear-graffiti,代码行数:22,代码来源:GeneralUtils.cpp

示例14: init

bool TitleScene::init() 
{
    if ( !Layer::init() ) 
	{
		return false; 
	}

	//glClearColor(255, 255, 255, 255);
    
    visibleSize = Director::getInstance()->getVisibleSize();
    m_Mag = Generic::getScreenMagnification(visibleSize);

	UserDefault* def = UserDefault::getInstance();
	def->setIntegerForKey("Battle", 0);

	displayBG();
	setSound();
    displayMenu(Generic::checkSaveData());

	this->scheduleUpdate();
    
    return true;
}
开发者ID:riverreal,项目名称:MillionCode,代码行数:23,代码来源:TitleScene.cpp

示例15: init

// on "init" you need to initialize your instance
bool Result::init()
{
    //////////////////////////////
    //  super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
    
    // add a label shows "Hello World"
    // create and initialize a label
    
    
    
    
    
    
    //タッチイベントの監視を開始
    auto listener = EventListenerTouchOneByOne::create();
    listener->onTouchBegan = CC_CALLBACK_2(Result::onTouchBegan, this);
    listener->onTouchCancelled= CC_CALLBACK_2(Result::onTouchCancelled,this);
    listener->onTouchMoved= CC_CALLBACK_2(Result::onTouchMoved,this);
    listener->onTouchEnded = CC_CALLBACK_2(Result::onTouchEnded, this);
    this->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, this);
    int dby=100;
    
    //スタートボタンを設置
    auto startButton = MenuItemImage::create(
                                             "BACKbutton.png",  // 通常状態の画像
                                             "BACKbutton.png",  // 押下状態の画像
                                             CC_CALLBACK_1(Result::pushStart, this)); // 押下時のアクション
    
    startButton->setPosition(Point(visibleSize.width/4,
                                 visibleSize.height/2-dby));
    
    //create menu, it's an autorelease object
    auto s_menu = Menu::create(startButton, NULL);
    s_menu->setPosition(Point::ZERO);
    this->addChild(s_menu, 2);
    
    //リトライボタンを設置
    auto retryButton = MenuItemImage::create(
                                             "RETRYbutton.png",  // 通常状態の画像
                                             "RETRYbutton.png",  // 押下状態の画像
                                             CC_CALLBACK_1(Result::pushRetry, this)); // 押下時のアクション
    
    retryButton->setPosition(Point(visibleSize.width*3/4 ,visibleSize.height/2-dby));
    //create menu, it's an autorelease object
    auto r_menu = Menu::create(retryButton, NULL);
    r_menu->setPosition(Point::ZERO);
    this->addChild(r_menu, 3);
    
    //this->particle = particle;
    
    
//    auto scoreLabel = Label::createWithSystemFont(cocos2d::StringUtils::toString(Stage:jugScore), "HiraKakuProN-W6", 48);
//    scoreLabel->setPosition(Point(visibleSize.width/2, visibleSize.height/2));
//    scoreLabel->setTag(20);
//    this->addChild(scoreLabel)
    

    UserDefault *userDef = UserDefault::getInstance();
    
    
    int highScore = userDef->getIntegerForKey("highScore", 0);
    //int型をセット
    int tempScore = userDef->getIntegerForKey("temp");
    
    //点数評価
    std::string honor;
    if(tempScore<=10)
        honor="GO How to Play";
    else if(10<tempScore&&tempScore<=30)
        honor="Do you play with a blindfold?";
    else if(30<tempScore&&tempScore<=50)
        honor="My grandma level";
    else if(50<tempScore&&tempScore<=80)
        honor="Otedamer";
    else if(80<tempScore&&tempScore<=100)
        honor="Pro otedamer";
    else if(100<tempScore&&tempScore<=130)
        honor="Cool Juggler";
    else if(130<tempScore&&tempScore<=150)
        honor="God juggler!!";
    else
        honor="God";
    std::string honor2="Your Rank : ";
    honor2.append(honor);
    auto honorLabel = Label::createWithSystemFont(honor2, "HiraKakuProN-W6", 40);
    honorLabel->setPosition(Point(visibleSize.width/2, visibleSize.height-70));
    this->addChild(honorLabel);

    
    CCLOG("highscore=%dtempScore=%d",highScore,tempScore);
    if(tempScore>highScore){
        userDef->setIntegerForKey("highScore", tempScore);
//.........这里部分代码省略.........
开发者ID:gomeifuku,项目名称:JugJug,代码行数:101,代码来源:ResultScene.cpp


注:本文中的UserDefault::setIntegerForKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。