Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ErLinErYi committed May 14, 2020
1 parent cc4bbdc commit 89c7592
Show file tree
Hide file tree
Showing 20 changed files with 162 additions and 86 deletions.
16 changes: 9 additions & 7 deletions PlantsVsZombies/Classes/Based/AppDelegate.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "AppDelegate.h"
#include "Scenes/LoadingScene/LoadingScene.h"
#include "Based/UserInformation.h"

#define USE_AUDIO_ENGINE 1
#define USE_SIMPLE_AUDIO_ENGINE 0
Expand Down Expand Up @@ -60,22 +61,23 @@ bool AppDelegate::applicationDidFinishLaunching()
auto director = Director::getInstance();

auto glview = director->getOpenGLView();

if(!glview) {

if(!glview)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
glview = GLViewImpl::createWithRect("PlantsVsZombies_1.1.8.2 (2020.05.09)", cocos2d::Rect(0, 0, designResolutionSize.width, designResolutionSize.height));
glview = GLViewImpl::createWithRect("PlantsVsZombies_1.1.9.3 (2020.05.12)", cocos2d::Rect(0, 0, designResolutionSize.width, designResolutionSize.height));
#else
glview = GLViewImpl::create("PlantsVsZombies_1.1.8.2 (2020.05.09)");
glview = GLViewImpl::create("PlantsVsZombies_1.1.9.3 (2020.05.12)");
#endif
director->setOpenGLView(glview);
}
// turn on display FPS
director->setDisplayStats(true);

// set FPS. the default value is 1.0/60 if you don't call this
director->setAnimationInterval(1.0f / 60);
director->setAnimationInterval(1.0f / UserInformation::getScreenDisplayFrequency());
// Set the design resolution
glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::EXACT_FIT);

