本文整理汇总了C++中UserDefault::getIntegerForKey方法的典型用法代码示例。如果您正苦于以下问题:C++ UserDefault::getIntegerForKey方法的具体用法?C++ UserDefault::getIntegerForKey怎么用?C++ UserDefault::getIntegerForKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserDefault
的用法示例。
在下文中一共展示了UserDefault::getIntegerForKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: displayIcon
void Picking::displayIcon()
{
auto fileU = FileUtils::getInstance();
auto fileContent = fileU->getStringFromFile("data/animData.xml");
UserDefault* def = UserDefault::getInstance();
int key = def->getIntegerForKey(SaveDataKey[n_DataKeyNum::eMonsterData01 + m_battleNum].c_str());
doc.Parse(fileContent.c_str());
fileContent = fileU->getStringFromFile("data/monsterData.xml");
mData.Parse(fileContent.c_str());
m_HP = atoi(mData.FirstChildElement()->FirstChildElement(MonsterNameData[key].c_str())->FirstChildElement("HP")->GetText());
auto sprite = doc.FirstChildElement()->FirstChildElement(MonsterNameData[key].c_str());
key = def->getIntegerForKey(SaveDataKey[n_DataKeyNum::eEnemyMonster01 + m_battleNum].c_str());
m_enemyHP = atoi(mData.FirstChildElement()->FirstChildElement(MonsterNameData[key].c_str())->FirstChildElement("HP")->GetText());
//cut image to fit inside frame
m_iconSprite = Sprite::create(sprite->FirstChildElement("spriteList")->FirstChildElement("animation")->FirstChildElement("stand")->GetText());
m_iconSprite->setScale(m_Mag * 1.5);
m_iconSprite->setPosition(Vec2((m_visibleSize.width / 6) * 1.8, m_visibleSize.height / 2));
m_instance->addChild(m_iconSprite);
}
示例2: 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;
}
示例3: textSelect
// テキストの設定
void resultText::textSelect()
{
// スコアデータの取得
UserDefault *userDef = UserDefault::getInstance();
float tempScore = userDef->getIntegerForKey("Score", 0);
int textRoot;
score = tempScore;
if (SCOREBORDER_1)
{
textRoot = 1;
}
else if (SCOREBORDER_2)
{
textRoot = 2;
}
else if (SCOREBORDER_3)
{
textRoot = 3;
}
else if (SCOREBORDER_4)
{
textRoot = 4;
}
else
{
textRoot = 5;
}
texts(textRoot);
}
示例4: getStar
int BBGameDataManager::getStar(int themeId, int levelId)
{
UserDefault* ud = UserDefault::getInstance();
// 更新星级
__String *starkey = __String::createWithFormat("star_%d_%d", themeId, levelId);
return ud->getIntegerForKey(starkey->getCString(), 0);
}
示例5: getBestTime
int BBGameDataManager::getBestTime(int themeId, int levelId)
{
UserDefault* ud = UserDefault::getInstance();
__String *bestkey = __String::createWithFormat("best_%d_%d", themeId, levelId);
return ud->getIntegerForKey(bestkey->getCString(), 0);
}
示例6: initData
void BBHandleLayer::initData()
{
m_visibleSize = Director::getInstance()->getVisibleSize();
m_blockLength = kBlockLength * BBGameDataManager::getInstance()->getScreenScale();
m_row = 5;
m_col = 4;
m_countDown = 2;
m_blockArr = Array::create();
m_blockArr->retain();
m_isReady = false;
m_showTips = false;
m_moves = 0;
m_over = false;
m_mixTimes = 100;
m_blockAnimOver = true;
m_idleBlockLastDirection = 0;
m_curIndex = m_row * m_col + 1;
UserDefault *ud = UserDefault::getInstance();
if (ud->getBoolForKey("hasLocalData")) {
m_moves = ud->getIntegerForKey("moves");
}
}
示例7: 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());
}
示例8: displayEnemy
void Picking::displayEnemy()
{
auto fileU = FileUtils::getInstance();
auto fileContent = fileU->getStringFromFile("data/animData.xml");
doc.Parse(fileContent.c_str());
UserDefault* def = UserDefault::getInstance();
enemyMonster = def->getIntegerForKey(SaveDataKey[(n_DataKeyNum::eEnemyMonster01) + m_battleNum].c_str());
auto sprite = doc.FirstChildElement()->FirstChildElement(MonsterNameData[enemyMonster].c_str());
/*
//CARD on the center
m_enemySpecial = Sprite::create("img/UI/battle/UI_B_12.png");
m_enemySpecial->setScale(m_Mag * 0.8);
m_enemySpecial->setPosition(Vec2(m_visibleSize.width / 2, m_visibleSize.height - m_enemySpecial->getBoundingBox().getMaxY() * 0.75));
m_instance->addChild(m_enemySpecial);
m_enemySpecial->setVisible(false); //hidden for animation
*/
//Monster Sprite number 2
m_enemyCard = Sprite::create(sprite->FirstChildElement("spriteList")->FirstChildElement("animation")->FirstChildElement("stand")->GetText());
m_enemyCard->setScale(m_Mag * 1.5);
m_enemyCard->setPosition(Vec2((m_visibleSize.width / 6) * 4.5, m_visibleSize.height /2));
m_instance->addChild(m_enemyCard);
}
示例9: 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;
}
示例10: 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);
}
}
示例11: 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();
}
}
示例12: 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();
}
示例13: doAction
void TestGameCenter::doAction(int tag) {
switch (tag) {
case TAG_GC_LOGIN: {
// std::function<void(int, std::string&)> callback = std::bind(&TestGameCenter::onUserCallback, this, std::placeholders::_1, std::placeholders::_2);
//use cocos utils
std::function<void(int, std::string&)> callback = CC_CALLBACK_2(TestGameCenter::onUserCallback, this);
if (_protocolGameCenterUser->isLoggedIn()) {
_resultInfo->setString("GameCenter: log in already.");
} else {
_protocolGameCenterUser->login(callback);
}
}
break;
case TAG_GC_LOGOUT: {
std::function<void(int, std::string&)> callback = CC_CALLBACK_2(TestGameCenter::onUserCallback, this);
_protocolGameCenterUser->logout(callback);
break;
}
case TAG_GC_SHOW_LEADERBOARDS: {
_protocolGameCenterSocial->showLeaderboards();
break;
}
case TAG_GC_SHOW_ACHIEVEMENTS: {
_protocolGameCenterSocial->showAchievements();
break;
}
case TAG_GC_SUBMIT_SCORE: {
UserDefault* userDefault = UserDefault::getInstance();
int score = userDefault->getIntegerForKey("high-score", 1000) + 1;
_protocolGameCenterSocial->submitScore(GAME_CENTER_LEADERBOARD_KEY_IOS_EASY, score, CC_CALLBACK_2(TestGameCenter::onSocialCallback, this));
_resultInfo->setString(StringUtils::format("Submitting new high score: %d", score));
break;
}
case TAG_GC_UNLOCK_ACHIEVEMENT: {
_protocolGameCenterSocial->unlockAchievement(GAME_CENTER_ACHIEVEMENT_KEY_IOS_PRIME);
_resultInfo->setString("Unlocking Achievement PRIME");
break;
}
case TAG_GC_RESET_ACHIEVEMENTS: {
_resultInfo->setString("Resetting all achievements...");
_protocolGameCenterSocial->resetAchievements(CC_CALLBACK_2(TestGameCenter::onSocialCallback, this));
break;
}
default:
break;
}
}
示例14: 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;
}
}
示例15: 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();
}
}