Beispiel #1
0
bool MainScene::init()
{
	CCSize winSize = Director::getInstance()->getVisibleSize();
	if (!CCLayer::init())
	{
		return false;
	}
	auto BackGround = Sprite::create("backg.png");
	BackGround->setPosition(ccp(winSize.width / 2, winSize.height / 2)); //위치지정
	this->addChild(BackGround);

	CCMenu *MenuMain = CCMenu::create(NULL); //메뉴생성
	CCMenu *MenuMain1 = CCMenu::create(NULL); //메뉴생성
	CCMenu *MenuMain2 = CCMenu::create(NULL); //메뉴생성

	//메뉴아이템 추가
	CCMenuItem *item1 = CCMenuItemImage::create("start.png",
		"start.png",
		this,
		menu_selector(MainScene::menuCloseCallback));
	CCMenuItem *item2 = CCMenuItemImage::create("rank.png",
		"rank.png",
		this,
		menu_selector(MainScene::RankCloseCallback));

	CCMenuItem *item3 = CCMenuItemImage::create("create.png",
		"create.png",
		this,
		menu_selector(MainScene::CreaterMenuCallback));


	MenuMain->addChild(item1, 1); //메뉴에 아이템 붙이기
	MenuMain1->addChild(item2, 2);
	MenuMain2->addChild(item3, 3);

	MenuMain->setPosition(ccp(winSize.width / 2, winSize.height / 2 - 20));
	MenuMain1->setPosition(ccp(winSize.width / 2, winSize.height / 2 - 90));
	MenuMain2->setPosition(ccp(winSize.width / 2, winSize.height / 2 - 160));

	this->addChild(MenuMain, 1);
	this->addChild(MenuMain1, 2);
	this->addChild(MenuMain2, 3);//메뉴를 레이어에 추가

	CCUserDefault* user = CCUserDefault::sharedUserDefault();
	int SaveSw = CCUserDefault::sharedUserDefault()->getIntegerForKey("SaveMake");
	if (SaveSw == 0){
		user->setIntegerForKey("SaveMake", 1);
		user->setIntegerForKey("Rank1", 0);
		user->setIntegerForKey("Rank2", 0);
		user->setIntegerForKey("Rank3", 0);
		user->setIntegerForKey("Rank4", 0);
		user->setIntegerForKey("Rank5", 0);
	}

	return true;
}
Beispiel #2
0
void LocalData::writeRuntimeDataToLocal()
{
	CCUserDefault* userDefault = CCUserDefault::sharedUserDefault();
	userDefault->setBoolForKey("hasmusic", RunTimeData::getInstance()->hasMusic);
	userDefault->setBoolForKey("guiderecord", RunTimeData::getInstance()->isFirstTime);
	userDefault->setStringForKey("levelStarStr", RunTimeData::getInstance()->levelStars);
	userDefault->setIntegerForKey("passedLevelNum", RunTimeData::getInstance()->passedLevel);
	userDefault->setIntegerForKey("totalStarNum", RunTimeData::getInstance()->startNum);
	userDefault->setIntegerForKey("annihilator", RunTimeData::getInstance()->annihilatorNum);
	userDefault->setBoolForKey("isFirstTime", RunTimeData::getInstance()->isFirstTime);
	userDefault->flush();
}
Beispiel #3
0
void Config::flush() {
	CCUserDefault* ud = CCUserDefault::sharedUserDefault();
	ud->setBoolForKey(CONFIG_KEY_MUTE, m_mute);
	ud->setBoolForKey(CONFIG_KEY_HASSAVEDPUZZLE, m_hasSavedPuzzle);
	ud->setIntegerForKey(CONFIG_KEY_HIGHSCORE, m_highScore);
	ud->setIntegerForKey(CONFIG_KEY_HIGHLEVEL, m_highLevel);
	ud->setIntegerForKey(CONFIG_KEY_SAVEDSCORE, m_savedScore);
	ud->setIntegerForKey(CONFIG_KEY_SAVEDTARGET, m_savedTarget);
	ud->setIntegerForKey(CONFIG_KEY_SAVEDLEVEL, m_savedLevel);
	ud->setIntegerForKey(CONFIG_KEY_SAVEDROW, m_savedRow);
	ud->setIntegerForKey(CONFIG_KEY_SAVEDCOL, m_savedCol);
	ud->setStringForKey(CONFIG_KEY_SAVEDPUZZLE, m_savedPuzzle);
	ud->flush();
}
Beispiel #4
0
void GameConfig::setTutorialProgress(PH::TutorialProgress progress)
{
    tutorialMode = progress;
    CCUserDefault* user = CCUserDefault::sharedUserDefault();
    user->setIntegerForKey(CONFIG_TUTORIAL_PROGRESS, tutorialMode);
    user->flush();
}
Beispiel #5
0
void GameConfig::save()
{
    std::string playerUID = PlayerData::getInstance()->player->uid;

    CCUserDefault* user = CCUserDefault::sharedUserDefault();

    user->setBoolForKey((playerUID + "_instance_stage").c_str(),
                        showInstanceStage);
    user->setBoolForKey((playerUID + "_soul_exchange").c_str(),
                        showSoulExchange);
    user->setBoolForKey((playerUID + "_shuffle_relation").c_str(),
                        showShuffleRelation);
    user->setBoolForKey((playerUID + "_first_time_neili").c_str(),
                        firstTimeNeili);
    user->setBoolForKey((playerUID + "_first_time_instance").c_str(),
                        firstTimeShowInstance);
    user->setBoolForKey((playerUID + "_first_time_zhuansheng").c_str(),
                        firstTimeZhuansheng);

    user->setIntegerForKey((playerUID + "_open_instance").c_str(), openInstanceStep);
    user->setBoolForKey((playerUID + "_open_jueding10").c_str(), openJueDing10);

    user->setBoolForKey((playerUID + "_show_drag_hint").c_str(), showDragHint);
    user->setBoolForKey((playerUID + "_show_attr_hint").c_str(), showAttrHint);

    user->flush();
}
Beispiel #6
0
void GameData::saveSettings()
{
    
#if (ANDROIDSAVEBYUSERDEFAULT == 1 && CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
    JNI_setBool("IsBeginner", gd_isBeginner);
    JNI_setInt("HighScore", gd_highScore);
    JNI_setInt("Gold", gd_gold);
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
    CCUserDefault* write = CCUserDefault::sharedUserDefault();
    write->setBoolForKey("IsBeginner", gd_isBeginner);
    write->setIntegerForKey("HighScore", gd_highScore);
    write->setIntegerForKey("Gold", gd_gold);
    write->flush();
#endif
    
}
Beispiel #7
0
void GameScene::saveScore()
{
	CCUserDefault* ud = CCUserDefault::sharedUserDefault();
	int rank;
	for( rank=1; rank<= 5 ; ++rank){
		char key[4];
		sprintf( key, "Score%dth", rank);
		int score = ud->getIntegerForKey(key,0);
		if( score < m_score )
			break;
	}
	for( int i = 5; i > rank ; --i){
		char key_src[4];
		sprintf( key_src, "Score%dth", i-1);
		char key_dst[4];
		sprintf( key_dst, "Score%dth", i);
		ud->setIntegerForKey(key_dst, ud->getIntegerForKey(key_src,0));
	}
	char key[4];
	sprintf( key, "Score%dth", rank);
	ud->setIntegerForKey(key, m_score);

	CCSprite* crown = NULL;
	switch(rank){
	case 1:
		crown = CCSprite::create("crown_gold.png");
		break;
	case 2:
		crown  = CCSprite::create("crown_silver.png");
		break;
	case 3:
		crown = CCSprite::create("crown_bronze.png");
		break;
	}
	if( crown ){
		crown->setPosition(ccp(m_winSize.width/2,m_winSize.height * 0.7));
		crown->setOpacity(0);
		crown->setScale(0);
		this->addChild(crown,kZOrderScore,kTagCrown);
		CCDelayTime* delay = CCDelayTime::create(0.8f);
		CCFadeIn* fadein = CCFadeIn::create(0.5f);
		CCScaleTo* zoomin = CCScaleTo::create(0.5f,1.0f);
		CCCallFuncN* callfunc = CCCallFuncN::create(this,callfuncN_selector(GameScene::callSkewAnim));
		crown->runAction(CCSequence::create(delay, CCSpawn::createWithTwoActions(fadein, zoomin),callfunc,NULL));
	}
}
Beispiel #8
0
void GameData::saveSettings()
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
    CCUserDefault* write = CCUserDefault::sharedUserDefault();
    write->setBoolForKey("IsExisted", _isExisted);
    write->setIntegerForKey("HighScore", _highScore);
    write->flush();
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
    JNI_setBool("IsExisted", _isExisted);
    JNI_setInt("HighScore", _highScore);