Expand Down
26 changes: 22 additions & 4 deletions PlantsVsZombies/Classes/Based/GameType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ GameType::~GameType()
void GameType::createGameType()
{
auto _levelData = _openlevelData->readLevelData(_openlevelData->getLevelNumber());
for (unsigned int i = 0; i < _levelData->getGameType().size(); i++)
for (unsigned int i = 0; i < _levelData->getGameType().size(); ++i)
{
switch (static_cast<GameTypes>(_levelData->getGameType().at(i)))
{
Expand Down Expand Up @@ -138,6 +138,21 @@ void GameType::updateRequirementNumbers(const std::string name)
}
}

void GameType::updateRequirementNumbers()
{
/* 如果有植物数量要求 */
if (_plantsRequriement->isHavePlantsRequriement)
{
updateNumbers(2);
}

/* 如果有阳光数量要求 */
if (_sunNumberRequriement->isHaveSunNumberRequriement)
{
updateNumbers(1);
}
}

void GameType::showNumbers(const int& ID)
{
switch(ID)
Expand Down Expand Up @@ -180,9 +195,11 @@ void GameType::updateNumbers(const int& ID)
{
case 1:
{
_sunNumberRequriement->allSunNumbersText->setString(to_string(_sunNumberRequriement->atLeastSunNumbers) + "/" + to_string(_sunNumberRequriement->allSunNumbers));
_sunNumberRequriement->allSunNumbersText->setString(
to_string(_sunNumberRequriement->atLeastSunNumbers) + "/" + to_string(_sunNumberRequriement->allSunNumbers));

if (!_sunNumberRequriement->isUpdateImage && _sunNumberRequriement->allSunNumbers >= _openlevelData->readLevelData(_openlevelData->getLevelNumber())->getAtLeastSunNumbers())
if (!_sunNumberRequriement->isUpdateImage && _sunNumberRequriement->allSunNumbers >=
_openlevelData->readLevelData(_openlevelData->getLevelNumber())->getAtLeastSunNumbers())
{
auto sprite = static_cast<Sprite*>(_node->getChildByName("LackSun"));
sprite->setSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("MoreSun.png"));
Expand All @@ -193,7 +210,8 @@ void GameType::updateNumbers(const int& ID)
break;
case 2:
{
_plantsRequriement->palntsNumbersText->setString(to_string(_plantsRequriement->userPlantsNumbers) + " / " + to_string(_plantsRequriement->surPlusPlantsNumbers));
_plantsRequriement->palntsNumbersText->setString(
to_string(_plantsRequriement->userPlantsNumbers) + " / " + to_string(_plantsRequriement->surPlusPlantsNumbers));

if (!_plantsRequriement->isUpdateImage && _plantsRequriement->surPlusPlantsNumbers <= 0)
{
Expand Down
1 change: 1 addition & 0 deletions PlantsVsZombies/Classes/Based/GameType.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class GameType
public:
void createGameType(); /* 创建游戏类型 */
void updateRequirementNumbers(const std::string name); /* 更新数量 */
void updateRequirementNumbers();
void waringPlantsNull(); /* 警告植物使用完 */
SunNumberRequriement* getSunNumberRequriement() const;
PlantsRequriement* getPlantsRequriement() const;
Expand Down
121 changes: 89 additions & 32 deletions PlantsVsZombies/Classes/Based/UserData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "Scenes/GameScene/GSControlLayer.h"
#include "Scenes/GameScene/GSZombiesAppearControl.h"
#include "Scenes/GameScene/GSInformationLayer.h"
#include "Scenes/GameScene/GSBackgroundLayer.h"
#include "Scenes/SelectPlantsScene/SelectPlantsScene.h"
#include "Plants/Plants.h"
#include "Plants/Plants-Files.h"
Expand Down Expand Up @@ -210,6 +211,9 @@ void UserData::caveUserData(char* key, double value)
case openUserDataReturnType::FileNotExist:
(*_userDataDocument)["UserData"].AddMember(rapidjson::StringRef(key), value, _userDataDocument->GetAllocator());
break;
case openUserDataReturnType::FileExistError:
remove(getUserDataFileName().c_str());
break;
}
flushUserData();
}
Expand All @@ -227,6 +231,9 @@ void UserData::caveUserData(char* key, bool value)
case openUserDataReturnType::FileNotExist:
(*_userDataDocument)["UserData"].AddMember(rapidjson::StringRef(key), value, _userDataDocument->GetAllocator());
break;
case openUserDataReturnType::FileExistError:
remove(getUserDataFileName().c_str());
break;
}
flushUserData();
}
Expand All @@ -244,6 +251,9 @@ void UserData::caveUserData(char* key, char* value)
case openUserDataReturnType::FileNotExist:
(*_userDataDocument)["UserData"].AddMember(rapidjson::StringRef(key), rapidjson::StringRef(value), _userDataDocument->GetAllocator());
break;
case openUserDataReturnType::FileExistError:
remove(getUserDataFileName().c_str());
break;
}
flushUserData();
}
Expand All @@ -261,6 +271,9 @@ void UserData::caveUserData(char* key, int value)
case openUserDataReturnType::FileNotExist:
(*_userDataDocument)["UserData"].AddMember(rapidjson::StringRef(key), value, _userDataDocument->GetAllocator());
break;
case openUserDataReturnType::FileExistError:
remove(getUserDataFileName().c_str());
break;
}
flushUserData();
}
Expand All @@ -273,6 +286,9 @@ int UserData::openIntUserData(char* key)
if (isHaveMember(key))
return (*_userDataDocument)["UserData"][key].GetInt();
break;
case openUserDataReturnType::FileExistError:
remove(getUserDataFileName().c_str());
break;
default: break;
}
return 0;
Expand All @@ -286,6 +302,9 @@ double UserData::openDoubleUserData(char* key)
if (isHaveMember(key))
return (*_userDataDocument)["UserData"][key].GetDouble();
break;
case openUserDataReturnType::FileExistError:
remove(getUserDataFileName().c_str());
break;
default: break;
}
return 0.0;
Expand All @@ -299,6 +318,9 @@ bool UserData::openBoolUserData(char* key)
if (isHaveMember(key))
return (*_userDataDocument)["UserData"][key].GetBool();
break;
case openUserDataReturnType::FileExistError:
remove(getUserDataFileName().c_str());
break;
default: break;
}
return false;
Expand All @@ -312,6 +334,9 @@ const char* UserData::openStringUserData(char* key)
if (isHaveMember(key))
return (*_userDataDocument)["UserData"][key].GetString();
break;
case openUserDataReturnType::FileExistError:
remove(getUserDataFileName().c_str());
break;
default: break;
}
return nullptr;
Expand Down Expand Up @@ -354,6 +379,7 @@ void UserData::caveLevelData(char* key)
(*_levelDataDocument).RemoveMember(key);
break;
case openUserDataReturnType::FileExistError:
remove(getLevelDataFileName().c_str());
return;
break;
}
Expand Down Expand Up @@ -410,41 +436,46 @@ void UserData::caveLevelPlantsData(char* key)
rapidjson::Value _object(rapidjson::kObjectType);
rapidjson::Document::AllocatorType& allocator = _levelDataDocument->GetAllocator();
(*_levelDataDocument)[key].AddMember("Plants", _object, allocator);
(*_levelDataDocument)[key]["Plants"].AddMember("PlantsNumber", PlantsGroup.size(), allocator);


