日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內(nèi)最全I(xiàn)T社區(qū)平臺 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當(dāng)前位置:首頁 > php開源 > 綜合技術(shù) > Cocos2d-x 3.2 大富翁游戲項目開發(fā)-第二十三部分 購買彩票

Cocos2d-x 3.2 大富翁游戲項目開發(fā)-第二十三部分 購買彩票

來源:程序員人生   發(fā)布時間:2015-02-02 08:19:34 閱讀次數(shù):2532次

當(dāng)角色途經(jīng)彩票的標(biāo)志或停留位置有彩票標(biāo)志時,彈出購買彩票的對話框,提示購買彩票,已買過的號碼,不顯示。當(dāng)機器對手途經(jīng)時則直接購買彩票。


1、

在RicherPlayer.h中增加std::vector<int> lottery_vector;用來存儲購買的彩票號碼
2、
RicherGameController 修改endGo方法,每走完1步就會進(jìn)入該方法,判斷是不是有彩票標(biāo)示圖標(biāo),有的話發(fā)送MSG_LOTTERY彩票消息,MOVEPASS標(biāo)示走完1步的標(biāo)志

void RicherGameController::endGo() { ................... Size titleSize = GameBaseScene::wayLayer->getLayerSize(); int passId = GameBaseScene::wayLayer->getTileGIDAt(Point(currentCol,titleSize.height-currentRow⑴)); if(passId == GameBaseScene::lottery_tiledID) { String * str = String::createWithFormat("%d-%f-%f-%d-%d",MSG_LOTTERY_TAG,1.0f,1.0f,_richerPlayer->getTag(),MOVEPASS); NotificationCenter::getInstance()->postNotification(MSG_LOTTERY,str); return; } .............. }

3、
角色行走終了后,判斷停留地點是不是有彩票標(biāo)志,有的話發(fā)送MSG_LOTTERY彩票消息,GOEND標(biāo)示行走終了的標(biāo)志

void RicherGameController::handlePropEvent() { ............... if(endId == GameBaseScene::lottery_tiledID) { String * str = String::createWithFormat("%d-%f-%f-%d-%d",MSG_LOTTERY_TAG,pointInMap.x,pointInMap.y,_richerPlayer->getTag(),GOEND); NotificationCenter::getInstance()->postNotification(MSG_LOTTERY,str); return; } ............... }

4、新建彩票號碼類LotteryCard ,該類里面的按鍵是菜單按鈕

