예제 #1
0
void GameWin::syncFlow()
{
	AppDelegate *app = (AppDelegate*)Application::getInstance();
	std::string  strFlow= updateFlow();//read local and add current

	NetworkType Networ = app->GetNetWorkStatus();
	if (Networ != NetworkTypeNone)
	{
		if (m_UserID > 0 && strFlow.length()>0)
		{
			_UserInfo userInfo = DataAccess::getUserInfoByID(m_UserID);
			HttpRequest* request = new HttpRequest();
			request->setUrl(UCAPIWebPostURL);
			request->setRequestType(HttpRequest::Type::POST);
			request->setResponseCallback(CC_CALLBACK_2(GameWin::onSyncCompleted, this));

			//char p[10];
			//sprintf(p, "%s", strFlow);
			std::string sPost = "action=save_user_info&EncryptData=";

			long lUserDiff = app->GetUserScoreDiff();
			int iLevel = app->GetUserLevel();


			char p1[10];
			char p2[10];
			char p3[10];
			sprintf(p1, "%d", lUserDiff);
			sprintf(p2, "%d", iLevel);
			string s1 = p1;
			string s2 = p2;

			//std::string sPost = "action=sync_point&EncryptData=";
			int iTools = app->GetToolsDiff();
			sprintf(p3, "%d", iTools);
			string s4 = p3;

			string s3 = "score = " + strFlow + "&local_point = " + s1 + "&LV = " + s2 + "&UserID = " + userInfo.strUserGuid+"&VirtualPops=" + s4;
			s3 = app->encode_data_for_http(s3);
			sPost = sPost + s3;
			sPost = sPost + "&" + app->GetAccessString();

			const char* postData = sPost.c_str();
			request->setRequestData(postData, strlen(postData));
			request->setTag("save_ranking");
			cocos2d::network::HttpClient::getInstance()->send(request);
			request->release();
		}
		else updateLocalFlow();//not login or read local error
	}
	else
	{
		updateLocalFlow();//no network
	}
}
예제 #2
0
void GameWin::touchButton(Object* obj,::ui::Widget::TouchEventType eventType)  
{  
    auto button = dynamic_cast<::ui::Button*>(obj);  
    int tag = button->getTag();  
    
	
	auto node =(Node*) this->getChildByTag(CHILD_TURNTABLE);
	if (node != nullptr) {
		return;
	}

	AppDelegate *app = (AppDelegate*)Application::getInstance();

	switch(eventType)  
    {  
	case ::ui::Widget::TouchEventType::ENDED:  

	if (app->getBGMstatus() == BGMusic_flag::ON){
		app->PlayEffect(SOUND_BUTTON_CLICK);

	}
		if(tag==1001){ //Continue

			if(app->GetNetWorkStatus() != NetworkType::NetworkTypeNone){
				std::string sGuid = app->GetUserGuid();
				log("GUID is %s", sGuid.c_str());
				if (sGuid.length() == 0){ // not a registered user
					if (m_iShowRegister == 5){
						MsgBoxType m_type = TP_Q_YESNO;;
						std::string title="Tweebaa";
						std::string msg = MSG_REGISTER_MSG;
						std::string info = "\0";
				
						MsgBox::setMsgBox(m_type, &title, &msg, &info);
						auto msgbox = MsgBox::create();
						auto btnYES = dynamic_cast<Button*>(msgbox->getChildByTag(MSGBOX_UINODE)->getChildByName("btn_Yes"));// Magnifier Button
						btnYES->setTitleFontSize(36);
						btnYES->setTitleText("YES");
						btnYES->addTouchEventListener(CC_CALLBACK_2(GameWin::CallbackRegisterYes, this));
						auto btnNO = dynamic_cast<Button*>(msgbox->getChildByTag(MSGBOX_UINODE)->getChildByName("btn_No"));// Magnifier Button
						btnNO->setTitleText("NOT NOW");
						btnNO->setTitleFontSize(36);
						btnNO->addTouchEventListener(CC_CALLBACK_2(GameWin::CallbackRegisterNo, this));
						msgbox->setTag(MSGBOX_TAG);
						this->addChild(msgbox, 999);
						//m_iShowRegister = 0;
						break;
					}else{
						//m_iShowRegister++;
					}
				}
			}

			if(m_iCurrentGameID == 1){
				auto scene = FindDiffScene::create();
				TransitionScene *transition = TransitionFade::create(1, scene);
				Director::getInstance()->replaceScene(transition);
			}else if(m_iCurrentGameID == 2){
				auto scene = ZoomGameScene::create();
				TransitionScene *transition = TransitionFade::create(1, scene);
				Director::getInstance()->replaceScene(transition);
			}else if (m_iCurrentGameID == 3){
				auto scene = jigSawScene::create();
				TransitionScene *transition = TransitionFade::create(1, scene);
				Director::getInstance()->replaceScene(transition);
			}else if (m_iCurrentGameID == 4){
				auto scene = GameScene::create();
				TransitionScene *transition = TransitionFade::create(1, scene);
				Director::getInstance()->replaceScene(transition);
			}else if (m_iCurrentGameID == 5){
				auto scene = PriceMatchScene::create();
				TransitionScene *transition = TransitionFade::create(1, scene);
				Director::getInstance()->replaceScene(transition);
			}else if (m_iCurrentGameID == 6){
				auto scene = MultiPriceMatchScene::create();
				TransitionScene *transition = TransitionFade::create(1, scene);
				Director::getInstance()->replaceScene(transition);
			}else{
				auto scene = WelcomeScene::create();
				TransitionScene *transition = TransitionFade::create(1, scene);
				Director::getInstance()->replaceScene(transition);			
			}


			//if(m_iCurrentGameID == 3){
			//	auto scene = jigSawScene::create();
			//	//auto scene = LevelSelectLayer::createScene();
			//	TransitionScene *transition = TransitionFade::create(1, scene);
			//	Director::getInstance()->replaceScene(transition);
			//}
			//if(m_iCurrentGameID == 4){
			//	auto scene = GameScene::create();
			//	//auto scene = LevelSelectLayer::createScene();
			//	TransitionScene *transition = TransitionFade::create(1, scene);
			//	Director::getInstance()->replaceScene(transition);
			//}
			//if(m_iCurrentGameID == 5){
			//	auto scene = PriceMatchScene::create();
			//	//auto scene = LevelSelectLayer::createScene();
			//	TransitionScene *transition = TransitionFade::create(1, scene);
			//	Director::getInstance()->replaceScene(transition);
			//}


		}
		if(tag==1002){ // Quit

			/*
			AppDelegate *app = (AppDelegate*)Application::getInstance();
			 std::string sCSD=app->GetLayoutString();
			_quitNode = CSLoader::createNode("res/quit_game/QuitGameLayer"+sCSD+".csb");

			this->addChild(_quitNode,15,4001);

			auto btnNo = dynamic_cast<Button*>(_quitNode->getChildByName("btnNo"));
			btnNo->setTag(2001);
			btnNo->setTitleText("No");
			btnNo->addTouchEventListener(CC_CALLBACK_2(GameWin::touchButton, this));	

			auto btnYes = dynamic_cast<Button*>(_quitNode->getChildByName("btnYes"));
			btnYes->setTag(2002);
			btnYes->setTitleText("Yes");
			btnYes->addTouchEventListener(CC_CALLBACK_2(GameWin::touchButton, this));	
			*/
			//MsgBoxType m_type = TP_Q_YESNO;
			//std::string title = MSG_QUIT_TITLE;
			//std::string msg = MSG_QUIT_MSG;

			//MsgBox::setMsgBox(m_type, &title, &msg);
			//auto msgbox = MsgBox::create();
			//msgbox->setTag(9000);
			//this->addChild(msgbox, 999);

			////Add Event to process
			//auto btnYes = dynamic_cast<Button*>(msgbox->getChildByTag(MSGBOX_UINODE)->getChildByName("btn_Yes"));// Magnifier Button
			//auto btnNo = dynamic_cast<Button*>(msgbox->getChildByTag(MSGBOX_UINODE)->getChildByName("btn_No"));// Magnifier Button
			//btnYes->addTouchEventListener(CC_CALLBACK_2(GameWin::yesCallback, this));
			//btnNo->addTouchEventListener(CC_CALLBACK_2(GameWin::noCallback, this));

			auto scene = WelcomeScene::create();
			if(scene == nullptr) break;

			TransitionScene *transition = TransitionFade::create(1, scene);
			Director::getInstance()->replaceScene(transition);

		}
		if(tag==1003){ //Buy Now
			/*
			auto scene = CheckoutScene::create();
			//scene->sProductID= m_strProductGUID;
			TransitionScene *transition = TransitionFade::create(1, scene);
			Director::getInstance()->replaceScene(transition);*/
			//Application::getInstance()->openURL("https://www.tweebaa.com/Product/prdSaleAll.aspx");
			
			std::string str = m_PrmtPrdct.m_strProductURL;
			str.append(ACTION_BUYNOW);
			Application::getInstance()->openURL(str);
		}
		if(tag==1004){ //share
			std::string str = m_PrmtPrdct.m_strProductURL;
			str.append(ACTION_SHARE);
			Application::getInstance()->openURL(str);

			//#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
			//	CCDictionary *content = CCDictionary::create();
			//	content -> setObject(CCString::create(m_strProductName), "content");
			//	content -> setObject(CCString::create(m_strImage), "image");
			//	content -> setObject(CCString::create("Tweebaa App"), "title");
			//	content -> setObject(CCString::create("I win the game"), "description");
			//	content -> setObject(CCString::create("http://tweebaa.com"), "url");
			//	content -> setObject(CCString::createWithFormat("%d", C2DXContentTypeNews), "type");
			//	content -> setObject(CCString::create("http://tweebaa.com"), "siteUrl");
			//	content -> setObject(CCString::create("Tweebaa"), "site");
			//	//content -> setObject(CCString::create("http://mp3.mwap8.com/destdir/Music/2009/20090601/ZuiXuanMinZuFeng20090601119.mp3"), "musicUrl");
			//	content -> setObject(CCString::create("extInfo"), "extInfo");
   // 
			//	C2DXShareSDK::showShareMenu(NULL, content, CCPointMake(100, 100), C2DXMenuArrowDirectionLeft, Gamewin_shareResultHandler);
	
			//#endif

		}
		if(tag==2001){
			/*
			Layer* background =(Layer*)this->getChildByTag(4001);
			background->removeFromParentAndCleanup(true);
			*/
			_quitNode->removeFromParentAndCleanup(true);
		}
		if(tag==2002){
			/*
		    Director::getInstance()->end();

			#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
				exit(0);
			#endif
			*/
			auto scene = WelcomeScene::create();
			TransitionScene *transition = TransitionFade::create(1, scene);
			Director::getInstance()->replaceScene(transition);

		}
		break;
	}

}