for (auto plant : PlantsGroup)
{
rapidjson::Value object(rapidjson::kObjectType);

object.AddMember("PlantsTag", plant.second->getPlantTag(), allocator);
object.AddMember("PlantsHealthPoint", plant.second->getPlantHealthPoint(), allocator);
object.AddMember("PlantsPositionX", plant.second->getPlantAnimation()->getPositionX(), allocator);
object.AddMember("PlantsPositionY", plant.second->getPlantAnimation()->getPositionY(), allocator);
object.AddMember("PlantsRow", plant.second->getPlantRow(), allocator);
object.AddMember("PlantsColumn", plant.second->getPlantColumn(), allocator);
object.AddMember("PlantsLocalZOrder", plant.second->getPlantAnimation()->getLocalZOrder(), allocator);
object.AddMember("PlantsType",static_cast<int>(plant.second->getPlantType()), allocator);
object.AddMember("PlantVisible", plant.second->getPlantAnimation()->isVisible(), allocator);

switch (plant.second->getPlantType())
auto visible = plant.second->getPlantAnimation()->isVisible();
if (visible)
{
case PlantsType::SunFlower:
object.AddMember("SunShowTime.X", dynamic_cast<SunFlower*>(plant.second)->getSunShowTime().x, allocator);
object.AddMember("SunShowTime.Y", dynamic_cast<SunFlower*>(plant.second)->getSunShowTime().y, allocator);
break;
case PlantsType::PotatoMine:
object.AddMember("BreakGround", dynamic_cast<PotatoMine*>(plant.second)->getBreakGround(), allocator);
break;
default:
break;
object.AddMember("PlantsTag", plant.second->getPlantTag(), allocator);
object.AddMember("PlantsHealthPoint", plant.second->getPlantHealthPoint(), allocator);
object.AddMember("PlantsPositionX", plant.second->getPlantAnimation()->getPositionX(), allocator);
object.AddMember("PlantsPositionY", plant.second->getPlantAnimation()->getPositionY(), allocator);
object.AddMember("PlantsRow", plant.second->getPlantRow(), allocator);
object.AddMember("PlantsColumn", plant.second->getPlantColumn(), allocator);
object.AddMember("PlantsLocalZOrder", plant.second->getPlantAnimation()->getLocalZOrder(), allocator);
object.AddMember("PlantsType", static_cast<int>(plant.second->getPlantType()), allocator);
object.AddMember("PlantVisible", visible, allocator);

switch (plant.second->getPlantType())
{
case PlantsType::SunFlower:
object.AddMember("SunShowTime.X", dynamic_cast<SunFlower*>(plant.second)->getSunShowTime().x, allocator);
object.AddMember("SunShowTime.Y", dynamic_cast<SunFlower*>(plant.second)->getSunShowTime().y, allocator);
break;
case PlantsType::PotatoMine:
object.AddMember("BreakGround", dynamic_cast<PotatoMine*>(plant.second)->getBreakGround(), allocator);
break;
default:
break;
}

auto number = to_string(++plantsNumber);
char* str = new char[number.size() + 1];
strcpy(str, number.c_str());
str[number.size()] = '\0';
(*_levelDataDocument)[key]["Plants"].AddMember(rapidjson::StringRef(str), object, _levelDataDocument->GetAllocator());
}

auto number = to_string(++plantsNumber);
char* str = new char[number.size() + 1];
strcpy(str, number.c_str());
str[number.size()] = '\0';
(*_levelDataDocument)[key]["Plants"].AddMember(rapidjson::StringRef(str),object, _levelDataDocument->GetAllocator());
}

(*_levelDataDocument)[key]["Plants"].AddMember("PlantsNumber", plantsNumber, allocator);
}

void UserData::caveLevelZombiesData(char* key)
Expand Down Expand Up @@ -632,6 +663,8 @@ void UserData::caveLevelOtherData(char* key)
rapidjson::Value object(rapidjson::kObjectType);

object.AddMember("SunNumbers", _global->userInformation->getSunNumbers(), allocator);
object.AddMember("SurSunNumbers", backgroundLayerInformation->gameType->getSunNumberRequriement()->allSunNumbers, allocator);
object.AddMember("SurPlusPlantsNumbers", backgroundLayerInformation->gameType->getPlantsRequriement()->surPlusPlantsNumbers, allocator);
object.AddMember("ZombiesAppearFrequency", controlLayerInformation->_zombiesAppearControl->getZombiesAppearFrequency(), allocator);
object.AddMember("ZombiesAppearTime", controlLayerInformation->_zombiesAppearControl->getTime(), allocator);
object.AddMember("IsBegin", controlLayerInformation->_zombiesAppearControl->getIsBegin(), allocator);
Expand Down Expand Up @@ -661,6 +694,9 @@ bool UserData::readLevelData()
case openUserDataReturnType::FileExistCorrect:
return true;
break;
case openUserDataReturnType::FileExistError:
remove(getLevelDataFileName().c_str());
return false;
default:
return false;
break;
Expand Down Expand Up @@ -693,6 +729,9 @@ bool UserData::isHaveLevelData(char* key)
if ((*_levelDataDocument).HasMember(key))
return true;
break;
case openUserDataReturnType::FileExistError:
remove(getLevelDataFileName().c_str());
break;
default: break;
}
return false;
Expand All @@ -710,6 +749,9 @@ void UserData::openSurvivalData(char* key)
openLevelCarData(key);
openLevelBulletData(key);
break;
case openUserDataReturnType::FileExistError:
remove(getSurvivalDataFileName().c_str());
break;
}
}

