#include "GameBaseScene.h"
int GameBaseScene::tiledColsCount;
int GameBaseScene::tiledRowsCount;
bool** GameBaseScene::canPassGrid;
Vector<RicherPlayer*> GameBaseScene::players_vector;
Vector<Sprite*> GameBaseScene::pathMarkVector;
TMXLayer* GameBaseScene::landLayer;
TMXLayer* GameBaseScene::wayLayer;
TMXTiledMap* GameBaseScene::_map;
int GameBaseScene::blank_land_tiledID;
int GameBaseScene::strength_30_tiledID;
int GameBaseScene::strength_50_tiledID;
int GameBaseScene::strength_80_tiledID;
int GameBaseScene::randomEvent_tiledID;
int GameBaseScene::lottery_tiledID;
int GameBaseScene::stock_tiledID;
int GameBaseScene::player1_building_1_tiledID;
int GameBaseScene::player1_building_2_tiledID;
int GameBaseScene::player1_building_3_tiledID;
int GameBaseScene::player2_building_1_tiledID;
int GameBaseScene::player2_building_2_tiledID;
int GameBaseScene::player2_building_3_tiledID;
Scene* GameBaseScene::createScene()
{
auto scene = Scene::create();
auto layer = GameBaseScene::create();
scene->addChild(layer);
return scene;
}
bool GameBaseScene::init()
{
if ( !Layer::init() )
{
return false;
}
addMap();
initTiledGrid();
setWayPassToGrid();
addRightBanner();
drawTable(2);
addPathMark();
addPlayer();
addGoButton();
registerNotificationObserver();
addDice();
addDigiteRoundSprite();
refreshRoundDisplay();
initLandLayerFromMap();
initPropTiledID();
initPopDialog();
doSomeForParticle();
initRandomAskEvent();
return true;
}
void GameBaseScene::initRandomAskEvent()
{
randomAskEventMap.insert(TAX_REBATES_TAG,LanguageString::getInstance()->getLanguageString(TAX_REBATES));
randomAskEventMap.insert(PAY_TAXES_TAG,LanguageString::getInstance()->getLanguageString(PAY_TAXES));
randomAskEventMap.insert(LOSS_STRENGTH_TAG,LanguageString::getInstance()->getLanguageString(LOSS_STRENGTH));
randomAskEventMap.insert(PHYSICAL_RECOVERY_TAG,LanguageString::getInstance()->getLanguageString(PHYSICAL_RECOVERY));
randomAskEventMap.insert(INVESTMENT_DIVIDENDS_TAG,LanguageString::getInstance()->getLanguageString(INVESTMENT_DIVIDENDS));
randomAskEventMap.insert(INVESTMENT_LOSS_TAG,LanguageString::getInstance()->getLanguageString(INVESTMENT_LOSS));
}
void GameBaseScene::doSomeForParticle()
{
landFadeOut = FadeOut::create(0.1);
landFadeIn = FadeIn::create(0.1);
landFadeOut->retain();
landFadeIn->retain();
scaleby1ForBuyLand = ScaleBy::create(0.1, 1.5);
scaleby2ForBuyLand = ScaleBy::create(0.5, 0.7);
scaleby1ForBuyLand->retain();
scaleby2ForBuyLand->retain();
foot1Sprite = Sprite::create(PLAYER1_1_PARTICLE_PNG);
addChild(foot1Sprite);
foot1Sprite->setAnchorPoint(ccp(0,0));
foot2Sprite = Sprite::create(PLAYER2_1_PARTICLE_PNG);
addChild(foot2Sprite);
foot2Sprite->setAnchorPoint(ccp(0,0));
starFish1Sprite = Sprite::create(PLAYER1_2_PARTICLE_PNG);
addChild(starFish1Sprite);
starFish1Sprite->setAnchorPoint(ccp(0,0));
starFish2Sprite = Sprite::create(PLAYER2_2_PARTICLE_PNG);
addChild(starFish2Sprite);
starFish2Sprite->setAnchorPoint(ccp(0,0));
heart1Sprite = Sprite::create(PLAYER1_3_PARTICLE_PNG);
addChild(heart1Sprite);
heart1Sprite->setAnchorPoint(ccp(0,0));
heart2Sprite = Sprite::create(PLAYER2_3_PARTICLE_PNG);
addChild(heart2Sprite);
heart2Sprite->setAnchorPoint(ccp(0,0));
}
void GameBaseScene::initPopDialog()
{
popDialog = PopupLayer::create(DIALOG_BG);
popDialog->setContentSize(CCSizeMake(Dialog_Size_Width, Dialog_Size_Height));
popDialog->setTitle(LanguageString::getInstance()->getLanguageString(DIALOG_TITLE)->getCString());
popDialog->setContentText("", 20, 60, 250);
popDialog->setCallbackFunc(this, callfuncN_selector(GameBaseScene::buyLandCallback));
popDialog->addButton(BUTTON_BG1, BUTTON_BG3, LanguageString::getInstance()->getLanguageString(OK)->getCString(), Btn_OK_TAG);
popDialog->addButton(BUTTON_BG2, BUTTON_BG3, LanguageString::getInstance()->getLanguageString(CANCEL)->getCString(), Btn_Cancel_TAG);
this->addChild(popDialog);
popDialog->setVisible(false);
}
void GameBaseScene::initLandLayerFromMap()
{
landLayer = _map->layerNamed("land");
}
void GameBaseScene::addDigiteRoundSprite()
{
gameRoundCount=0;
auto frameCache = SpriteFrameCache::getInstance();
frameCache->addSpriteFramesWithFile("map/digital_round.plist");
digiteRoundVector.pushBack(frameCache->getSpriteFrameByName(DIGITAL_0));
digiteRoundVector.pushBack(frameCache->getSpriteFrameByName(DIGITAL_1));
digiteRoundVector.pushBack(frameCache->getSpriteFrameByName(DIGITAL_2));
digiteRoundVector.pushBack(frameCache->getSpriteFrameByName(DIGITAL_3));
digiteRoundVector.pushBack(frameCache->getSpriteFrameByName(DIGITAL_4));
digiteRoundVector.pushBack(frameCache->getSpriteFrameByName(DIGITAL_5));
digiteRoundVector.pushBack(frameCache->getSpriteFrameByName(DIGITAL_6));
digiteRoundVector.pushBack(frameCache->getSpriteFrameByName(DIGITAL_7));
digiteRoundVector.pushBack(frameCache->getSpriteFrameByName(DIGITAL_8));
digiteRoundVector.pushBack(frameCache->getSpriteFrameByName(DIGITAL_9));
}
void GameBaseScene::refreshRoundDisplay()
{
for(auto it = refreshRoundVector.begin();it != refreshRoundVector.end();it++)
{
((Sprite*) *it)->setVisible(false);
}
refreshRoundVector.clear();
int count = gameRoundCount;
Sprite* st;
if(count ==0 )
{
st = Sprite::createWithSpriteFrame(digiteRoundVector.at(0));
addChild(st);
refreshRoundVector.pushBack(st);
}
while(count!=0)
{
st = Sprite::createWithSpriteFrame(digiteRoundVector.at(count%10));
addChild(st);
refreshRoundVector.pushBack(st);
count = count/10;
}
refreshRoundVector.reverse();
for(int i = 0;i< refreshRoundVector.size();i++)
{
Sprite * sp = refreshRoundVector.at(i);
sp->setPosition(ccp((tableStartPosition_x+50)+(i*25),50));
sp->setVisible(true);
}
}
void GameBaseScene::addPathMark()
{
Sprite* mark1 = Sprite::create(PATH_MARK_1);
Sprite* mark2 = Sprite::create(PATH_MARK_2);
Sprite* mark3 = Sprite::create(PATH_MARK_3);
Sprite* mark4 = Sprite::create(PATH_MARK_4);
Sprite* mark5 = Sprite::create(PATH_MARK_5);
Sprite* mark6 = Sprite::create(PATH_MARK_6);
mark1->setAnchorPoint(ccp(0,0));
mark2->setAnchorPoint(ccp(0,0));
mark3->setAnchorPoint(ccp(0,0));
mark4->setAnchorPoint(ccp(0,0));
mark5->setAnchorPoint(ccp(0,0));
mark6->setAnchorPoint(ccp(0,0));
mark1->setVisible(false);
mark2->setVisible(false);
mark3->setVisible(false);
mark4->setVisible(false);
mark5->setVisible(false);
mark6->setVisible(false);
addChild(mark1);
addChild(mark2);
addChild(mark3);
addChild(mark4);
addChild(mark5);
addChild(mark6);
pathMarkVector.pushBack(mark1);
pathMarkVector.pushBack(mark2);
pathMarkVector.pushBack(mark3);
pathMarkVector.pushBack(mark4);
pathMarkVector.pushBack(mark5);
pathMarkVector.pushBack(mark6);
}
void GameBaseScene::drawPathColor(std::vector<int> rowVector,std::vector<int> colVector)
{
int stepsCount = rowVector.size()-1;
for(int i=1;i<rowVector.size();i++)
{
pathMarkVector.at(i-1)->setPosition(ccp(colVector[i]*32,rowVector[i]*32));
pathMarkVector.at(i-1)->setVisible(true);
}
}
void GameBaseScene::addDice()
{
diceFrameCache= SpriteFrameCache::getInstance();
diceFrameCache->addSpriteFramesWithFile("map/dice.plist","map/dice.png");
Vector<SpriteFrame*> diceVector ;
char name[20];
memset(name, 0, 20);
for (int i=1; i<=6; i++)
{
sprintf(name, "dice_%02d.png",i);
diceVector.pushBack(diceFrameCache->getSpriteFrameByName(name));
}
if(!AnimationCache::getInstance()->getAnimation("dice_animation"))
{
AnimationCache::getInstance()->addAnimation(Animation::createWithSpriteFrames(diceVector,0.1),"dice_animation");
}
dice_animate = Animate::create(AnimationCach