如果人物在3个以上,则需要做进一步处理,比如失败方的房屋如何处理,这些在处理到多个角色的时候再做处理。
oid GameBaseScene::initRandomAskEvent() { ................. randomAskEventMap.insert(STORM_UP_TAG,LanguageString::getInstance()->getLanguageString(STORM_SKILL_UP)); randomAskEventMap.insert(STEP_UP_TAG,LanguageString::getInstance()->getLanguageString(STEP_SKILL_UP)); randomAskEventMap.insert(TRANSFER_UP_TAG,LanguageString::getInstance()->getLanguageString(TRANSFER_SKILL_UP)); } void GameBaseScene::doRandomAskEvent(RicherPlayer* player) { int randomNumber = rand()%(randomAskEventMap.size()) + 1; __String * str = randomAskEventMap.at(randomNumber); switch(randomNumber) { ................ //技能得到提升 case STORM_UP_TAG: { player->skill_vector.at(0) ++; break; } case STEP_UP_TAG: { player->skill_vector.at(1) ++; break; } case TRANSFER_UP_TAG: { player->skill_vector.at(2) ++; break; } } CocosToast::createToast(this,str->getCString(),TOAST_SHOW_TIME,player->getPosition()); }
2、添加游戏结束画面
在角色开始行走之前增加游戏结束判断 void RicherGameController::pickOnePlayerToGo() { for(auto it=GameBaseScene::players_vector.begin();it!=GameBaseScene::players_vector.end();it++) { RicherPlayer* richerPlayer = dynamic_cast<RicherPlayer*>(*it); //判断角色资金是否小于0,当小于0时发送游戏结束消息。(如果人物在3个以上,需要做多个角色判断处理) if(richerPlayer->getMoney() <= 0) { String * str = String::createWithFormat("%d-%f-%f-%d",MSG_GAME_OVER_TAG,0.0f,richerPlayer->getTag()); NotificationCenter::getInstance()->postNotification(MSG_GAME_OVER,str); return;//游戏返回,不再向下执行 } } ............... } //处理游戏结束消息 void GameBaseScene::receivedNotificationOMsg(Object* data) { .......... case MSG_GAME_OVER_TAG: { int playerTag = messageVector.at(3)->intValue(); //当是第一人物时,游戏显示失败画面。否则显示胜利 switch(playerTag) { case PLAYER_1_TAG: { Sprite* gameOver = Sprite::create("images/lose.png"); gameOver->setPosition(winSize/2); addChild(gameOver); break; } case PLAYER_2_TAG: { playParticle(winSize/2,"images/win_particle.plist"); Sprite* gameOver = Sprite::create("images/win.png"); gameOver->setPosition(winSize/2); addChild(gameOver); break; } } break; } }
本节代码同下一部分《游戏保存》一并发布
未完待续........
原文链接:https://www.f2er.com/cocos2dx/344257.html