Cocos2d-x 3.2 Monopoly game project development-Part 1 skill improvement and game end judgment, cocos2d-x Project Development
This section focuses on the increase of skill escalation events and game end judgment. The game judgment is simply handled. If there is a role whose capital is less than 0, the game is deemed to be over.
If there are more than three characters, further processing is required, such as how to handle the houses of the failed party and how to deal with them when dealing with multiple roles.
1. Add random events for skill improvement
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 (values, LanguageString: getInstance ()-> getLanguageString (values);} void GameBaseScene: doRandomAskEvent (RicherPlayer * player) {int randomNumber = rand () % (randomAskEventMap. size () + 1; _ String * str = randomAskEventMap. at (randomNumber); switch (randomNumber ){................ // skill improvement 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 ;}} cococostoast: createToast (this, str-> getCString (), TOAST_SHOW_TIME, player-> getPosition ());}
2. Add the game ending Screen
Before the role starts to walk, add the game end judgment void RicherGameController: pickOnePlayerToGo () {for (auto it = GameBaseScene: players_vector.begin (); it! = GameBaseScene: players_vector.end (); it ++) {RicherPlayer * richerPlayer = dynamic_cast <RicherPlayer *> (* it); // determines whether the role's funds are less than 0, when the value is less than 0, the game end message is sent. (If there are more than three characters, you need to determine and process multiple roles.) if (richerPlayer-> getMoney () <= 0) {String * str = String :: createWithFormat ("% d-% f-% d", MSG_GAME_OVER_TAG, 0.0f, 0.0f, richerPlayer-> getTag (); icationicationcenter: getInstance () -> postNotification (MSG_GAME_OVER, str); return; // The returned result of the game. No further execution is performed }}...............} // process the game end message void GameBaseScene: receivedNotificationOMsg (Object * data ){.......... case MSG_GAME_OVER_TAG: {int playerTag = messageVec Tor. at (3)-> intValue (); // when it is the first character, the game shows a failure screen. Otherwise, the displayed victory switch (playerTag) {case player_victory 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 ;}}
The code in this section is released together with the next part "save game ".
To be continued ........