void LotteryCard::cardInit(int numbers,int width,int height,float CardSpriteX,float CardSpriteY) { //設(shè)置初始化值 lotteryNumber = numbers; //背景色彩 layerColorBG = LayerColor::create(Color4B(100,100,100,255),width⑸,height⑸); layerColorBG->setPosition(Point(CardSpriteX,CardSpriteY)); if(lotteryNumber > 0) { //創(chuàng)建menuitem,設(shè)置其tag為彩票的號碼 ballMenuImage = MenuItemImage::create("images/lt_defalut_ball.png", "images/lt_blueball.png", this, menu_selector(LotteryCard::ballButtonCallback)); ballMenuImage->setTag(lotteryNumber); ballMenuImage->setPosition(Point(layerColorBG->getContentSize().width/2,layerColorBG->getContentSize().height/2)); // 添加文字說明并設(shè)置位置 labelLotteryNumber = LabelTTF::create(String::createWithFormat("%i",lotteryNumber)->getCString(),"HiraKakuProN-W6",25); labelLotteryNumber->setColor(Color3B(200,200,200)); labelLotteryNumber->setPosition(Point(layerColorBG->getContentSize().width/2,layerColorBG->getContentSize().height/2)); ballMenuImage->addChild(labelLotteryNumber); //創(chuàng)建menu,添加menuitem Menu* menu = Menu::create(); menu->setPosition(CCPointZero); layerColorBG->addChild(menu); menu->addChild(ballMenuImage); //該彩票sprite的tag也是彩票號碼 this->setTag(lotteryNumber); } this->addChild(layerColorBG); } //調(diào)用彩票菜單按鍵的回調(diào)函數(shù) void LotteryCard::ballButtonCallback(CCObject* pSender) { Node* node = dynamic_cast<Node*>(pSender); ballMenuImage->selected(); if (m_callback && m_callbackListener) { (m_callbackListener->*m_callback)(node); } } //設(shè)置菜單為不選中狀態(tài) void LotteryCard::setUnSelected() { ballMenuImage->unselected(); } //設(shè)置彩票菜單按鍵的回調(diào)函數(shù) void LotteryCard::setBallCallbackFunc(cocos2d::Object *target, SEL_CallFuncN callfun) { m_callbackListener = target; m_callback = callfun; } //返回彩票號碼 int LotteryCard::getLotteryNumber() { return lotteryNumber; } //設(shè)置彩票號碼 void LotteryCard::setLotteryNumber(int num) { lotteryNumber = num; if(lotteryNumber > 0) { labelLotteryNumber->setString(String::createWithFormat("%i",lotteryNumber)->getCString()); } }

5、修改PopupLayer類,添加彩票布局

在PopupLayer.h頭文件中添加對話框類型枚舉 enum POP_TYPE { NORMAL,//普通對話框 LOTTERY,//彩票對話框 STOCK, //留作后面的股票對話框 }; void setLotteryContext(Size size); //設(shè)置彩票號碼布局內(nèi)容 POP_TYPE pop_type; //當(dāng)前對話框類型 void setPopType(POP_TYPE type); //設(shè)置當(dāng)前對話框類型 Vector<LotteryCard*> lotteryVector; //所有彩票號碼容器 void refreshBallBackGround(Node *pNode); //點擊1個彩票號碼后,更新其他彩票背景為不選中 int lottery_selected; //選中的彩票號碼 std::vector<int> selected_number_vector; //已選擇的彩票號碼容器 void setHasSelectedLotteryNumber(std::vector<int> _vector); //設(shè)置已選擇的彩票號碼 看具體的實現(xiàn) bool PopupLayer::init() { ......... lottery_selected = 0;//初始化時,沒有選中的號碼 .......... } void PopupLayer::onEnter() { ............ switch(pop_type) { case LOTTERY: { //如果對話框是彩票類型,則添加彩票布局 setLotteryContext(contentSize); break; } case STOCK: { break; } default: { // 此處表示普通對話框,則只顯示文本內(nèi)容 if (getLabelContentText()) { LabelTTF* ltf = getLabelContentText(); ltf->setPosition(ccp(winSize.width / 2, winSize.height / 2)); ltf->setDimensions(CCSizeMake(contentSize.width - m_contentPadding * 2, contentSize.height - m_contentPaddingTop)); ltf->setHorizontalAlignment(kCCTextAlignmentLeft); ltf->setColor(ccc3(0,0,0)); this->addChild(ltf); } } } ............ } //設(shè)置彩票號碼布局內(nèi)容 void PopupLayer::setLotteryContext(Size size) { Size winSize = Director::getInstance()->getWinSize(); Size center =(winSize - size)/2; //彩票布局行列為 10 X 3 for(int row=0; row<10; row++) { for(int col=0; col<3; col++) { //創(chuàng)建彩票號碼 LotteryCard* card = LotteryCard::createCardSprite((row+1)+ col*10, 40,40, center.width+20+row*(size.width/11), (winSize.height/2+30)⑷0*col); //設(shè)置彩票的tag為彩票號碼 card->setTag((row+1)+ col*10); //注冊彩票點擊回調(diào)函數(shù)refreshBallBackGround() card->setBallCallbackFunc(this,callfuncN_selector(PopupLayer::refreshBallBackGround)); addChild(card); //號碼放到彩票容器中 lotteryVector.pushBack(card); //遍歷已選擇過的彩票容器,把已選過的置為不可見 for(int i=0;i<selected_number_vector.size();i++) { if(selected_number_vector.at(i) == (row+1)+ col*10) { card->setVisible(false); } } } } } //把選擇的號碼,放入已選擇過的彩票容器。參數(shù)_vector是表示已選擇過的,由角色調(diào)用時把角色自帶的lottery_vector傳來 void PopupLayer::setHasSelectedLotteryNumber(std::vector<int> _vector) { for(int i=0;i<_vector.size();i++) { selected_number_vector.push_back(_vector.at(i)); } } //更新號碼背景,并把選中的號碼做為tag傳給購買按鈕,由購買按鍵回傳給主場景 void PopupLayer::refreshBallBackGround(Node *pNode) { int tag2= pNode->getTag(); for(auto it=lotteryVector.begin();it!=lotteryVector.end();it++) { LotteryCard* node = (LotteryCard*)(*it); int tag1= node->getTag(); if(node->getTag() != pNode->getTag()) { node->setUnSelected(); } } lottery_selected = tag2; Vector<Node*> menuItemVector = getMenuButton()->getChildren(); for(int i=0;i< getMenuButton()->getChildrenCount();i++) { if(menuItemVector.at(i)->getTag() != 0) { menuItemVector.at(i)->setTag(tag2); break; } } }

6、回到游戲主場景,看看是怎樣顯示出彩票對話框的

/注冊彩票消息的視察者 void GameBaseScene::registerNotificationObserver() { ............. NotificationCenter::getInstance()->addObserver( this, callfuncO_selector(GameBaseScene::receivedNotificationOMsg), MSG_LOTTERY, NULL); } //彩票消息處理 void GameBaseScene::receivedNotificationOMsg(Object* data) { .............. case MSG_LOTTERY_TAG: { int playerTag = messageVector.at(3)->intValue(); moveTag = messageVector.at(4)->intValue(); switch(playerTag) { case PLAYER_1_TAG: { //如果是第1角色,創(chuàng)建對話框,設(shè)置類型為彩票類型 PopupLayer* popDialogLottery = PopupLayer::create(DIALOG_BG); popDialogLottery->setContentSize(CCSizeMake(Dialog_Size_Width, Dialog_Size_Height)); popDialogLottery->setTitle(LanguageString::getInstance()->getLanguageString(SELECT_LOTTERY_TITLE)->getCString()); popDialogLottery->setContentText("", 20, 60, 250); popDialogLottery->setPopType(LOTTERY); //添加回調(diào)函數(shù)lotteryButtonCallback ,當(dāng)點擊購買或取消將調(diào)用該方法 popDialogLottery->setCallbackFunc(this, callfuncN_selector(GameBaseScene::lotteryButtonCallback)); //把角色已買過的號碼傳給對話框,讓其不可見 popDialogLottery->setHasSelectedLotteryNumber(player1->lottery_vector); //添加2個按鍵,購買 取消 popDialogLottery->addButton(BUTTON_BG1, BUTTON_BG3, LanguageString::getInstance()->getLanguageString(BUY_OK)->getCString(), Btn_OK_TAG); popDialogLottery->addButton(BUTTON_BG2, BUTTON_BG3, LanguageString::getInstance()->getLanguageString(CANCEL)->getCString(), Btn_Cancel_TAG); this->addChild(popDialogLottery); break; } case PLAYER_2_TAG: { //如果是角色2,則隨機購買彩票,不彈出對話框 int random_lottery_number = rand()%(30) + 1; repeatForCheck: for(int i=0;i<player2->lottery_vector.size();i++) { if(player2->lottery_vector.at(i) == random_lottery_number) { random_lottery_number = rand()%(30) + 1; goto repeatForCheck; } } //把購買后的彩票放到角色采票容器中 player2->lottery_vector.push_back(random_lottery_number); //更新角色資金 refreshMoneyLabel(player2,-BUY_LOTTERY_MONEY); //如果是角色行走終了,停留位置有彩票標(biāo)志致使發(fā)送的彩票消息,則購買彩票終了后,需要發(fā)送處理角色上下左右相鄰地塊的消息 if(moveTag == GOEND) { CocosToast::createToast(this, String::createWithFormat("%s %d",LanguageString::getInstance()->getLanguageString(BUY_LOTTERY)->getCString(),BUY_LOTTERY_MONEY)->getCString(), TOAST_SHOW_TIME,player2->getPosition(),(SEL_CallFun)&GameBaseScene::sendMSGDealAroundLand2); } //如果是走完1步,就是途經(jīng)彩票標(biāo)示發(fā)送的彩票消息,則發(fā)送行走下1步的消息,繼續(xù)走下1步 else if(moveTag == MOVEPASS) { CocosToast::createToast(this, String::createWithFormat("%s %d",LanguageString::getInstance()->getLanguageString(BUY_LOTTERY)->getCString(),BUY_LOTTERY_MONEY)->getCString(), TOAST_SHOW_TIME,player2->getPosition(),(SEL_CallFun)&GameBaseScene::sendMSGMoveOneStep); } break; } } break; } } //發(fā)送走下1步的消息 void GameBaseScene::sendMSGMoveOneStep() { NotificationCenter::getInstance()->postNotification(MSG_MOVE_ONE_STEP,String::createWithFormat("%d",MSG_MOVE_ONE_STEP_TAG)); } //對話框購買或取消按鍵點擊后的回調(diào)函數(shù) void GameBaseScene::lotteryButtonCallback(Node *pNode) { //如果點擊的是購買按鍵 if(pNode->getTag() != ⑴ && pNode->getTag() != Btn_Cancel_TAG) { //更新角色1的彩票容器 player1->lottery_vector.push_back(pNode->getTag()); //更新資金 refreshMoneyLabel(player1,-BUY_LOTTERY_MONEY); //如果是角色行走終了,停留位置有彩票標(biāo)志致使發(fā)送的彩票消息,則購買彩票終了后,需要發(fā)送處理角色上下左右相鄰地塊的消息 if(moveTag == GOEND) { CocosToast::createToast(this, String::createWithFormat("%s %d",LanguageString::getInstance()->getLanguageString(BUY_LOTTERY)->getCString(),BUY_LOTTERY_MONEY)->getCString(), TOAST_SHOW_TIME,player1->getPosition(),(SEL_CallFun)&GameBaseScene::sendMSGDealAroundLand2); }else if(moveTag == MOVEPASS)//如果是走完1步,就是途經(jīng)彩票標(biāo)示發(fā)送的彩票消息,則發(fā)送行走下1步的消息,繼續(xù)走下1步 { CocosToast::createToast(this, String::createWithFormat("%s %d",LanguageString::getInstance()->getLanguageString(BUY_LOTTERY)->getCString(),BUY_LOTTERY_MONEY)->getCString(), TOAST_SHOW_TIME,player1->getPosition(),(SEL_CallFun)&GameBaseScene::sendMSGMoveOneStep); } pNode->getParent()->getParent()->removeFromParent(); } else //處理取消按鍵 { pNode->getParent()->getParent()->removeFromParent(); if(moveTag == GOEND) { sendMSGDealAroundLand2(); }else if(moveTag == MOVEPASS) { sendMSGMoveOneStep(); } } }

7、
在控制器中注冊走下1步的視察者

void RicherGameController::registerNotificationObserver() { ..... NotificationCenter::getInstance()->addObserver( this, callfuncO_selector(RicherGameController::receivedMsg), MSG_MOVE_ONE_STEP, NULL); } //收到走1不的消息后,調(diào)用moveOneStep ,繼續(xù)下1步的行走,至此購買彩票事件處理終了 void RicherGameController::receivedMsg(Object* data) { .............. if(retMsgType == MSG_MOVE_ONE_STEP_TAG) { moveOneStep(_richerPlayer); } }


點擊下載代碼


未完待續(xù)........................


生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對您的學(xué)習(xí)有所幫助,可以手機掃描二維碼進(jìn)行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關(guān)閉
程序員人生
主站蜘蛛池模板: 一区久久 | 久久精品一区二区三区不卡牛牛 | 麻豆成人av | 成人性生交大片免费网站 | 欧美日日夜夜 | 成人精品国产免费网站 | 日本动漫做毛片一区二区 | 精品视频在线播放 | 免费的黄色网址 | 欧美一级毛片免费网站 | 国产精品永久 | 国产精品视频一区二区三区 | av在线一| 淫男乱女笨蛋英子 | 久久aaa| 亚洲国产二区 | 亚洲视频久久 | 精品成人一区二区三区 | 黄色成人在线网站 | 污免费在线观看 | 精品久久久久一区二区国产 | 玖玖在线视频 | 国产成人精品久久久 | 成人h在线观看 | 久久国产精品成人免费浪潮 | 国产精品免费一区二区 | 一区二区三区精品在线 | 亚洲一区二区精品在线 | 91人人视频在线观看 | 欧美九九九 | 国产精品18 | 国产精品电影在线观看 | 国内精品久久久久久影视8 成人午夜影院 | 一级黄色大片 | 一级黄色片在线观看 | 99re在线视频免费观看 | 草久久久| 在线免费观看成人 | 成人免费视频观看视频 | av看片网| 日韩一区二区三区av |