#endif
}
Beispiel #9
0
bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    CCDirector* pDirector = CCDirector::sharedDirector();
    CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();

    pDirector->setOpenGLView(pEGLView);
	
    // turn on display FPS
    pDirector->setDisplayStats(true);

    // set FPS. the default value is 1.0/60 if you don't call this
    pDirector->setAnimationInterval(1.0 / 60);

    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    float fx = winSize.width / DESIGN_RESOLUTION_WIDTH;
    float fy = winSize.height / DESIGN_RESOLUTION_HEIGHT;
    if (fx > fy)
        g_fResScale = fx;
    else
        g_fResScale = fy;
    
    // create a scene. it's an autorelease object
    // run
    
    CCUserDefault* userdata = CCUserDefault::sharedUserDefault();
    if (!userdata->getIntegerForKey(LEVEL))
    {
        userdata->setIntegerForKey(LEVEL, 1);
    }
    
    CCScene *pScene = LogoScene::scene();
    pDirector->runWithScene(pScene);
//    pDirector->runWithScene(CarGame::scene());
//    pDirector->runWithScene(NinjaScene::scene());

    return true;
}
Beispiel #10
0
void Level::setCurrentLevel(int number) {
	CCUserDefault* db = CCUserDefault::sharedUserDefault();
	db->setIntegerForKey(CURRENT_LEVEL_KEY, number);
	db->flush();
}
Beispiel #11
0
void Logic::storeData() {
    CCUserDefault *u = CCUserDefault::sharedUserDefault();
    u->setStringForKey("loginName", loginName);
    u->setStringForKey("nickname", nickname);
    u->setIntegerForKey("uid", uid);
}
// Initialize our Main Menu Layer, and add the initial main menu with the title screen, play button and about button.
bool GameOverLayer::init()
{
    // Initialize the parent
    if (!CCLayer::init()) return false;
    
    // Load the high scores
    CCUserDefault *store = CCUserDefault::sharedUserDefault();
    int bestScore = store->getIntegerForKey("best-score", 0);
    int bestDistance = store->getIntegerForKey("best-distance", 0);
    int bestDifficulty = store->getIntegerForKey("best-difficulty", 0);
    bool newRecord = false;
    
    if (GameManager::sharedGameManager()->getScore() > bestScore && GameManager::sharedGameManager()->getDistance() > bestDistance)
    {
        bestScore = GameManager::sharedGameManager()->getScore();
        bestDistance = GameManager::sharedGameManager()->getDistance();
        bestDifficulty = GameManager::sharedGameManager()->getDifficulty();
        store->setIntegerForKey("best-score", bestScore);
        store->setIntegerForKey("best-distance", bestDistance);
        store->setIntegerForKey("best-difficulty", bestDifficulty);
        store->flush();
        newRecord = true;
    }
    
    // Set the screen size to the full dimensions of the device (full screen)
    this->setContentSize(SCREEN_SIZE);
    
    float labelScaleText = 1.2f;
    if (GameManager::sharedGameManager()->getDeviceType() == kDeviceTypeAndroid854x480 ||
        GameManager::sharedGameManager()->getDeviceType() == kDeviceTypeAndroid800x480 ||
        GameManager::sharedGameManager()->getDeviceType() == kDeviceTypeAndroid800x400 ||
        GameManager::sharedGameManager()->getDeviceType() == kDeviceTypeAndroid720x480)
    {
        labelScaleText = 0.9f;
    }
    else if (GameManager::sharedGameManager()->getDeviceSize() == kDeviceSizeNormal)
    {
        labelScaleText = 1.0f;
    }
    else if (GameManager::sharedGameManager()->getDeviceSize() == kDeviceSizeSmall)
    {
        labelScaleText = 0.5f;
    }
    
    CCSprite *gameOverTitle = CCSprite::createWithSpriteFrameName("game_over.png");
    gameOverTitle->setScale(0.9f);
    gameOverTitle->setPosition(ccp(SCREEN_WIDTH/2, SCREEN_HEIGHT*0.8));
    this->addChild(gameOverTitle);
    
    CCString *score = CCString::createWithFormat("YOUR SCORE: %i", GameManager::sharedGameManager()->getScore());
    CCLabelBMFont *scoreLabel = CCLabelBMFont::create(score->getCString(), "myGlyphs.fnt");
    scoreLabel->setScale(labelScaleText);
    scoreLabel->setPosition(ccp(SCREEN_WIDTH/2, SCREEN_HEIGHT*0.65));
    this->addChild(scoreLabel);
    
    CCString *distance = CCString::createWithFormat("YOUR DISTANCE: %i", GameManager::sharedGameManager()->getDistance());
    CCLabelBMFont *distanceLabel = CCLabelBMFont::create(distance->getCString(), "myGlyphs.fnt");
    distanceLabel->setScale(labelScaleText);
    distanceLabel->setPosition(ccp(SCREEN_WIDTH/2, SCREEN_HEIGHT*0.59));
    this->addChild(distanceLabel);
    
    CCString *ydifficulty;
    switch (GameManager::sharedGameManager()->getDifficulty())
    {
        case 3:
            ydifficulty = CCString::create("HARD");
            break;
        case 2:
            ydifficulty = CCString::create("MEDIUM");
            break;
        default:
            ydifficulty = CCString::create("EASY");
    }
    
    CCString *difficulty = CCString::createWithFormat("YOUR DIFFICULTY: %s", ydifficulty->getCString());
    CCLabelBMFont *difficultyLabel = CCLabelBMFont::create(difficulty->getCString(), "myGlyphs.fnt");
    difficultyLabel->setScale(labelScaleText);
    difficultyLabel->setPosition(ccp(SCREEN_WIDTH/2, SCREEN_HEIGHT*0.53));
    this->addChild(difficultyLabel);
    
    CCString *highScore = CCString::createWithFormat("HIGH SCORE: %i", bestScore);
    CCLabelBMFont *highScoreLabel = CCLabelBMFont::create(highScore->getCString(), "myGlyphs.fnt");
    highScoreLabel->setScale(labelScaleText);
    highScoreLabel->setPosition(ccp(SCREEN_WIDTH/2, SCREEN_HEIGHT*0.43));
    this->addChild(highScoreLabel);
    
    CCString *highDistance = CCString::createWithFormat("BEST DISTANCE: %i", bestDistance);
    CCLabelBMFont *highDistanceLabel = CCLabelBMFont::create(highDistance->getCString(), "myGlyphs.fnt");
    highDistanceLabel->setScale(labelScaleText);
    highDistanceLabel->setPosition(ccp(SCREEN_WIDTH/2, SCREEN_HEIGHT*0.37));
    this->addChild(highDistanceLabel);
    
    CCString *bdifficulty;
    switch (bestDifficulty)
    {
        case 3:
            bdifficulty = CCString::create("HARD");
            break;
        case 2:
            bdifficulty = CCString::create("MEDIUM");
            break;
        default:
            bdifficulty = CCString::create("EASY");
    }
    
    CCString *highDifficulty = CCString::createWithFormat("DIFFICULTY: %s", bdifficulty->getCString());
    CCLabelBMFont *highDifficultyLabel = CCLabelBMFont::create(highDifficulty->getCString(), "myGlyphs.fnt");
    highDifficultyLabel->setScale(labelScaleText);
    highDifficultyLabel->setPosition(ccp(SCREEN_WIDTH/2, SCREEN_HEIGHT*0.31));
    this->addChild(highDifficultyLabel);
    
    // Play again button
    createPlayAgainButton();
    
    // Play Game Over Sound
    CocosDenshion::SimpleAudioEngine::sharedEngine()->setEffectsVolume(1.0f);
    CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("sfx_gameover.mp3", false);
    
    // Do new record animation
    if (newRecord)
    {
        // TODO
    }
    
    // Initialization was successful
    return true;
}
Beispiel #13
0
void SGWelComeLayer::requestFinished(int msgid, CCObject *data)
{
    CCLOG("收到数据");
    switch (msgid)
    {
        case MSG_HTTP_FAST_LOGIN:
        {
            std::string serverip = CCUserDefault::sharedUserDefault()->getStringForKey("serverip");
            short serverpost = (short)CCUserDefault::sharedUserDefault()->getIntegerForKey("serverpost");
            
            //记录服务器ip和端口号
            SGMainManager::shareMain()->setServerInfo(CCString::create(serverip.c_str()) , serverpost);
            
            //连接socket
            SGSocketClient::sharedSocketClient()->startConn(serverip.c_str() , serverpost);
            
        }
            break;
        case MSG_HTTP_LOGIN:
        {
            int isLogin = SGMainManager::shareMain()->getIsFBLogin();
            if (isLogin != 1 || !SGMainManager::shareMain()->getIsFbAutologin())
            {
                std::string serverip = CCUserDefault::sharedUserDefault()->getStringForKey("serverip");
                int serverpost = CCUserDefault::sharedUserDefault()->getIntegerForKey("serverpost");
                SGSocketClient::sharedSocketClient()->startConn(serverip.c_str() ,(short)serverpost);
            }
            else
            {
                SGMainManager::shareMain()->setIsFbAutologin(false);
            }
        }
            break;
        case MSg_HTTP_SERVERLIST:
        {
            SGServerListLayer *box = SGServerListLayer::create(this, (CCArray *)data, SGServerListLayerComeFromFirst);
            SGMainManager::shareMain()->showBox(box,false);

            
        }
            break;
        case MSG_HTTP_UPDATE_SERVER_STATE:
        {
            CCDictionary *dict = (CCDictionary*)data;
            CCString *serverIp = (CCString*)dict->objectForKey("serverIp");
            CCString *serverPost = (CCString*)dict->objectForKey("serverPost");
            CCString *serverId = (CCString*)dict->objectForKey("serverId");
            CCString *serverShowId = (CCString*)dict->objectForKey("serverShowId");
            CCString* serverName = (CCString*)dict->objectForKey("serverName");
            //保存即将登陆的服务器的描述
            serverDes = ((CCString * )dict->objectForKey("serverDes") )->m_sString;
            //save ip and post of server
            CCUserDefault::sharedUserDefault()->setIntegerForKey("serverid",serverId->intValue());
            CCUserDefault::sharedUserDefault()->setIntegerForKey("serverShowId", serverShowId->intValue());
            CCUserDefault::sharedUserDefault()->setStringForKey("serverip", serverIp->getCString());
            CCUserDefault::sharedUserDefault()->setIntegerForKey("serverpost", serverPost->intValue());
            CCUserDefault::sharedUserDefault()->setStringForKey("servername", serverName->getCString());
            CCUserDefault::sharedUserDefault()->flush();
            
            
            CCLog("最新服务器 ip=%s\n post=%s\n id=%s\n name=%s",serverIp->getCString(),serverPost->getCString(),serverId->getCString(),serverName->getCString());
            
            changeServerbtn->setFont(serverName->getCString());
            CCUserDefault::sharedUserDefault()->setStringForKey("servername", serverName->getCString());
            
            //如果是维护中 则不再登陆。
            short serverState = (short)(  ( (CCString *)dict->objectForKey("serverState") )->intValue() );
            if (1 != serverState)
            {
                ;
            }
            //提示不能登陆的详细信息。
            else
            {
                SGMainManager::shareMain()->showMessage(serverDes.c_str());
            }
            //MM: 即使维护中,也尝试登录,101用户会自动放过。
            this->realLogin();
        }
            break;

        case MSg_HTTP_LASTESTSERVER:
        {
            CCDictionary *dict = (CCDictionary*)data;
            CCString *serverIp = (CCString*)dict->objectForKey("serverIp");
            CCString *serverPost = (CCString*)dict->objectForKey("serverPost");
            CCString *serverId = (CCString*)dict->objectForKey("serverId");
            CCString* serverName = (CCString*)dict->objectForKey("serverName");
            //保存即将登陆的服务器的描述
            serverDes = ((CCString * )dict->objectForKey("serverDes") )->m_sString;
            //save ip and post of server
            CCUserDefault::sharedUserDefault()->setIntegerForKey("serverid",serverId->intValue());
            CCUserDefault::sharedUserDefault()->setStringForKey("serverip", serverIp->getCString());
            CCUserDefault::sharedUserDefault()->setIntegerForKey("serverpost", serverPost->intValue());
            CCUserDefault::sharedUserDefault()->setStringForKey("servername", serverName->getCString());
            CCUserDefault::sharedUserDefault()->flush();
            
            
            CCLog("最新服务器 ip=%s\n post=%s\n id=%s\n name=%s",serverIp->getCString(),serverPost->getCString(),serverId->getCString(),serverName->getCString());
            
            changeServerbtn->setFont(serverName->getCString());
            CCUserDefault::sharedUserDefault()->setStringForKey("servername", serverName->getCString());
            
        }
            break;
        case MSG_HTTP_GET_CHANNEL_USER_ID:
        {
            CCDictionary* dict = (CCDictionary*) data;
            CCUserDefault* ccud = CCUserDefault::sharedUserDefault();
            CCString* actId = (CCString*) dict->objectForKey("sdkAccountId");
            ccud->setStringForKey("userId", actId->m_sString);
            ccud->setStringForKey("username", actId->m_sString);
            ccud->setStringForKey("password", actId->m_sString);
            ccud->setIntegerForKey("channelId", GlobalConfig::gi()->getRealChannelId());
#if (GCCT_CHINA_UC_ADR_THIRD == GAME_CHANNEL_TYPE) //uc adr
            //MM: 将本次s_sid作为loginkey,登入使用。
            ccud->setStringForKey("loginKey", UCSdk::s_sid);
#elif (GCCT_CHINA_KUAIYONG_IOS_THIRD == GAME_CHANNEL_TYPE)
            //MM: 将快用的tokenKey作为loginkey,登入使用。
            ccud->setStringForKey("loginKey", ( (KuaiYongIosImp*) SdkController::gi()->getSdkImp() )->kyToken );
#else
            
#endif
            CCString* nickName = (CCString*) dict->objectForKey("sdkNickName");
            ccud->setStringForKey("sdk_user_nick_name", nickName->m_sString);
            //还有一个"sdkCreator"字段,但是未起作用,所以没有在这里添加。
            registerBtn->setFont(nickName->getCString()); //将按钮文本变为其uc账号昵称。

            ccud->setBoolForKey("isExist", true);
            ccud->setBoolForKey("isAccount", true);
            ccud->flush();
            //MMD: SDKIF SDK登陆成功!仅当21号http消息完成后,才设置SDK登陆成功标志,其他情况一概无视。
            ExtClassOfSDK::sharedSDKInstance()->setIsLoginSDK(true);
            //添加的针对非注册体系下的td数据设置,目前有uc在使用。
            ExtClassOfSDK::sharedSDKInstance()->setTdData(actId->m_sString, nickName->m_sString);
        }
            break;
        default:
            break;
    }
    SGMainManager::shareMain()->getMainScene()->plat->removeConnection();
}