예제 #1
0
void MultiPriceMatch::yesCallback(cocos2d::Ref* pSender, cocos2d::ui::Widget::TouchEventType type){
    if (type == cocos2d::ui::Widget::TouchEventType::ENDED){

		AppDelegate *app = (AppDelegate*)Application::getInstance();
		if (app->getBGMstatus() == BGMusic_flag::ON){
			app->PlayEffect(SOUND_BUTTON_CLICK);
		}		

		_vec_circle.clear();
		_vec_circle2.clear();
		this->unschedule(schedule_selector(MultiPriceMatch::updateTimeLabel));
		//this->unschedule(schedule_selector(FindDiffLayer::updateDragMove));

		//AppDelegate *app = (AppDelegate*)Application::getInstance();
//		app->SaveGamePassLevel();
		app->moveToNextGameLevel();

		if (app->iGameMode == MobileGameMode::Theme_Mode)
		{
			auto scene = ThemeLayer::createScene();
			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);
		}

		this->removeChildByTag(9000);
        CCLOG("touch ended.");
    }
}
예제 #2
0
void MultiPriceMatch::menuKeyCallback(Ref* pSender, ui::Widget::TouchEventType eEventType){

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


	switch (eEventType) {
		case ui::Widget::TouchEventType::BEGAN:
			cocos2d::log("touch Began");
			break;
		case ui::Widget::TouchEventType::ENDED:
			cocos2d::log("touch Ended");
			if (app->getBGMstatus() == BGMusic_flag::ON){
				app->PlayEffect(SOUND_BUTTON_CLICK);
			}	
			MultiPriceMatch::gameover(); //quit the game
			break;
		case ui::Widget::TouchEventType::MOVED:
			cocos2d::log("touch Cancel");
			break;
		case ui::Widget::TouchEventType::CANCELED:
			cocos2d::log("touch Cancel");
			break;
		default:
			cocos2d::log("touch Default");
			break;
	}
	return;

}
예제 #3
0
void GameWin::CallbackRegisterNo(cocos2d::Ref* pSender, cocos2d::ui::Widget::TouchEventType type){
	if (type == cocos2d::ui::Widget::TouchEventType::ENDED)         {
	AppDelegate *app = (AppDelegate*)Application::getInstance();
	if (app->getBGMstatus() == BGMusic_flag::ON){
		app->PlayEffect(SOUND_BUTTON_CLICK);
	}

	switch (m_iCurrentGameID){
			case 1:{
				auto scene = FindDiffScene::create();
				TransitionScene *transition = TransitionFade::create(1, scene);
				Director::getInstance()->replaceScene(transition);
			}
				   break;

			case 2:{
				auto scene = ZoomGameScene::create();
				TransitionScene *transition = TransitionFade::create(1, scene);
				Director::getInstance()->replaceScene(transition);
			}
				   break;
			case 3:{


				auto scene = jigSawScene::create();

				TransitionScene *transition = TransitionFade::create(1, scene);
				Director::getInstance()->replaceScene(transition);
			}
				   break;
			case 4:{
				auto scene = GameScene::create();


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

			case 5:{
				auto scene = PriceMatchScene::create();


				TransitionScene *transition = TransitionFade::create(1, scene);
				Director::getInstance()->replaceScene(transition);
			}
				   break;
			case 6:
			{
				auto scene = MultiPriceMatchScene::create();
				TransitionScene *transition = TransitionFade::create(1, scene);
				Director::getInstance()->replaceScene(transition);
			}
		}			
		this->removeChildByTag(9000);
	}
}
예제 #4
0
void GameWin::CallbackRegisterYes(cocos2d::Ref* pSender, cocos2d::ui::Widget::TouchEventType type){
	if (type == cocos2d::ui::Widget::TouchEventType::ENDED){
		AppDelegate *app = (AppDelegate*)Application::getInstance();
		if (app->getBGMstatus() == BGMusic_flag::ON){
			app->PlayEffect(SOUND_BUTTON_CLICK);
		}

		GameWin::showRegister();
	}
}
예제 #5
0
void MultiPriceMatch::PlayAnimation(float dt)
{
	Armature *armature = dynamic_cast<Armature *>(_SORT_UINode->getChildByTag(888));
	armature->getAnimation()->playWithIndex(0, -1, 0);//from the first frame, no loop
	armature->getAnimation()->setSpeedScale(0.8);
	AppDelegate* app = (AppDelegate*)Application::getInstance();
	if (app->getBGMstatus() == BGMusic_flag::ON)
	{
		app->PlayEffect(SOUND_ANIMATION);
	}
}
예제 #6
0
void MultiPriceMatch::btnPriceCallback(Ref* pSender, ui::Widget::TouchEventType eEventType){
	/*if (eEventType != ui::Widget::TouchEventType::BEGAN)*/

	CCNode* node = (CCNode*) pSender;
	int tag = node->getTag();
	bool bSel = false;

	for (int i = 0; i < 3;i++){
		if (tag == (BTN_PRICE_1 + i)) bSel = true;
	}

	if (bSel == false) return;

	cocos2d::log("button's tag is %d",tag);
	auto button = (Button*) _SORT_UINode->getChildByTag(tag);
	AppDelegate *app = (AppDelegate*)Application::getInstance();


	switch (eEventType) {
		case ui::Widget::TouchEventType::BEGAN:
			cocos2d::log("btnPriceCallback Began");
			button->getTouchBeganPosition();
			button->setZOrder(99);
			break;
		case ui::Widget::TouchEventType::ENDED:
			cocos2d::log("btnPriceCallback Ended");
			if (app->getBGMstatus() == BGMusic_flag::ON){
				app->PlayEffect(SOUND_BUTTON_CLICK);

			}	
			button->setZOrder(1);
			MovetoPriceLabel(button);
			break;
		case ui::Widget::TouchEventType::MOVED:
			button->setPosition(button->getTouchMovePosition());
			cocos2d::log("btnPriceCallback Moving");
			break;
		case ui::Widget::TouchEventType::CANCELED:
			cocos2d::log("touch Cancel");
			button->setZOrder(1);
			break;
		default:
			cocos2d::log("touch Default");
			break;
	}
	return;

}
예제 #7
0
void MultiPriceMatch::noCallback(cocos2d::Ref* pSender, cocos2d::ui::Widget::TouchEventType type){
    if (type == cocos2d::ui::Widget::TouchEventType::ENDED){
			
		AppDelegate *app = (AppDelegate*)Application::getInstance();
		if (app->getBGMstatus() == BGMusic_flag::ON){
			app->PlayEffect(SOUND_BUTTON_CLICK);
		}		
		
		//Don't quit the game
		this->removeChildByTag(9000);
		//enable the touch event
		//CallFunc *runCallback = CallFunc::create(CC_CALLBACK_0(FindDiffLayer::resetTouchEvent, this));
		//this->runAction(Sequence::create(DelayTime::create(1.0f), runCallback, nullptr));
        CCLOG("touch ended.");
    }
}
예제 #8
0
void MultiPriceMatch::ShowTutorialCallback(Ref* pSender, ui::Widget::TouchEventType eEventType){
	if (eEventType == cocos2d::ui::Widget::TouchEventType::ENDED){

		AppDelegate *app = (AppDelegate*)Application::getInstance();
		if (app->getBGMstatus() == BGMusic_flag::ON){
			app->PlayEffect(SOUND_BUTTON_CLICK);
		}		

		auto scene = TutorialScene::create();
		if(scene != nullptr){
			TransitionScene *transition = TransitionFade::create(1, scene);
			Director::getInstance()->pushScene(transition);
		}

	}
}
예제 #9
0
void GameLayer::PlayAnimation(float dt)
{
	Armature *armature = dynamic_cast<Armature *>(_rootNode->getChildByTag(888));
	if (nAniFlag == 1)
	{
		armature->setPosition(Vec2(200, 400));
		armature->setRotation(270);
		nAniFlag = 2;
	}
	else
	{
		armature->setPosition(Vec2(800, 200));
		armature->setRotation(180);
		nAniFlag = 1;
	}
	armature->getAnimation()->playWithIndex(0, -1, 0);//from the first frame, no loop
	AppDelegate* app = (AppDelegate*)Application::getInstance();
	if (app->getBGMstatus() == BGMusic_flag::ON)
	{
		app->PlayEffect(SOUND_ANIMATION);
	}
}
예제 #10
0
bool MultiPriceMatch::init(){

	bool bRet = false;
	do{
		if(!Layer::init()){
			break;
		}

		int currenlevel = 0;

		//if (_gamestatus != GAME_START) {
		//	_gamestatus = GAME_START;
		//}
		AppDelegate *app = (AppDelegate*)Application::getInstance();
		CC_BREAK_IF(!app);

		_nTlimit = 3; // total tools can be used in each game
		_nTlcount = app->getToolsNumberInfo(); // total tools user has
		_nLvl = app->GetUserLevel(); //totol tips can be used
		_fPerToNLvl = app->GetPercentToNextLevel(); //Percent to next level
		_lTtlScore = app->GetUserTotalScore();
		currenlevel = app->getCurrentGameLevel();

		_gametime = GAME_TIME_EASY;

		//_zoomin = true;
		//saveProductInfo();
		CC_BREAK_IF(!loadProductInfo());

		_SORT_UINode = CSLoader::createNode(SORT_UINODE_CSB);
		CC_BREAK_IF(_SORT_UINode == nullptr);
		_SORT_UINode->setTag(SORT_UI_NODE);
		this->addChild(_SORT_UINode);

		_vec_Price.clear();
		_vec_Price_original.clear();
		_vec_Price_index.clear();

		char strName[20] = LBL_SP_PDX;
		char strLabel[20] = IMG_PD_PRICE;
		char strBtn[20] = BTN_PD_PRICE;

		//string price, price2;

		_vec_lblPrice.clear();
		_vec_btnPrice.clear();

		std::vector <std::string> vec_price;
		std::vector <std::string> vec_Price_original;

		std::random_device rd1;
		std::mt19937 g1(rd1());
 		std::shuffle(std::begin(_product_list), std::end(_product_list), g1);


		for (int i = 0; i < 3; i++){
			std::string price = StringUtils::format("%s",_product_list[i].price.c_str());
			//log("Before: price for %d is %s",i, price.c_str());
			vec_price.push_back(price);
			vec_Price_original.push_back(price);
		}
	
		//srand(unsigned(time(NULL)));
		//std::random_shuffle(vec_price.begin(), vec_price.end());


		std::random_device rd;
		std::mt19937 g(rd());
 		std::shuffle(std::begin(vec_price), std::end(vec_price), g);

		//auto engine = std::default_random_engine();
		//std::shuffle(std::begin(vec_price), std::end(vec_price), engine);

		//for (int i = 0; i < 3; i++){
		//	log("After: price for %d is %s",i, vec_price[i].c_str());
		//}

		for (int i = 0; i < 3; i++){
			for (int j = 0; j < 3; j++){
				if (vec_Price_original[i].compare(vec_price[j].c_str()) == 0){
					_vec_Price_index.push_back(j);
				}
			}
		}

		for (int i = 0; i < 3; i++){
			log("%d", _vec_Price_index[i]);
		}

		for (int i = 0; i < 3; i++){
			log("for %d", i);
			strName[5] = LETTER_NUM_1 + i;
			strLabel[6] = LETTER_NUM_1 + i;
			strBtn[6] = LETTER_NUM_1 + i;
			//std::string price = StringUtils::format("%s",_product_list[i].price->getCString());

			//add Image
			auto sp = dynamic_cast<Sprite*>(_SORT_UINode->getChildByName(strName));
			CC_BREAK_IF(sp == nullptr);
			sp->setTag(PRODUCT_IMG_1 + i);
			//sp->setTexture(_product_list[i].image->getCString());
			sp->setTexture(_product_list[i].image.c_str());
			sp->setScale((sp->getBoundingBox().size.width/sp->getContentSize().width)*0.6);//resize to 300 
			sp->setZOrder(2);

			//sp->addTouchEventListener(CC_CALLBACK_2(MultiPriceMatch::btnPriceCallback, this));



			//add Price Label
			auto label = dynamic_cast<Sprite*>(_SORT_UINode->getChildByName(strLabel));
			CC_BREAK_IF(label == nullptr);
			label->setTag(LBL_PRICE_1 + i);
			label->setZOrder(0);
			_vec_lblPrice.push_back(label);
			//_vec_originalPos.push_back(label->getPosition());

			//add Price Button
			auto btn = dynamic_cast<Button*>(_SORT_UINode->getChildByName(strBtn));
			CC_BREAK_IF(btn == nullptr);
			btn->setTag(BTN_PRICE_1 + i);
			btn->setTitleText(vec_price[i]);
			btn->setTitleColor(ccc3(255,248,220));
			btn->setTitleFontSize(32);
			btn->setZOrder(1);
			btn->addTouchEventListener(CC_CALLBACK_2(MultiPriceMatch::btnPriceCallback, this));
			_vec_originalPos.push_back(btn->getPosition());
			_vec_btnPrice.push_back(btn);

		}

		auto lblTimer = dynamic_cast<Text*>(_SORT_UINode->getChildByName(TXT_TIMER));
		CC_BREAK_IF(lblTimer == nullptr);
		this->schedule(schedule_selector(MultiPriceMatch::updateTimeLabel), 0.01f);

		auto btnMain = dynamic_cast<Button*>(_SORT_UINode->getChildByName(BUTTON_MAIN));
		CC_BREAK_IF(btnMain == nullptr);
		//auto btnSetting = dynamic_cast<Button*>(_SORT_UINode->getChildByName(BUTTON_SETTING));
		//auto btnVoice = dynamic_cast<Button*>(_SORT_UINode->getChildByName("btnVoice"));
		auto btnQuit = dynamic_cast<Button*>(_SORT_UINode->getChildByName(BUTTON_QUIT));
		CC_BREAK_IF(btnQuit == nullptr);

		if (app->iGameMode == MobileGameMode::Theme_Mode){
			//btnMain->setVisible(false);
			//btnQuit->setVisible(false);
		}
		//auto btMagnifier = dynamic_cast<Button*>(_SORT_UINode->getChildByName("btMagnifier"));
		//Add by Long for theme mode

		//Add by Long EOF

		//test button
		btnMain->addTouchEventListener(CC_CALLBACK_2(MultiPriceMatch::menuKeyCallback, this));
		btnQuit->addTouchEventListener(CC_CALLBACK_2(MultiPriceMatch::ShowTutorialCallback, this));


		auto btnClr = dynamic_cast<Button*>(_SORT_UINode->getChildByName(BTN_CLEAR));
		CC_BREAK_IF(btnClr == nullptr);
		btnClr->addTouchEventListener(CC_CALLBACK_2(MultiPriceMatch::btnClear, this));
		btnClr->setTitleColor(ccc3(255,248,220));
		btnClr->setTitleFontSize(32);
		btnClr->setTitleText("CLEAR");
		btnClr->setVisible(false);

		auto txtClear = dynamic_cast<Text*>(_SORT_UINode->getChildByName("clear"));
		txtClear->setVisible(false);
		//btnClr->addChild(txtClear);

		auto btnSub = dynamic_cast<Button*>(_SORT_UINode->getChildByName(BTN_SUBMIT));
		CC_BREAK_IF(btnSub == nullptr);
		btnSub->addTouchEventListener(CC_CALLBACK_2(MultiPriceMatch::btnSubmit, this));
		btnSub->setTitleColor(ccc3(255,248,220));
		btnSub->setTitleFontSize(32);
		btnSub->setTitleText("SUBMIT");
		btnSub->setVisible(false);

		auto txtsubmit = dynamic_cast<Text*>(_SORT_UINode->getChildByName("submit"));
		txtsubmit->setVisible(false);

		auto txtPrice1 = dynamic_cast<Text*>(_SORT_UINode->getChildByName("price_1"));
		auto txtPrice2 = dynamic_cast<Text*>(_SORT_UINode->getChildByName("price_2"));
		auto txtPrice3 = dynamic_cast<Text*>(_SORT_UINode->getChildByName("price_3"));
		txtPrice1->setVisible(false);
		txtPrice2->setVisible(false);
		txtPrice3->setVisible(false);

		auto lvlbar = dynamic_cast<Sprite*> (_SORT_UINode->getChildByName(LINK_UI_LEVELBAR));
		lvlbar->setAnchorPoint(Vec2(0,0.5));
		//lvlbar->setPositionX(lvlbar->getPositionX()-lvlbar->getContentSize().width/2);
		lvlbar->setScaleX(_fPerToNLvl);

		auto btnTips = dynamic_cast<Button*>(_SORT_UINode->getChildByName(LINK_UI_BTN_TIPS));
		CC_BREAK_IF(btnTips == nullptr);
		btnTips->addTouchEventListener(CC_CALLBACK_2(MultiPriceMatch::ShowHintCallback, this));


		auto touchListener = EventListenerTouchOneByOne::create();
		touchListener->onTouchBegan = CC_CALLBACK_2(MultiPriceMatch::onTouchBegan, this);
		touchListener->onTouchEnded = CC_CALLBACK_2(MultiPriceMatch::onTouchEnded, this);
		touchListener->onTouchMoved = CC_CALLBACK_2(MultiPriceMatch::onTouchMoved, this);
		touchListener->onTouchCancelled = CC_CALLBACK_2(MultiPriceMatch::onTouchCancelled, this);
		_eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);

		//AppDelegate *app = (AppDelegate*)Application::getInstance();
		if (app->iGameMode == MobileGameMode::Theme_Mode){
			btnMain->setVisible(false);
			//btnSetting->setVisible(false);
			//btnVoice->setVisible(false);
			btnQuit->setVisible(false);
		}

		if ( app->getBGMstatus() == BGMusic_flag::ON){
			app->StartBGMusic(BGM_GAME);
		}

		//UserDefault *load = UserDefault::getInstance();
		//string sFirstFlip = load->getStringForKey("FIRSTTIME_LINK","0");
		//{
		//	if (atoi(sFirstFlip.c_str()) == 0)
		//	{
		//		scheduleOnce(schedule_selector(MultiPriceMatch::loadFirstTutorial), 1.1f);
		//		load->setStringForKey("FIRSTTIME_LINK", "1");
		//	}
		//}
		_bTlEnabled = true;

		//-----------------------------------add animation----------------------------------------------------------

		ArmatureDataManager::getInstance()->addArmatureFileInfo(ANIMATION_FILE);
		Armature *armature = Armature::create(ARMATURE);
		CC_BREAK_IF(armature == nullptr);
		armature->setAnchorPoint(Vec2(0.5, 0.5));
		armature->setVisible(true);
		armature->setPosition(Vec2(235, 480));
		armature->setTag(888);
		auto imgBackFrame = dynamic_cast<Sprite*> (_SORT_UINode->getChildByName(BOARD));
		CC_BREAK_IF(imgBackFrame == nullptr);
		imgBackFrame->setZOrder(1);
		schedule(schedule_selector(MultiPriceMatch::PlayAnimation), 5.0f);
		_SORT_UINode->addChild(armature);


		//-------------------------------------------------------------------------------------
		bRet = true;
	}while(0);

	return bRet;
}
예제 #11
0
bool GameLayer::init()
{
	iTotalTime = 30;
	spCard.clear();//clear it first
	if (Layer::init())
	{

		//-----------------------------------Setup basic settings-----------------------------------------
		//get the origin point of the X-Y axis, and the visiable size of the screen
		Size visiableSize = Director::getInstance()->getVisibleSize();
		Point origin = Director::getInstance()->getVisibleOrigin();

		AppDelegate *app = (AppDelegate*)Application::getInstance();
		std::string sCSD = app->GetLayoutString();
		_rootNode = CSLoader::createNode("res/memory_game/flip" + sCSD + ".csb");
		addChild(_rootNode, 1);

		SpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("Flip_Level.plist");
		thetime = 0;
		iFirstCard = -1;
		iSecondCard = -1;

		//--------------------------------------Setup common gadgets-------------------------------------
		_nTlimit = 3; // total tools can be used in each game
		_nTlcount = app->getToolsNumberInfo(); // total tools user has
		_nLvl = app->GetUserLevel(); //totol tips can be used
		_fPerToNLvl = app->GetPercentToNextLevel(); //Percent to next level
		_lTtlScore = app->GetUserTotalScore();

		auto btnTips = dynamic_cast<::ui::Button*>(_rootNode->getChildByName("btnTips"));
		if (btnTips){
			btnTips->setTag(2001);
			btnTips->addTouchEventListener(CC_CALLBACK_2(GameLayer::touchButton, this));
		}
		auto button_Main = dynamic_cast<::ui::Button*>(_rootNode->getChildByName("button_Main"));
		if (button_Main){
			button_Main->setTag(2002);
			button_Main->addTouchEventListener(CC_CALLBACK_2(GameLayer::touchButton, this));
		}
		auto btnTipsTools = dynamic_cast<::ui::Button*>(_rootNode->getChildByName("btnTipsTools"));
		if (btnTipsTools){
			btnTipsTools->setTag(2003);
			btnTipsTools->addTouchEventListener(CC_CALLBACK_2(GameLayer::touchButton, this));
		}

		if (app->iGameMode == MobileGameMode::Theme_Mode){
			//button_Main->setVisible(false);
			//btnTips->setVisible(false);
		}
		auto timerLabel = dynamic_cast<::ui::Text*>(_rootNode->getChildByName("lblTimer"));

		auto lvlbar = dynamic_cast<Sprite*> (_rootNode->getChildByName("lv_bar_4"));
		lvlbar->setAnchorPoint(Vec2(0, 0.5));
		lvlbar->setScaleX(_fPerToNLvl);

		if (app->getBGMstatus() == BGMusic_flag::ON)
		{
			app->StartBGMusic(BGM_GAME);
		}

		//----------------------------------create a random array------------------------------------
		int iDiv = iMaxCard / 2;
		int* array1 = new int[iMaxCard / 2];
		int* array2 = new int[iMaxCard / 2];
		int* unique_array = new int[iMaxCard];
		int* array4 = new int[iMaxCard];
		int i = 0;
		for (i = 0; i<iDiv; i++)
		{
			array1[i] = i;
			array2[i] = i;
		}
		randomArray(array1, iMaxCard / 2);
		randomArray(array2, iMaxCard / 2);
		for (i = 0; i<iMaxCard; i++)
		{
			unique_array[i] = i;
		}
		for (i = 0; i<iDiv; i++)
		{
			array4[i] = array1[i];
		}
		for (i = iDiv; i<iMaxCard; i++)
		{
			array4[i] = array2[i - iDiv];
		}
		randomArray(unique_array, iMaxCard);
		for (i = 0; i<iMaxCard; i++)
		{
			unique_array[i] = array4[unique_array[i]];
			log("i=%d,%d", i, array4[unique_array[i]]);
		}
		//setup brick content
		srand((unsigned)time(0));//set rand() with real
		int random = rand();
		sprintf(sFile[0], "%s", sGame[random%MUST_HAVE]);
		sprintf(sFile[1], "%s", sGame[MUST_HAVE + int(random % (IMAGE_COUNT - MUST_HAVE) / 3)]);
		sprintf(sFile[2], "%s", sGame[MUST_HAVE + int((IMAGE_COUNT - MUST_HAVE) / 3) + int(random % (IMAGE_COUNT - MUST_HAVE) / 3)]);
		sprintf(sFile[3], "%s", sGame[MUST_HAVE + int((IMAGE_COUNT - MUST_HAVE) / 3) * 2 + int(random % (IMAGE_COUNT - MUST_HAVE) / 3)]);

		auto memory_bg_2 = dynamic_cast<Sprite*>(_rootNode->getChildByName("memory_bg_2"));
		if (memory_bg_2){
			memory_bg_2->setZOrder(-100);

		}

		//-----------------------------------------Touch Event Create----------------------------------------------------
		auto touchListener1 = EventListenerTouchOneByOne::create();
		touchListener1->onTouchBegan = [this](Touch* touch, Event* event) -> bool//start lambda,[]内为捕获列表
		{
			auto bounds = event->getCurrentTarget()->getBoundingBox();

			if (bounds.containsPoint(touch->getLocation()))
			{
				if (iWaiting == 1){
					return true;
				}
				else if (iWaiting == 2)/*already open 2 cards,turn over,reset*/
				{
					firstCard->setScale(1);
					firstCard->setTexture("res/memory_game/memory_square.png");
					//firstCard->setDisplayFrame(SpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("memory_square.png"));//roll back 
					firstCard->cancel_rollback_timer();
					secondCard->setScale(1);
					secondCard->setTexture("res/memory_game/memory_square.png");
					//secondCard->setDisplayFrame(SpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("memory_square.png"));//roll back
					secondCard->cancel_rollback_timer();
					iFirstCard = -1;
					iSecondCard = -1;
					iWaiting = 0;
					return true;
				}

				auto target = static_cast<TouchSprite*>(event->getCurrentTarget());
				int i = target->getTag() - 1000;
				char file[100];
				if (i<1 || i>8){
					log("invalide target tag=%d", i);
					return true;
				}
				sprintf(file, "%s", sFile[i - 1]);

				bool bFound = false;
				log("enter here 1=%d,2=%d", iFirstCard, iSecondCard);
				if (iFirstCard == -1 && iSecondCard == -1)
				{
					iFirstCard = target->getZOrder() - 20;
				}
				else if (iFirstCard >= 0 && iSecondCard == -1)
				{
					iWaiting = 1; //waiting for 
					iSecondCard = target->getZOrder() - 20;
					if (iFirstCard == iSecondCard)
					{
						//The same card,
						bFound = false;
						iSecondCard = -1;
						iWaiting = 0;
						return 0;
					}
					else
					{
						firstCard = (TouchSprite*)spCard.at(iFirstCard);
						secondCard = (TouchSprite*)spCard.at(iSecondCard);
						log("tag1=%d,tag2=%d", firstCard->getTag(), secondCard->getTag());
						if (firstCard->getTag() == secondCard->getTag() && firstCard->getTag()>1000)
						{
							bFound = true;
							firstCard->setTag(999);
							secondCard->setTag(999);
							iFirstCard = -1;
							iSecondCard = -1;
							iWaiting = 0;
							CheckWin();
						}
						else
						{
							iFirstCard = -1;
							iSecondCard = -1;
							log("not found!");
							iWaiting = 2;//next touch will reset
							if (iTotalTime > 1)
							{
								iTotalTime --;
							}
							else
							{
								iTotalTime = 0;
							}
							this->showDeductPointEffect("lblTimer");
						}
					}
				}
				if (!bFound)
				{
					log("file=%s,should setup rollback timer,tag=%d", file, target->getTag());
					target->setDisplayFrame(SpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(file));
					if (!target)
					{
						return 1;
					}
					//target->setScale(0.95);//?
					target->setScaleX(0.9);
					target->setScaleY(0.97);

					if (iFirstCard >= 0 && iSecondCard == -1)//first card
					{
						firstCard = target;
						target->setup_rollback_timer(4);//scheduleOnce(schedule_selector(GameLayer::RollBackClickMe), 2.0f );
					}
					else
					{
						iFirstCard = -1;
						iSecondCard = -1;
						firstCard->cancel_rollback_timer();
						firstCard->setup_rollback_timer(2);//should be rollback with the first card simultaneously
						target->setup_rollback_timer(2);//should be rollback with the first card simultaneously
					}
				}
				else//bFound==true
				{
					log("found 1=%d,2=%d", iFirstCard, iSecondCard);
					//reset it
					firstCard->setDisplayFrame(SpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(file));
					//firstCard->setScale(0.95);
					firstCard->setScaleX(0.9);
					firstCard->setScaleY(0.97);
					secondCard->setDisplayFrame(SpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(file));
					//secondCard->setScale(0.95);
					secondCard->setScaleX(0.9);
					secondCard->setScaleY(0.97);
					log("found it tag=%d,tag2=%d", firstCard->getTag(), secondCard->getTag());

				}
				//delete[]file;
			}
			return true;
		};

		for (int col = 0; col < iCols; col++)
		{
			float x_position = 0.0;
			if (col <= iCols / 2)
			{
				x_position = Director::getInstance()->getVisibleSize().width / 2 - (iCols / 2 - col) * 190 + 80;
			}
			else
			{
				x_position = Director::getInstance()->getVisibleSize().width / 2 + (col - iCols / 2) * 190 + 80;
			}
			for (int row = 0; row < iRows; row++)
			{
				float y_position = 0.0;
				if (row <= iRows / 2)
				{
					y_position = Director::getInstance()->getVisibleSize().height / 2 + (iRows / 2 - row) * 190 - 80;
				}
				else
				{
					y_position = Director::getInstance()->getVisibleSize().height / 2 - (row - iRows / 2) * 190 - 80;
				}
				auto card1 = Sprite::create("res/memory_game/memory_square.png");

				/*
				char file[100];
				sprintf(file, "%s", sFile[0]);
				card1->setDisplayFrame(SpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(file));*/
				card1->setPosition(Vec2(x_position + 50, y_position));

				if (row == 0 && col == 0){
					Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(touchListener1, card1);
				}
				else{
					Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(touchListener1->clone(), card1);
				}
				int index = row + col*iRows;
				this->addChild(card1, 20 + index, 1001 + unique_array[index]);
				log("index=%d,z-index=%d,x=%f,y=%f", index, unique_array[index], x_position, y_position);
				spCard.pushBack(card1);

				auto card2 = Sprite::create("res/memory_game/kuang.png");
				card2->setPosition(Vec2(x_position + 50, y_position));
				this->addChild(card2, 100 + index, 1001 + unique_array[index]);
				log("index=%d,z-index=%d,x=%f,y=%f", index, unique_array[index], x_position, y_position);

			}
		}

		iFirstCard = -1;
		iSecondCard = -1;

		app->LogAccess("MemoryMatch");
		m_iCurrentGameLevel = app->getCurrentGameLevel();

		schedule(schedule_selector(GameLayer::updateLabels), 0.01f);
		schedule(schedule_selector(GameLayer::updateTimeLabel), 1.0f);

		delete[] array1;
		delete[] array2;
		delete[] unique_array;
		delete[] array4;
		//Director::sharedDirector()->getScheduler()->scheduleSelector(SEL_SCHEDULE(&GameLayer::loadingCallBack), this, .5f, false);


		//-----------------------------------add animation----------------------------------------------------------

		auto mastco = dynamic_cast<Sprite *> (_rootNode->getChildByName("Sprite_10"));
		//int mastcoZOrder=-1;
		if (mastco)
		{
			//mastcoZOrder = mastco->getZOrder();
			mastco->setVisible(false);
		}

		ArmatureDataManager::getInstance()->addArmatureFileInfo("res/animations/1.3/1.3.ExportJson");
		Armature *armature = Armature::create("1.3");
		armature->setAnchorPoint(Vec2(0.5, 0.5));
		armature->setRotation(270);
		armature -> setPosition(Vec2(150,400));
		armature->setVisible(true);
		armature->setTag(888);
		schedule(schedule_selector(GameLayer::PlayAnimation), 5.0f);
		_rootNode->addChild(armature);
		nAniFlag = 1;
		//-------------------------------------------------------------------------------------

		_bTlEnabled = true;

		return true;
	}
	else
	{
		return false;
	}
}
예제 #12
0
void GameLayer::touchButton(Object* obj, ::ui::Widget::TouchEventType eventType)
{
	auto button = dynamic_cast<::ui::Button*>(obj);
	int tag = button->getTag();
	if (eventType == ::ui::Widget::TouchEventType::ENDED)
	{
		AppDelegate *app = (AppDelegate*)Application::getInstance();
		app->PlayEffect(SOUND_BUTTON_CLICK);
		if (tag == 2001)
		{ //Tutorial
			auto scene = TutorialScene::create();
			if (scene != nullptr){
				TransitionScene *transition = TransitionFade::create(1, scene);
				Director::getInstance()->pushScene(transition);
			}
		}
		if (tag == 2002)
		{ //Home

			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(GameLayer::yesCallback, this));
			btnNo->addTouchEventListener(CC_CALLBACK_2(GameLayer::noCallback, this));

		}
		if (tag == 2003)
		{  //AI tips
			if (_bTlEnabled == false) return;
			_bTlEnabled = false;



			if (_nTlimit > 0)
			{
				if (_nTlcount > 0)
				{
					_nTlcount--;
					//AppDelegate *app = (AppDelegate*)Application::getInstance();
					app->setToolsNumberInfo(_nTlcount);
				}
				else
				{
					if (_lTtlScore >= 10)
					{
						showDeductPointEffect("txtScore");
						_lTtlScore = _lTtlScore - 10;
						//AppDelegate *app = (AppDelegate*)Application::getInstance();
						app->UpdateUserScore(0, 10);
					}
					else return;
				}
				_nTlimit--;
				if (_nTlimit == 0)
				{
					auto spTips = dynamic_cast<::ui::Button*>(_rootNode->getChildByName("btnTipsTools"));
					spTips->setColor(ccc3(84, 84, 84));//not disabled button, so use color instead
				}
				if (app->getBGMstatus() == BGMusic_flag::ON){
					app->PlayEffect(SOUND_TOOL_CLICK);
				}
				UseTips();
				this->scheduleOnce(schedule_selector(GameLayer::enableTools), 2.0f);
			}
			else return;
		}
	}
}
예제 #13
0
// on "init" you need to initialize your instance
bool CollageScene::init()
{
    
	
	string filePath = FileUtils::getInstance()->getWritablePath();
	TEMP_filePath = filePath;
	filePath += Cache_Path;
	if(access(filePath.c_str(),0)<0)
	{
		if(!CreateFolder(filePath.c_str()))
		{
			MessageBox("Can not create Cache Folder","Device ERROR");
			return false;
		}
	}
	//////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
	auto loadingUI = CSLoader::createNode("Collage/LoadingScene.csb");
	addChild(loadingUI);

	textPercentage = dynamic_cast<Text*>(loadingUI->getChildByName("Text_Percentage"));
	textPercentage->setText("0%");
	auto Image_bar = Sprite::create("Collage/bar.png");
	
	ct= ProgressTimer::create(Image_bar);
	ct->setAnchorPoint(Vec2::ZERO);
	ct->setPosition(Vec2(319,317));
	
	ct->setType(ProgressTimer::Type::BAR);
	ct->setMidpoint(Vec2(0,0));
	ct->setBarChangeRate(Vec2(1,0));
	ct->setPercentage(0);
	addChild(ct);

	std::thread t1(&CollageScene::LoadResources,this);
	t1.detach();

	Director::sharedDirector()->getScheduler()->scheduleSelector(SEL_SCHEDULE(&CollageScene::loadingCallBack), this, .5f, false);

	////////////////////////////////loading coloar pattern//////////
	sctColorList ColorPattern;
	
	ColorPattern.R=255;
	ColorPattern.G=255;
	ColorPattern.B=255;
	HttpConnection::v_color_list.push_back(ColorPattern);

	ColorPattern.R=255;
	ColorPattern.G=245;
	ColorPattern.B=114;
	HttpConnection::v_color_list.push_back(ColorPattern);

	ColorPattern.R=255;
	ColorPattern.G=206;
	ColorPattern.B=81;
	HttpConnection::v_color_list.push_back(ColorPattern);

	ColorPattern.R=247;
	ColorPattern.G=147;
	ColorPattern.B=78;
	HttpConnection::v_color_list.push_back(ColorPattern);

	ColorPattern.R=240;
	ColorPattern.G=83;
	ColorPattern.B=63;
	HttpConnection::v_color_list.push_back(ColorPattern);

	ColorPattern.R=226;
	ColorPattern.G=0;
	ColorPattern.B=137;
	HttpConnection::v_color_list.push_back(ColorPattern);

	ColorPattern.R=158;
	ColorPattern.G=61;
	ColorPattern.B=150;
	HttpConnection::v_color_list.push_back(ColorPattern);

	ColorPattern.R=182;
	ColorPattern.G=189;
	ColorPattern.B=224;
	HttpConnection::v_color_list.push_back(ColorPattern);

	ColorPattern.R=0;
	ColorPattern.G=181;
	ColorPattern.B=239;
	HttpConnection::v_color_list.push_back(ColorPattern);

	ColorPattern.R=0;
	ColorPattern.G=108;
	ColorPattern.B=163;
	HttpConnection::v_color_list.push_back(ColorPattern);

	ColorPattern.R=210;
	ColorPattern.G=235;
	ColorPattern.B=226;
	HttpConnection::v_color_list.push_back(ColorPattern);

	ColorPattern.R=109;
	ColorPattern.G=196;
	ColorPattern.B=188;
	HttpConnection::v_color_list.push_back(ColorPattern);

	ColorPattern.R=88;
	ColorPattern.G=185;
	ColorPattern.B=71;
	HttpConnection::v_color_list.push_back(ColorPattern);

	ColorPattern.R=0;
	ColorPattern.G=115;
	ColorPattern.B=102;
	HttpConnection::v_color_list.push_back(ColorPattern);

	ColorPattern.R=224;
	ColorPattern.G=193;
	ColorPattern.B=169;
	HttpConnection::v_color_list.push_back(ColorPattern);

	ColorPattern.R=190;
	ColorPattern.G=135;
	ColorPattern.B=105;
	HttpConnection::v_color_list.push_back(ColorPattern);

	ColorPattern.R=142;
	ColorPattern.G=83;
	ColorPattern.B=42;
	HttpConnection::v_color_list.push_back(ColorPattern);

	ColorPattern.R=223;
	ColorPattern.G=225;
	ColorPattern.B=223;
	HttpConnection::v_color_list.push_back(ColorPattern);

	ColorPattern.R=121;
	ColorPattern.G=125;
	ColorPattern.B=130;
	HttpConnection::v_color_list.push_back(ColorPattern);

	ColorPattern.R=52;
	ColorPattern.G=55;
	ColorPattern.B=65;
	HttpConnection::v_color_list.push_back(ColorPattern);

	ColorPattern.R=0;
	ColorPattern.G=0;
	ColorPattern.B=0;
	HttpConnection::v_color_list.push_back(ColorPattern);
	HttpConnection::numberOfLoadSprites++;

	AppDelegate *app = (AppDelegate*)Application::getInstance();
	if ( app->getBGMstatus() == BGMusic_flag::ON){
		app->StartBGMusic(BGM_COLLAGE);
	}

	return true;
}
예제 #14
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;
	}

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

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

	 //loginLayer=Layer::create();
	 addChild(_rootNode,1);

	 /*
	LayerColor *layer1 = LayerColor::create(Color4B(0, 0, 0, 180));
	TurntableSystem* price =new TurntableSystem(layer1);
	layer1->setTag(CHILD_TURNTABLE);
	addChild(layer1,99);*/
	

	/*
	cocostudio::ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("Animation0.png", "Animation0.plist", "Animation.ExportJson");
	cocostudio::Armature *armature = cocostudio::Armature::create("Animation");
	armature->getAnimation()->playByIndex(0);
	armature->setScale(0.5f);
	armature->setPosition(ccp(visibleSize.width * 0.5, visibleSize.height * 0.5));
	this->addChild(armature);
	
	*/

	 /*
	cocostudio::Armature* armature;
	cocostudio::ArmatureDataManager::getInstance()->addArmatureFileInfo("res/animations/coin/coin.ExportJson");
	armature = cocostudio::Armature::create("coin");
	if (armature){
		armature->setPosition(ccp(visiableSize.width * 0.8, visiableSize.height * 0.5));
		armature->getAnimation()->playByIndex(0);
		armature->setScale(0.25);
		this->addChild(armature);
	}
	*/
	


	//Get Promotion 
	// Setting HTTP Request Header
 //   if(m_iIsLoad==0){
 //       m_iIsLoad=1;
	//HttpRequest* request = new HttpRequest();
 //   request->setUrl(PromotionWebGetURL);
 //   request->setRequestType(HttpRequest::Type::GET);
 //   request->setResponseCallback(CC_CALLBACK_2(GameWin::onHttpRequestCompleted,this));
 //   request->setTag("GET test");
 //   cocos2d::network::HttpClient::getInstance()->send(request);
 //   request->release();
 //   }

	//ImageView* imgPromotion = dynamic_cast<ImageView*>(_rootNode->getChildByName("ivPromotionImg")); 
	//	 auto card1 = Sprite::create("match_game_img_1_b.jpg");
	// //card1->setPosition(Vec2(0, imgPromotion->getPositionY()+ imgPromotion->getContentSize().height/2));
	//	log("1=%f,%f,%f,%f",imgPromotion->getPositionX(),imgPromotion->getPositionY(),imgPromotion->getContentSize().width,imgPromotion->getContentSize().height);
	//	card1->setAnchorPoint(Vec2(0,0)); 
	//card1->setPosition(Vec2(0, 0));
	// //float zoom_x = visiableSize.width *0.5 / card1->getContentSize().width;
	//// float zoom_y = visiableSize.height * 0.5 / card1->getContentSize().height;
	// //card1->setScale(0.055f);
	// //card1->setScaleY(zoom_y);
	//card1->setScale(0.38f);
	//  imgPromotion->addChild(card1,2,1001);

	m_PrmtPrdct = app->getPromoteProduct();

	if(m_PrmtPrdct.m_iIsLoad == 0){
        
		m_PrmtPrdct.m_iIsLoad=1;
		HttpRequest* request = new HttpRequest();
		request->setUrl(PromotionWebGetURL);
		request->setRequestType(HttpRequest::Type::GET);
		request->setResponseCallback(CC_CALLBACK_2(GameWin::onHttpRequestCompleted,this));
		request->setTag("GET test");
		cocos2d::network::HttpClient::getInstance()->send(request);
		request->release();
    }

	if(_rootNode){
        auto img=_rootNode->getChildByName("ivPromotionImg");
        if(img){
            ImageView* imgPromotion = dynamic_cast<ImageView*>(_rootNode->getChildByName("ivPromotionImg"));
			auto card1 = Sprite::create(m_PrmtPrdct.m_strImage.c_str());
			card1->setAnchorPoint(Vec2(0,0)); 
			card1->setPosition(Vec2(0, 0));
			card1->setScale((imgPromotion->getBoundingBox().size.width / card1->getContentSize().width));
			imgPromotion->addChild(card1,2,1001);
        }
    }
    if(_rootNode && _rootNode->getChildByName("lblProductName")){
        Text* lblProductName=dynamic_cast<Text*>(_rootNode->getChildByName("lblProductName"));// (CCLabelTTF*)this->getChildByTag(2001);
        lblProductName->setString(m_PrmtPrdct.m_strProductName);
    }


	auto btnContine = dynamic_cast<Button*>(_rootNode->getChildByName("btnContine"));
	btnContine->setTag(1001);
	btnContine->addTouchEventListener(CC_CALLBACK_2(GameWin::touchButton, this));	

	auto btnQuit = dynamic_cast<Button*>(_rootNode->getChildByName("btnQuit"));
	btnQuit->setTag(1002);
	btnQuit->addTouchEventListener(CC_CALLBACK_2(GameWin::touchButton, this));	

	auto btnBuyNow = dynamic_cast<Button*>(_rootNode->getChildByName("btnBuyNow"));
	btnBuyNow->setTag(1003);
	btnBuyNow->addTouchEventListener(CC_CALLBACK_2(GameWin::touchButton, this));	

	auto btnShare = dynamic_cast<Button*>(_rootNode->getChildByName("btnShare"));
	btnShare->setTag(1004);
	btnShare->addTouchEventListener(CC_CALLBACK_2(GameWin::touchButton, this));	


	//Show Total User Score
	long l_coins = app->GetUserTotalScore();
	char p[20];
	sprintf(p, "%ld", l_coins);
	string sTotal = p;
	
	iReward = app->getReward();
	iStar = app->getStar();
	char p1[20];
	sprintf(p1, "%ld", iReward);
	string sReward = p1;
	app->setReward(0,0);

	auto lblReward = dynamic_cast<::ui::Text*>(_rootNode->getChildByName("lblReward"));
	if (lblReward)
	{
		lblReward->setString(sReward);
	}
	auto lblScore = dynamic_cast<::ui::Text*>(_rootNode->getChildByName("lblScore"));
	if (lblReward)
	{
		lblScore->setString(sTotal);
	}


	//_rootNode->getChildByName("Img_Box")->setVisible(false);
	auto imgStar = dynamic_cast<ImageView*>(_rootNode->getChildByName(WIN_STAR_FRAME));	
	if (imgStar != nullptr) {
		_rootNode->getChildByName(WIN_STAR_BOX)->setVisible(false);
		if (iStar == 3){
			imgStar->loadTexture(WIN_STAR_3);
		}
		else if (iStar == 2){
			imgStar->loadTexture(WIN_STAR_2);
		}
		else if (iStar == 1){
			imgStar->loadTexture(WIN_STAR_1);
		}
	}
	if (app->getBGMstatus() == BGMusic_flag::ON)
	{
		app->PlayEffect(SOUND_WIN);
	}


		// start ansyc method load the atlas.png
	//Director::getInstance()->getTextureCache()->addImageAsync("MatchBg.png", CC_CALLBACK_1(GameWin::loadingCallBack, this));
	
	/*auto card1 = Sprite::create("match_game_img_1_b.jpg");
	// card1->setPosition(Vec2(visiableSize.width / 2 +88 * generalscalefactor,   visiableSize.height/2 +50 *generalscalefactor));
	 //float zoom_x = visiableSize.width *0.5 / card1->getContentSize().width;
	// float zoom_y = visiableSize.height * 0.5 / card1->getContentSize().height;
	 card1->setScale(150/800);
	 //card1->setScaleY(zoom_y);
	 
	 Image* image = new Image();
	 image->s
	 Texture2D* texture = new Texture2D();
    
	Sprite* sprite = dynamic_cast<Sprite*>(_rootNode->getChildByName("spPromotionImg"));  //spPromotionImg
	sprite->initWithFile("match_game_img_1_b.jpg");

	  this->addChild(card1,1,1001);
	*/


	Sprite* imgBackground = Sprite::create(WIN_BACKGROUND);

	imgBackground->setAnchorPoint(Vec2(0, 0));
	imgBackground->setPosition(Vec2(0, 0));
	this->addChild(imgBackground, -1, 222); 


	syncFlow();//sync with server
	app->PlayEffect(SOUND_GAME_PASS);

    return true;
}