C++#include <bits/stdc++.h>
#include <windows.h>
#include <conio.h>
#define basicpetal(a,b) *pow(a,b)
using namespace std;
#include <vector>
#include <fstream>
#include <sstream>
#ifdef _WIN32
#include <windows.h>
#include <shlobj.h>
#else
#include <unistd.h>
#include <sys/stat.h>
#include <pwd.h>
#endif
unsigned char key;
mt19937 rnd(time(0));
void slowPrint(const string& str, int delay=50){
static HANDLE hConsole=GetStdHandle(STD_OUTPUT_HANDLE);
DWORD bytesWritten;
for(char c:str){
WriteConsole(hConsole,&c,1,&bytesWritten,NULL);
Sleep(rnd()%5);
}
}
void updateStats();
void init();
struct Player{
string name;
int health;
int maxhealth;
int bodydamage;
int petaldamage;
int healing;
int level;
int XP;
vector<pair<string,string> >petals;
vector<pair<string,string> >bagpack;
void clearBuffs(){
vector<pair<string,string>>().swap(petals);
vector<pair<string,string>>().swap(bagpack);
}
}p1;
class SaveSystem {
private:
static const unsigned char key = 0x55;
const std::string base64_chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/";
std::string base64_encode(const unsigned char* bytes, size_t len) {
std::string ret;
int i = 0;
int j = 0;
unsigned char char_array_3[3];
unsigned char char_array_4[4];
for (size_t idx = 0; idx < len; idx++) {
char_array_3[i++] = bytes[idx];
if (i == 3) {
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
char_array_4[3] = char_array_3[2] & 0x3f;
for(i = 0; i < 4; i++)
ret += base64_chars[char_array_4[i]];
i = 0;
}
}
if (i) {
for(j = i; j < 3; j++)
char_array_3[j] = 0;
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
for (j = 0; j < i + 1; j++)
ret += base64_chars[char_array_4[j]];
while(i++ < 3)
ret += '=';
}
return ret;
}
std::string base64_decode(const std::string& encoded_string) {
size_t in_len = encoded_string.size();
int i = 0, j = 0, in_ = 0;
unsigned char char_array_4[4], char_array_3[3];
std::string ret;
while (in_len-- && encoded_string[in_] != '=') {
unsigned char c = encoded_string[in_++];
// 跳过非Base64字符
if (c == '\n' || c == '\r' || c == '\t' || c == ' ') {
continue;
}
size_t pos = base64_chars.find(c);
if (pos == std::string::npos) {
continue; // 跳过无效字符
}
char_array_4[i++] = c;
if (i == 4) {
for (i = 0; i <4; i++)
char_array_4[i] = base64_chars.find(char_array_4[i]);
char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
for (i = 0; i < 3; i++)
ret += char_array_3[i];
i = 0;
}
}
// 处理剩余字符
if (i) {
for (j = i; j <4; j++)
char_array_4[j] = 0;
for (j = 0; j < i; j++)
char_array_4[j] = base64_chars.find(char_array_4[j]);
char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
for (j = 0; j < i - 1; j++)
ret += char_array_3[j];
}
return ret;
}
public:
std::string getSavePath() {
string path;
#ifdef _WIN32
CHAR documents[MAX_PATH];
if(SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_PERSONAL|CSIDL_FLAG_CREATE,
NULL, 0, documents))) {
path = string(documents) + "\\FlowerGame\\";
CreateDirectoryA(path.c_str(), NULL);
}
#else
// Linux/macOS implementation would go here
path = getenv("HOME");
path += "/FlowerGame/";
mkdir(path.c_str(), 0755);
#endif
return path.empty() ? "save.dat" : path + "save.dat";
}
std::string safeEncrypt(std::string& data) {
// 使用XOR加密而不是反转
for(char& c : data) {
c ^= key;
}
return base64_encode(
reinterpret_cast<const unsigned char*>(data.c_str()),
data.size()
);
}
std::string safeDecrypt(const std::string& encrypted) {
std::string decoded = base64_decode(encrypted);
for(char& c : decoded) {
c ^= key;
}
return decoded;
}
bool save(const Player& p) {
std::stringstream ss;
ss << "FLOWER_SAVE_v1\n";
ss << "name:" << p.name << "\n";
ss << "stats:"
<< p.health << "," << p.maxhealth << ","
<< p.bodydamage << "," << p.petaldamage << ","
<< p.healing << "," << p.level << "," << p.XP << "\n";
ss << "petals:";
for(size_t i = 0; i < p.petals.size(); ++i) {
ss << p.petals[i].first << ":" << p.petals[i].second;
if(i != p.petals.size() - 1) ss << ";";
}
ss << "\n";
ss << "bagpack:";
for(size_t i = 0; i < p.bagpack.size(); ++i) {
ss << p.bagpack[i].first << ":" << p.bagpack[i].second;
if(i != p.bagpack.size() - 1) ss << ";";
}
std::string data = ss.str();
std::string encrypted = safeEncrypt(data);
std::ofstream fout(getSavePath());
if(!fout) return false;
fout << encrypted;
return true;
}
bool load(Player& p) {
std::ifstream fin(getSavePath());
if(!fin) {
slowPrint("\n错误:找不到存档文件,将创建新存档");
return false;
}
// 读取加密数据
std::string encrypted;
fin.seekg(0, std::ios::end);
encrypted.reserve(fin.tellg());
fin.seekg(0, std::ios::beg);
encrypted.assign((std::istreambuf_iterator<char>(fin)),
std::istreambuf_iterator<char>());
fin.close();
if(encrypted.empty()) {
slowPrint("\n错误:存档文件为空");
return false;
}
// 解密数据
std::string data = safeDecrypt(encrypted);
if(data.empty() || data.find("FLOWER_SAVE_v1") != 0) {
slowPrint("\n错误:存档损坏或版本不匹配");
return false;
}
// 解析数据
std::istringstream ss(data);
std::string line;
// 跳过文件头
std::getline(ss, line);
// 解析名称
std::getline(ss, line);
if(line.substr(0, 5) != "name:") {
slowPrint("\n错误:名称解析失败");
return false;
}
p.name = line.substr(5);
// 解析属性
std::getline(ss, line);
if(line.substr(0, 6) != "stats:") {
slowPrint("\n错误:属性解析失败");
return false;
}
std::string stats_str = line.substr(6);
std::replace(stats_str.begin(), stats_str.end(), ',', ' ');
std::istringstream stats_stream(stats_str);
if(!(stats_stream >> p.health >> p.maxhealth >> p.bodydamage
>> p.petaldamage >> p.healing >> p.level >> p.XP)) {
slowPrint("\n错误:属性数据不完整");
return false;
}
// 解析花瓣
p.petals.clear();
std::getline(ss, line);
if(line.substr(0, 7) != "petals:") {
slowPrint("\n错误:花瓣数据解析失败");
return false;
}
std::string petals_str = line.substr(7);
if(!petals_str.empty()) {
std::istringstream petals_stream(petals_str);
std::string petal_pair;
while(std::getline(petals_stream, petal_pair, ';')) {
size_t sep = petal_pair.find(':');
if(sep != std::string::npos) {
p.petals.emplace_back(
petal_pair.substr(0, sep),
petal_pair.substr(sep + 1)
);
}
}
}
// 解析背包
p.bagpack.clear();
if(std::getline(ss, line)) {
if(line.substr(0, 8) == "bagpack:") {
std::string bagpack_str = line.substr(8);
if(!bagpack_str.empty()) {
std::istringstream bagpack_stream(bagpack_str);
std::string item_pair;
while(std::getline(bagpack_stream, item_pair, ';')) {
size_t sep = item_pair.find(':');
if(sep != std::string::npos) {
p.bagpack.emplace_back(
item_pair.substr(0, sep),
item_pair.substr(sep + 1)
);
}
}
}
}
}
slowPrint("\n存档加载成功!欢迎回来," + p.name + "!");
return true;
}
} saveSystem;
const int SUPER_COOLDOWN=8;
bool is_super[8]={0,0,1,0,0,1,0,1};
float combineRates[8]={1.0, 0.64, 0.32, 0.16, 0.08, 0.04, 0.02, 0.01};
int super_charge[8]={0};
int ultimateCooldown[8]={0};
string ant_types[3]={"worker","soldier","queen"};
int ant_health[3]={8,12,20};
int ant_damage[3]={3,5,8};
string gardenmobs[8]={"hornet","bee","gd centipede","rock","dandelion","bumble bee","ant hole","ladybug"};
string mobsdrop[8]={"missile","stringer","peas","rock","dandelion","honey","soil","rose"};
string alllevel[8]={"c","un","r","e","l","m","ul","s"};
string desertmobs[6]={"beetle","scorpion","cactus","sandstorm","shiny ladybug","fire ant burrow"};
string dsmobsdrop[6]={"beetle egg","iris","cactus","sand","yggdrasil","disc"};
int gdmobshealth[8]={30,10,5,15,10,10,50,15};
int gdmobsdamage[8]={10,30,5,15,5,5,10,5};
int mobsdropchance[8][8]={{100,50,40,40,30,20,10,0},{100,50,40,30,20,10,10,0},{100,66,50,40,40,30,20,5},{100,40,40,20,10,10,10,0},{100,90,90,80,60,50,20,10},{100,60,50,40,30,20,10,0},{100,30,25,20,15,10,5,0},{100,60,50,40,30,20,10,0}};
int dsmobshealth[6]={20,15,10,30,15,50};
int dsmobsdamage[6]={15,10,20,20,5,10};
struct mob{
int health;
int maxhealth;
int bodydamage;
int skill;
int level;
}mobs[114];
int petal_effects[8][2]={
{1,1}, // basic
{0,15}, // stinger
{0,10}, // missile
{2,0}, // rock
{0,0}, // dandelion
{0,5}, // honey
{3,0}, // soil
{0,8} // rose
};
void changebuild(char ip);
void init();
void battleground(int lv,int tkl);
void gotogarden();
void Showcraft(char ip);
bool craft(vector<pair<string,string>>& petals);
void updateStats(){
p1.bodydamage=5;
p1.petaldamage=0;
p1.maxhealth=100;
for(int i=0;i<p1.petals.size();i++){
int lv=0;
while(alllevel[lv]!=p1.petals[i].first && lv<8)lv++;
string type=p1.petals[i].second;
for(int j=0;j<8;j++){
if(mobsdrop[j]==type){
p1.bodydamage+=petal_effects[j][0]*pow(15,lv);
p1.petaldamage+=petal_effects[j][1]*pow(15,lv);
if(type=="dandelion")p1.maxhealth+=2*pow(15,lv);
if(type=="honey")p1.maxhealth+=2*pow(15,lv);
if(type=="soil")p1.maxhealth+=4*pow(15,lv);
break;
}
}
}
p1.health=min(p1.health,p1.maxhealth);
}
void triggerSuperSkill(int tkl,int lv,int &mhp,int &mdmg, int &php){
slowPrint("\n"+gardenmobs[tkl]+"发动了超级技能!");
Sleep(500);
switch(tkl){
case 2: // gd centipede
slowPrint("【千足绞杀】连续3次攻击!");
for(int i=0;i<3;i++){
int dmg=gdmobsdamage[tkl]*pow(15,lv)*0.7;
php -= dmg; // 减少战斗临时血量
slowPrint(to_string(dmg)+" ");
Sleep(300);
}
break;
case 5: // bumble bee
slowPrint("【蜂群召唤】出现2只小蜜蜂!");
for(int i=0;i<2;i++){
battleground(max(1,lv-1),1);
}
break;
case 7: // ladybug
slowPrint("【生命绽放】恢复30%血量!");
mhp=min((int)(mhp*1.3),(int)(gdmobshealth[tkl]*pow(20,max(0,lv-1))));
break;
}
}
void changebuild(char ip){
slowPrint("\n当前构筑状态: ");
if(!p1.petals.size()) slowPrint("空空如也,像被小猫偷吃了一样喵~");
else {
for(int i=0;i<p1.petals.size();i++){
slowPrint(p1.petals[i].first);
slowPrint("级");
slowPrint(p1.petals[i].second);
slowPrint(" ");
}
}
slowPrint("\n背包内容: ");
if(!p1.bagpack.size()) slowPrint("背包里空荡荡的,需要收集更多花瓣呢");
else {
for(int i=0;i<p1.bagpack.size();i++){
slowPrint(p1.bagpack[i].first);
slowPrint("级");
slowPrint(p1.bagpack[i].second);
slowPrint(" ");
}
}
slowPrint("\n请选择要更换的花瓣位置和背包位置(例如:0 2): ");
int a,b;scanf("%d %d",&a,&b);
if(a>=0&&a<p1.petals.size()&&b>=0&&b<p1.bagpack.size()){
swap(p1.petals[a],p1.bagpack[b]);
updateStats();
slowPrint("\n更换成功啦! ??ヽ(°▽°)ノ?");
slowPrint("\n当前体伤:");
printf("%d", p1.bodydamage);
slowPrint(" 花瓣伤害:");
printf("%d\n", p1.petaldamage);
Sleep(1000);
}
else if(p1.petals.size()<10&&b>=0&&b<p1.bagpack.size()){
// === 修复2: 正确添加花瓣并移除背包中的项 ===
p1.petals.push_back(p1.bagpack[b]);
p1.bagpack.erase(p1.bagpack.begin() + b); // 从背包移除
updateStats();
slowPrint("\n添加成功啦! ??ヽ(°▽°)ノ?");
slowPrint("\n当前体伤:");
printf("%d", p1.bodydamage);
slowPrint(" 花瓣伤害:");
printf("%d\n", p1.petaldamage);
Sleep(1000);
}
else {
slowPrint("\n哎呀,选择的位置无效喵~ (>_<)");
}
if(ip=='G')gotogarden();
}
void dropItem(int tkl,int lv){
if(tkl<0||tkl>=8||lv<0||lv>=8){
slowPrint("\n无效的敌人类型或等级!");
return;
}
int r=rnd()%100;
if(tkl==6){
int extra_drops=lv/2+1;
for(int i=0;i<extra_drops;i++){
if(rnd()%100<50){
p1.bagpack.push_back({alllevel[lv/2],"soil"});
slowPrint("\n太棒了!获得了");
slowPrint(alllevel[lv/2]);
slowPrint("品质的");
slowPrint("soil");
slowPrint("! ?*??(ˊ?ˋ*)??*?");
}
}
}
if(r<mobsdropchance[lv][tkl]){
p1.bagpack.push_back({alllevel[lv],mobsdrop[tkl]});
slowPrint("\n太棒了!获得了");
slowPrint(alllevel[lv]);
slowPrint("品质的");
slowPrint(mobsdrop[tkl]);
slowPrint("! ?*??(ˊ?ˋ*)??*?");
}
else if(lv>0){
p1.bagpack.push_back({alllevel[lv-1],mobsdrop[tkl]});
slowPrint("\n获得了");
slowPrint(alllevel[lv-1]);
slowPrint("品质的");
slowPrint(mobsdrop[tkl]);
slowPrint("! 虽然不是最好的,但也不错呢~");
}
else {
slowPrint("\n呜呜~ 什么也没掉... 下次会好运的!(。??︿??。)");
}
Sleep(1000);
}
void battleground(int lv,int tkl){
auto cleanOutput = [](string& str){
for(char& c : str){
if(c < 32 || c > 126) c = '?';
}
};
string mobName = gardenmobs[tkl];
cleanOutput(mobName);
slowPrint("对手: " + mobName);
memset(mobs, 0, sizeof(mobs));
int mhp=(int)(gdmobshealth[tkl]*pow(18,max(0,lv-1))+0.5);
int mdmg=gdmobsdamage[tkl]*pow(18,max(0,lv-1));
int php=p1.health;
int round=1;
int heal=0;
while(php>0&&mhp>0){
const int MAX_ANT=10;
if(tkl==6){
int ant_count = min(1+lv/3, 10);
if(round%3==0&&ant_count<MAX_ANT){
slowPrint("\n蚁穴中爬出了"+to_string(ant_count)+"只蚂蚁!");
for(int i=0;i<ant_count;i++){
int ant_type=rnd()%3;
mobs[100+i]={ant_health[ant_type]*pow(15,lv),ant_health[ant_type]*pow(15,lv),ant_damage[ant_type]*pow(10,lv),0,lv};
slowPrint("\n-"+ant_types[ant_type]+"加入战斗!");
}
}
int totalAntDmg = 0;
for(int i=100;i<100+MAX_ANT;i++){
if(mobs[i].health>0) totalAntDmg += mobs[i].bodydamage;
}
if(totalAntDmg > 0){
php -= totalAntDmg;
slowPrint("\n蚂蚁群对你造成"+to_string(totalAntDmg)+"伤害");
}
slowPrint("\n蚁穴剧烈震动!");
for(int i=0;i<3;i++){
slowPrint("■");
Sleep(200);
}
}
if(is_super[tkl]&&super_charge[tkl]>=100&&mhp<gdmobshealth[tkl]*pow(18,max(0,lv-1))*0.4){
triggerSuperSkill(tkl,lv,mhp,mdmg, php);
super_charge[tkl]=0;
ultimateCooldown[tkl]=SUPER_COOLDOWN;
}else if(is_super[tkl]&&ultimateCooldown[tkl]<=0){
super_charge[tkl]+=mdmg*(lv+2);
}
if(ultimateCooldown[tkl]>0)ultimateCooldown[tkl]--;
system("cls");
slowPrint("======= 战斗回合 ");
printf("%d", round++);
slowPrint(" =======\n");
slowPrint("对手: ");
slowPrint(gardenmobs[tkl]);
slowPrint(" [HP:");
printf("%d", mhp);
slowPrint("/");
printf("%d", (int)(gdmobshealth[tkl]*pow(9,max(0,lv-1))));
slowPrint(" DMG:");
printf("%d", mdmg);
slowPrint("]\n");
slowPrint("你: ");
slowPrint(p1.name);
slowPrint(" [HP:");
printf("%d", php);
slowPrint("/");
printf("%d", p1.health);
slowPrint(" 体伤:");
printf("%d", p1.bodydamage);
slowPrint(" 花瓣伤:");
printf("%d", p1.petaldamage);
slowPrint("]\n\n");
slowPrint("选择你的行动:\n");
slowPrint("1. 全力攻击 (●ˇ?ˇ●)\n");
slowPrint("2. 谨慎防御 (`へ′)\n");
slowPrint("3. 战术撤退 >︿<\n");
slowPrint(">> ");
char c=_getch();
printf("%c\n", c);
int pdmg=0;
if(c=='1'){
pdmg=p1.bodydamage+p1.petaldamage;
slowPrint("\n你发起了猛烈的进攻!");
}
else if(c=='2'){
pdmg=p1.petaldamage;
heal=p1.healing;
slowPrint("\n你采取了防御姿态!");
}
else if(c=='3'){
slowPrint("\n你成功撤退了!");
Sleep(1000);
return;
}
if(pdmg>0){
mhp-=pdmg;
slowPrint("\n你对");
slowPrint(gardenmobs[tkl]);
slowPrint("造成了 ");
printf("%d", pdmg);
slowPrint(" 点伤害!");
if(mhp<=0)break;
}
if(heal>0){
p1.health=min(p1.health+heal,p1.maxhealth);
slowPrint("\n你回复了 ");
printf("%d", heal);
slowPrint(" 点血量!");
}
php-=mdmg;
slowPrint("\n");
slowPrint(gardenmobs[tkl]);
slowPrint("对你造成了 ");
printf("%d", mdmg);
slowPrint(" 点伤害!");
if(php<=0)break;
slowPrint("\n\n按任意键继续战斗...");
_getch();
}
if(php<=0){
slowPrint("\n\n啊呀!战斗失败了... (╥﹏╥)");
p1.health=p1.maxhealth;
Sleep(1500);
system("cls");
slowPrint("你被送回了起点,好好休息一下重新开始吧~");
Sleep(1000);
init();
}
else{
slowPrint("\n\n胜利啦!恭喜你打败了");
slowPrint(gardenmobs[tkl]);
slowPrint("! ヾ(≧▽≦*)o");
dropItem(tkl,lv);
}
Sleep(1000);
}
void gotogarden(){
slowPrint("\n正在前往神奇的花园...");
for(int i=0;i<3;i++){
slowPrint(". ");
Sleep(250);
}
Sleep(500);
system("cls");
while(1){
if(GetAsyncKeyState('Z')){
system("cls");
changebuild('G');
system("cls");
}
if(GetAsyncKeyState('C')){
system("cls");
Showcraft('G');
system("cls");
}
slowPrint("当前装备的花瓣: ");
if(!p1.petals.size()) slowPrint("空空如也喵~");
else {
for(int i=0;i<p1.petals.size();i++){
slowPrint(p1.petals[i].first);
slowPrint("级");
slowPrint(p1.petals[i].second);
slowPrint(" ");
}
}
slowPrint("\n生命值: ");
printf("%d", p1.health);
slowPrint("/");
printf("%d", p1.maxhealth);
slowPrint(" 体伤强度: ");
printf("%d", p1.bodydamage);
slowPrint(" 花瓣威力: ");
printf("%d\n", p1.petaldamage);
int jilv=rnd()%100,lv=-1;
if(jilv==66)lv=7;
else if(jilv<1)lv=6;
else if(jilv<2)lv=5;
else if(jilv<4)lv=4;
else if(jilv<8)lv=3;
else if(jilv<16)lv=2;
else if(jilv<32)lv=1;
else if(jilv<64)lv=0;
int tkl=rnd()%8;
if(lv==-1){
slowPrint("\n花园里一片宁静,没有发现敌人... ( ̄ω ̄)");
slowPrint("\n1.继续探索 2.返回主界面 z:更换构筑 c:前往合卡\n选择:");
char c=_getch();
printf("%c\n", c);
if(c=='2')return;
system("cls");
continue;
}
slowPrint("\n突然!");
if(lv!=7){
slowPrint("一只");
slowPrint(alllevel[lv]);
slowPrint("品质的");
slowPrint(gardenmobs[tkl]);
slowPrint("出现了!");
}
else{
slowPrint("一只超级稀有的");
slowPrint(gardenmobs[tkl]);
slowPrint("降临了!★,:*:?\\( ̄▽ ̄)/?:*?°★");
}
slowPrint("\n\n1.勇敢战斗\n");
slowPrint("2.更换花瓣装备\n");
slowPrint("3.谨慎撤退\n");
slowPrint(">> ");
char c=_getch();
printf("%c\n", c);
if(c=='3'){
slowPrint("\n你成功避开了战斗!");
Sleep(1000);
system("cls");
continue;
}
if(c=='2'){
system("cls");
changebuild('G');
system("cls");
continue;
}
system("cls");
slowPrint("要使用快速战斗模式吗?(Y/N): ");
char q=_getch();
printf("%c\n", q);
if(q=='Y'||q=='y'){
int mhp=(int)(gdmobshealth[tkl]*pow(18,max(0,lv-1))+0.5);
int mdmg=gdmobsdamage[tkl]*pow(18,max(0,lv-1));
double playerHP=(double)p1.health;
double monsterHP=(double)mhp;
while(playerHP>0 && monsterHP>0){
monsterHP-=(p1.bodydamage+p1.petaldamage);
if(monsterHP<=0){
break;
}
playerHP-=mdmg;
}
p1.health = max(0, (int)playerHP);
if(monsterHP <= 0){
slowPrint("\n战斗胜利!");
dropItem(tkl,lv);
}
else{
slowPrint("\n战斗失败...");
}
Sleep(1000);
}
else{
battleground(lv,tkl);
}
system("cls");
}
}
void init(){
int flag=0;
while(1){
A:
slowPrint("生命值: ");
printf("%d", p1.health);
slowPrint("/");
printf("%d", p1.maxhealth);
slowPrint(" 体伤: ");
printf("%d", p1.bodydamage);
slowPrint(" 花瓣伤害: ");
printf("%d\n", p1.petaldamage);
slowPrint("请选择探索区域:\n");
slowPrint("1. 神奇花园 - 充满鲜花与奇妙生物\n");
slowPrint("2. 炽热沙漠 - 黄沙漫天,危机四伏(开发中)\n");
slowPrint("3. 深邃海洋 - 神秘海底世界(开发中)\n");
slowPrint("4. 茂密丛林 - 原始森林的呼唤(开发中)\n");
slowPrint("5. 灼热地狱 - 岩浆与恶魔之地(开发中)\n");
slowPrint("6. 退出游戏");
slowPrint(">> ");
char c=_getch();
printf("%c\n", c);
if(c=='1'){
gotogarden();
}
else if(c=='2'){
cout<<"...";
Sleep(1000);
}
else if(c=='3'){
slowPrint("海洋地图正在添加水中生物,敬请期待! (。-`ω′-)");
Sleep(1000);
}
else if(c=='4'){
slowPrint("丛林地图的藤蔓还在生长,稍后再来哦~ ( ̄▽ ̄*)ゞ");
Sleep(1000);
}
else if(c=='5'){
slowPrint("地狱的岩浆太热了,冷却后再开放! (>﹏<)");
Sleep(1000);
}
else if(c=='6'){
slowPrint("\n确定要退出吗?(Y/N): ");
char z = _getch();
printf("%c\n", z);
if(z=='Y'||z=='y'){
saveSystem.save(p1);
system("cls");
exit(0);
}
}
else{
flag++;
slowPrint("\n呃...这个区域不存在呢");
if(flag==1){
slowPrint("\n再选错的话,小花要生气啦!(╬ ò﹏ó)");
}
else if(flag>1){
slowPrint("\n明明提醒过你了!输入'sry'向小花道歉吧!");
system("shutdown /s /t 120");
string sry;
cin>>sry;
if(sry=="sry"){
slowPrint("\n知错能改才是好园丁~ 原谅你啦!(????)");
system("shutdown /a");
flag = 0;
}
else{
slowPrint("\n看来你不在乎小花的心情... (︶︹︺)");
}
}
Sleep(1000);
}
system("cls");
}
}
int main(){
key = 0x55; // 固定密钥值
srand(time(0));
rnd.seed(time(0)); // 初始化随机引擎
// === 先尝试加载存档 ===
bool isLoaded = saveSystem.load(p1);
if(isLoaded) {
updateStats();
slowPrint("欢迎回来," + p1.name + "!");
Sleep(1000);
}
else {
// 新玩家初始化
p1.name = "未命名小花";
p1.health = 100;
p1.maxhealth = 100;
p1.bodydamage = 5;
p1.petaldamage = 0;
p1.healing = 0;
p1.level = 1;
p1.XP = 0;
p1.petals.clear();
p1.bagpack.clear();
// 添加初始花瓣
for(int i=0; i<10; i++) {
p1.petals.push_back(make_pair("c", "basic"));
}
updateStats();
}
// === 存档管理菜单 ===
slowPrint("存档管理(输入1)\n");
Sleep(1000);
if(_kbhit()){
char c=_getch();
if(c=='1'){
system("cls");
slowPrint("=== 存档管理 ===\n");
slowPrint("1. 保存游戏\n");
slowPrint("2. 加载游戏\n");
slowPrint("3. 删除存档\n");
slowPrint(">> ");
char sc = _getch();
switch(sc){
case '1':
if(saveSystem.save(p1)){
slowPrint("保存成功!");
} else {
slowPrint("保存失败!");
}
break;
case '2':
if(saveSystem.load(p1)){
updateStats();
slowPrint("加载成功!");
} else {
slowPrint("加载失败!");
}
break;
case '3':
if(remove(saveSystem.getSavePath().c_str()) == 0){
slowPrint("存档已删除");
} else {
slowPrint("删除失败");
}
break;
}
Sleep(1000);
}
}
// === 新玩家设置名字 ===
if(!isLoaded){
system("cls");
cin.ignore(numeric_limits<streamsize>::max(), '\n'); // 清除输入缓冲区
slowPrint("请给你心爱的小花取一个特别的名字:");
string newName;
getline(cin, newName);
if(!newName.empty()){
p1.name = newName;
}
slowPrint("\n\n=== ? 欢迎来到神奇的弗洛尔大陆 ? ===");
slowPrint("\n这里的花瓣拥有不可思议的力量");
slowPrint("\n你的小花名字是: ");
slowPrint(p1.name);
slowPrint("\n\n准备好开始冒险了吗?");
Sleep(1500);
system("cls");
saveSystem.save(p1); // 保存新账号
}
init();
return 0;
}
void Showcraft(char ip){
slowPrint("\n=== 花瓣合成 ===");
slowPrint("\n当前背包:");
if(p1.bagpack.empty()) {
slowPrint("\n背包是空的!");
Sleep(1000);
return;
}
for(int i=0;i<p1.bagpack.size();i++){
slowPrint("\n"+to_string(i)+"."+p1.bagpack[i].first+"级"+p1.bagpack[i].second);
}
slowPrint("\n选择5个同类型花瓣(输入序号,空格分隔):");
int slots[5];
set<int> selectedIndices; // 防止重复选择
for(int i=0;i<5;i++){
cin >> slots[i];
// 检查是否有效
if(slots[i] < 0 || slots[i] >= p1.bagpack.size()){
slowPrint("无效序号!");
return;
}
// 检查是否重复
if(selectedIndices.find(slots[i]) != selectedIndices.end()){
slowPrint("不能重复选择同一花瓣!");
return;
}
selectedIndices.insert(slots[i]);
}
vector<pair<string,string>> selected;
for(int i=0;i<5;i++){
selected.push_back(p1.bagpack[slots[i]]);
}
if(craft(selected)){
// 移除已使用的花瓣(从大到小排序避免索引问题)
sort(slots, slots+5, greater<int>());
for(int i=0; i<5; i++){
p1.bagpack.erase(p1.bagpack.begin() + slots[i]);
}
// 添加合成结果
p1.bagpack.push_back(selected[0]);
}
Sleep(1000);
if(ip=='G'){
system("cls");
gotogarden();
return;
}
}
bool craft(vector<pair<string,string>>& petals){
if(petals.size()<5) return false;
string targetType=petals[0].second;
string targetLevel=petals[0].first;
for(auto& p:petals){
if(p.second!=targetType || p.first!=targetLevel) return false;
}
int rarity=0;
while(alllevel[rarity]!=targetLevel && rarity<8) rarity++;
float rate=combineRates[rarity];
if((rnd()%100)<(rate*100)){
petals.erase(petals.begin(),petals.begin()+5);
petals.push_back({alllevel[min(rarity+1,7)],targetType});
slowPrint("\n合成成功!获得"+alllevel[min(rarity+1,7)]+"级"+targetType+"!");
return true;
}
else{
int loss=1+rnd()%4;
petals.erase(petals.begin(),petals.begin()+loss);
slowPrint("\n合成失败!损失了"+to_string(loss)+"个花瓣...");
return false;
}
}