Expand All @@ -721,6 +763,8 @@ bool UserData::isHaveSurvivalData(char* key)
if ((*_levelDataDocument).HasMember(key))
return true;
break;
case openUserDataReturnType::FileExistError:
remove(getSurvivalDataFileName().c_str());
default: break;
}
return false;
Expand Down Expand Up @@ -983,6 +1027,12 @@ void UserData::openLevelOtherData(char* key)
_global->userInformation->setSunNumbers(
(*_levelDataDocument)[key]["OtherData"]["SunNumbers"].GetInt());
informationLayerInformation->updateSunNumbers();

backgroundLayerInformation->gameType->getSunNumberRequriement()->allSunNumbers =
(*_levelDataDocument)[key]["OtherData"]["SurSunNumbers"].GetInt();
backgroundLayerInformation->gameType->getPlantsRequriement()->surPlusPlantsNumbers =
(*_levelDataDocument)[key]["OtherData"]["SurPlusPlantsNumbers"].GetInt();
backgroundLayerInformation->gameType->updateRequirementNumbers();
}

void UserData::openSurvivalOtherData(char* key)
Expand Down Expand Up @@ -1039,11 +1089,15 @@ string UserData::encryption(string& str)

string UserData::decryption(string& str)
{
unsigned char* decryptString, * decryptString1;
unsigned char* decryptString = nullptr, * decryptString1 = nullptr;

auto ret = base64Decode((unsigned char*)str.c_str(), (unsigned int)str.length(), &decryptString);

if (ret > 0) decryptString[ret] = '\0';
else return "";

decryptString[base64Decode((unsigned char*)str.c_str(), (unsigned int)str.length(), &decryptString)] = '\0';

string sss(reinterpret_cast<char*>(decryptString));

for (auto& s : sss)
{
if (s >= 'a' && s <= 'z')s = ((s - 'a') + 24) % 26 + 'a';
Expand All @@ -1053,7 +1107,10 @@ string UserData::decryption(string& str)
}
reverse(sss.begin(), sss.end());

decryptString1[base64Decode((unsigned char*)sss.c_str(), (unsigned int)sss.length(), &decryptString1)] = '\0';
ret = base64Decode((unsigned char*)sss.c_str(), (unsigned int)sss.length(), &decryptString1);

if (ret > 0) decryptString1[ret] = '\0';
else { CC_SAFE_FREE(decryptString); return ""; }

string s(reinterpret_cast<char*>(decryptString1));

Expand Down
7 changes: 7 additions & 0 deletions PlantsVsZombies/Classes/Based/UserInformation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,13 @@ void UserInformation::setUpdateRequired(const bool updateRequired)
_updateRequired = updateRequired;
}

DWORD UserInformation::getScreenDisplayFrequency()
{
DEVMODE dm;
::EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm);
return dm.dmDisplayFrequency;
}

void UserInformation::setGameDifficulty(const int difficulty)
{
_gameDifficulty = difficulty;
Expand Down
1 change: 1 addition & 0 deletions PlantsVsZombies/Classes/Based/UserInformation.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class UserInformation
static string getNewEditionName(bool dot = false);
static bool getUpdateRequired();
static void setUpdateRequired(const bool update);
static DWORD getScreenDisplayFrequency();

CC_CONSTRUCTOR_ACCESS:
UserInformation();
Expand Down
1 change: 1 addition & 0 deletions PlantsVsZombies/Classes/Plants/Plants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ void Plants::zombieRecoveryMove(Zombies* zombie)
zombie->getZombieIsEat() && zombie->getZombieIsStop()) /* 僵尸正在吃植物 && 僵尸正在停止移动 */
{
setPlantVisible(false);
_plantAnimation->stopAllActions();
Bullet::playSoundEffect("gulp");
zombie->setZombieIsEat(false);
if (!zombie->getZombieIsPlayDieAnimation()) /* 僵尸没有播放死亡动画 */
Expand Down
Loading

0 comments on commit 89c7592

Please sign in to comment.