种瓜模拟器0.1.4(国庆节)(大更新)
2026-10-01 17:47:18
发布于:广东
Melon Growing Simulator 0.1.4 国庆节版本
更新类型:Bug 修复 + 界面美化
新增:
- 控制台彩色文字输出,国庆祝福语高亮显示
- 全部 int 改为 long long,解决金钱、种子数值溢出问题
- 完善 safe_cin 安全输入函数,拦截字母、符号等非法输入,防止程序卡死
修复:
- 修正注释笔误
falg2→flag2
优化:
- 全部界面增加国庆节主题文字,三语言同步
- 代码结构整理,Refresh、命名规范优化
- 存档读写逻辑稳定性提升
本人原创代码,仅供复制代码游玩,未经同意,请勿转载改编
———————————————————————————
代码:
#include<bits/stdc++.h>
#include<windows.h>
#define int long long
using namespace std;
const int N = 2e5 + 10;
int lu = 3;//Language语言,1.简体中文 2.繁体中文 3.English
bool flag = false,flag2 = false,mode = false;//flag收瓜时自动补种 falg2成熟时自动收瓜 mode是否开创造
void clean() {
#ifdef _WIN32
system("cls");
#else//**/
system("clear");
#endif
}
void await(double ms) {
#ifdef _WIN32
Sleep(ms*1000);
#else
usleep(ms * 1000*1000);
#endif
}
WORD setColorAuto(int textColor, int backColor = 0){
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(hConsole, &csbi);
WORD originalColor = csbi.wAttributes;
WORD newColor = static_cast<WORD>((backColor << 4) | textColor);
SetConsoleTextAttribute(hConsole, newColor);
return originalColor;
}void printColor(const char* str, int textColor, int backColor = 0){
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(hConsole, &csbi);
WORD originalColor = csbi.wAttributes;
WORD newColor = static_cast<WORD>((backColor << 4) | textColor);
SetConsoleTextAttribute(hConsole, newColor);
std::cout << str;
SetConsoleTextAttribute(hConsole, originalColor);
}
void safe_cin(int &x){
string s;
cin >> s;
x = 0;
if(s.size() >= 20){
x = 1e9;
return;
}
for(int i = 0;i < s.size();i++){
if(!isdigit(s[i])){
x = 1e9;
return;
}
x *= 10;
x += s[i] - '0';
}
}
void Refresh(char melon_field[],int &seed,int &money){//刷新
clean();
int tm = 1;
for(int i = 1;i <= 5;i++){
for(int j = 1;j <= 5;j++){
if(melon_field[tm] == '.'){
melon_field[tm] = 'Y';
}else if(melon_field[tm] == 'Y'){
melon_field[tm] = 'O';
}else if(melon_field[tm] == 'O'){
melon_field[tm] = 'Q';
}else if(melon_field[tm] == 'Q'){
if(flag2){
money += 8;
melon_field[tm] = '#';
if(flag){
if(seed > 0){
melon_field[tm] = '.';
if(!mode) seed--;
}
}
}
}
tm++;
}
}
}
void print_melon_field(char melon_field[],int &money,int &seed){
if(lu == 1){
cout << "=========瓜 田=========\n";//简体中文
printColor("国庆节快乐!\n",12);
}else if(lu == 2){
cout << "=========瓜 田=========\n";//繁體中文
printColor("國慶節快樂!\n",12);
}else{
cout << "======melon field======\n";//English
printColor("Happy National Day!\n",12);
}
if(lu == 1){
cout << "钱:" << money << " 种子:" << seed << "\n";//简体中文
}else if(lu == 2){
cout << "錢:" << money << " 種子:" << seed << "\n";//繁體中文
}else{
cout << "money:" << money << " seed:" << seed << "\n";//English
}
int tm = 1;//临时变量,是输出的第几个瓜
for(int i = 1;i <= 5;i++){
for(int j = 1;j <= 5;j++){
cout << melon_field[tm];
tm++;
}
cout << "\n";
}
cout << "\n";
cout.flush();
if(lu == 1){
cout << "1.种瓜\n2.收瓜\n3.买种子\n4.退出\n5.刷新\n";//简体中文
}else if(lu == 2){
cout << "1.種瓜\n2.收瓜\n3.買種子\n4.退出\n5.刷新\n";//繁體中文
}else{
cout << "1.Plant melons\n2.Harvest melons\n3.Buy seeds\n4.Exit\n5.Refresh\n";//English
}
}
void play_melon_field(char melon_field[],int &money,int &seed){
while(true){
print_melon_field(melon_field,money,seed);
int op;
if(lu == 1){
cout << "请输入指令(只需输入对应数字即可)>>>";//简体中文
}else if(lu == 2){
cout << "請輸入指令(只需輸入對應數字即可)>>>";//繁體中文
}else{
cout << "Please enter the command(Just enter the corresponding number)>>>";//English
}
cout.flush();
safe_cin(op);
while((op > 5 || op < 1) && op != 19491001){
clean();
if(lu == 1){
printColor("请输入1-5的数字",12);
}else if(lu == 2){
printColor("請輸入1-5的數字",12);
}else{
printColor("Please enter a number from 1 to 5",12);
}
cout.flush();
await(5);
clean();
print_melon_field(melon_field,money,seed);
cout.flush();
if(lu == 1){
cout << "请输入指令(只需输入对应数字即可)>>>";//简体中文
}else if(lu == 2){
cout << "請輸入指令(只需輸入對應數字即可)>>>";//繁體中文
}else{
cout << "Please enter the command(Just enter the corresponding number)>>>";//English
}
safe_cin(op);
}
if(op == 1){
int x,y;
if(lu == 1){
cout << "请输入行坐标(从1~5)\n>>>";//简体中文
}else if(lu == 2){
cout << "請輸入行座標(從1~5)\n>>>";//繁體中文
}else{
cout << "Please enter the line coordinate (from 1 to 5)\n>>>";//English
}
cout.flush();
safe_cin(x);
while(x > 5 || x < 1){
clean();
if(lu == 1){
printColor("请输入1-5的数字",12);
}else if(lu == 2){
printColor("請輸入1-5的數字",12);
}else{
printColor("Please enter a number from 1 to 5",12);
}
cout.flush();
await(5);
clean();
print_melon_field(melon_field,money,seed);
if(lu == 1){
cout << "请输入行坐标(从1~5)\n>>>";//简体中文
}else if(lu == 2){
cout << "請輸入行座標(從1~5)\n>>>";//繁體中文
}else{
cout << "Please enter the line coordinate (from 1 to 5)\n>>>";//English
}
cout.flush();
safe_cin(x);
}
if(lu == 1){
cout << "请输入列坐标(从1~5)\n>>>";//简体中文
}else if(lu == 2){
cout << "請輸入列座標(從1~5)\n>>>";//繁體中文
}else{
cout << "Please enter the column coordinate (from 1 to 5)\n>>>";//English
}
cout.flush();
safe_cin(y);
while(y > 5 || y < 1){
clean();
if(lu == 1){
printColor("请输入1-5的数字",12);
}else if(lu == 2){
printColor("請輸入1-5的數字",12);
}else{
printColor("Please enter a number from 1 to 5",12);
}
cout.flush();
await(5);
clean();
print_melon_field(melon_field,money,seed);
if(lu == 1){
cout << "请输入列坐标(从1~5)\n>>>";//简体中文
}else if(lu == 2){
cout << "請輸入列座標(從1~5)\n>>>";//繁體中文
}else{
cout << "Please enter the column coordinate (from 1 to 5)\n>>>";//English
}
cout.flush();
safe_cin(y);
}
if(seed <= 0 && !mode){
if(lu == 1){
printColor("\n没有种子了,请购买种子",12);//简体中文
}else if(lu == 2){
printColor("\n沒有種子了,請購買種子",12);//繁體中文
}else{
printColor("\nNo seeds left,please buy seeds",12);//English
}
await(3);
}else{
if(!mode) seed--;
melon_field[(x - 1) * 5 + y] = '.';
clean();
}
clean();
}
if(op == 2){
int x,y;
if(lu == 1){
cout << "请输入行坐标(从1~5)\n>>>";//简体中文
}else if(lu == 2){
cout << "請輸入行座標(從1~5)\n>>>";//繁體中文
}else{
cout << "Please enter the line coordinate (from 1 to 5)\n>>>";//English
}
cout.flush();
safe_cin(x);
while(x > 5 || x < 1){
clean();
if(lu == 1){
printColor("请输入1-5的数字",12);
}else if(lu == 2){
printColor("請輸入1-5的數字",12);
}else{
printColor("Please enter a number from 1 to 5",12);
}
cout.flush();
await(5);
clean();
print_melon_field(melon_field,money,seed);
if(lu == 1){
cout << "请输入行坐标(从1~5)\n>>>";//简体中文
}else if(lu == 2){
cout << "請輸入行座標(從1~5)\n>>>";//繁體中文
}else{
cout << "Please enter the line coordinate (from 1 to 5)\n>>>";//English
}
cout.flush();
safe_cin(x);
}
if(lu == 1){
cout << "请输入列坐标(从1~5)\n>>>";//简体中文
}else if(lu == 2){
cout << "請輸入列座標(從1~5)\n>>>";//繁體中文
}else{
cout << "Please enter the column coordinate (from 1 to 5)\n>>>";//English
}
cout.flush();
safe_cin(y);
while(y > 5 || y < 1){
clean();
if(lu == 1){
printColor("请输入1-5的数字",12);
}else if(lu == 2){
printColor("請輸入1-5的數字",12);
}else{
printColor("Please enter a number from 1 to 5",12);
}
cout.flush();
await(5);
clean();
print_melon_field(melon_field,money,seed);
if(lu == 1){
cout << "请输入列坐标(从1~5)\n>>>";//简体中文
}else if(lu == 2){
cout << "請輸入列座標(從1~5)\n>>>";//繁體中文
}else{
cout << "Please enter the column coordinate (from 1 to 5)\n>>>";//English
}
cout.flush();
safe_cin(y);
}
if(melon_field[(x - 1) * 5 + y] == 'Q') {
melon_field[(x - 1) * 5 + y] = '#';
money += 10;
if(flag){
if(seed > 0){
melon_field[(x - 1) * 5 + y] = '.';
seed--;
}
}
}
clean();
}
if(op == 3){
if(lu == 1){
cout << "请输入购买数量\n>>>";//简体中文
}else if(lu == 2){
cout << "請輸入購買數量\n>>>";//繁體中文
}else{
cout << "Please enter the purchase quantity\n>>>";//English
}
int sum = 0;
safe_cin(sum);
if(sum * 5 > money && !mode){
if(lu == 1){
printColor("\n钱不够了",12);//简体中文
}else if(lu == 2){
printColor("\n錢不夠了",12);//繁體中文
}else{
printColor("\nNot enough money",12);//English
}
await(3);
clean();
}else{
if(lu == 1){
cout << "\n购买成功";//简体中文
}else if(lu == 2){
cout << "\n購買成功";//繁體中文
}else{
cout << "\nPurchase successful";//English
}
seed += sum;
if(!mode) money -= sum * 5;
await(3);
clean();
}
}
if(op == 4){
string save_code = "";
for(int i = 1;i <= 25;i++){
if(melon_field[i] == '#') save_code += '0';
else if(melon_field[i] == '.') save_code += '1';
else if(melon_field[i] == 'Y') save_code += '2';
else if(melon_field[i] == 'O') save_code += '3';
else if(melon_field[i] == 'Q') save_code += '4';
}
save_code += "|";
save_code += to_string(money);
save_code += "|";
save_code += to_string(seed);
save_code += "#";
if(lu == 1){
cout << "\n你的存档码:"<<save_code;
}else if(lu == 2){
cout << "\n你的存檔碼:"<<save_code;
}else{
cout << "\nYour save code:"<<save_code;
}
await(5);
cout.flush();
return;
}
if(op == 5){
Refresh(melon_field,seed,money);
}
if(op == 19491001){
clean();
if(!mode){
mode = true;
if(lu == 1){
cout << "创造:";//简体中文
printColor("开",2);
}else if(lu == 2){
cout << "創造:";//繁體中文
printColor("開",2);
}else{
cout << "Create: ";//English
printColor("On",2);
}
await(2);
}else{
mode = false;
if(lu == 1){
cout << "创造:";//简体中文
printColor("关",12);
}else if(lu == 2){
cout << "創造:";//繁體中文
printColor("關",12);
}else{
cout << "Create: ";//English
printColor("Off",12);
}
await(2);
}
clean();
}
}
}
void new_melon_field(){//新建程序
char melon_field[30];
int money = 500,seed = 25;
for(int i = 1;i <= 25;i++){
melon_field[i] = '#';
}
play_melon_field(melon_field,money,seed);
return;
}
void open_melon_field(){//打开程序
char melon_field[30];
int money = 0,seed = 0;
string cin_save_code;
if(lu == 1){
cout << "请输入存档码\n>>>";//简体中文
}else if(lu == 2){
cout << "請輸入存檔碼\n>>>";//繁體中文
}else{
cout << "Please enter the save code\n>>>";//English
}
cin >> cin_save_code;
if(cin_save_code.size() < 30){
clean();
if(lu == 1) printColor("存档码无效,新建瓜田\n",12);
else if(lu == 2) printColor("存檔碼無效,新建瓜田\n",12);
else printColor("Invalid save code, create new field\n",12);
await(3);
clean();
new_melon_field();
}
int tm = 1;
for(int i = 0;i < 25;i++){
if(cin_save_code[i] == '0'){
melon_field[i+1] = '#';
}else if(cin_save_code[i] == '1'){
melon_field[i+1] = '.';
}else if(cin_save_code[i] == '2'){
melon_field[i+1] = 'Y';
}else if(cin_save_code[i] == '3'){
melon_field[i+1] = 'O';
}else if(cin_save_code[i] == '4'){
melon_field[i+1] = 'Q';
}
tm++;
}
while(cin_save_code[tm] != '|'){
money *= 10;
money += cin_save_code[tm] - '0';
tm++;
}
tm++;
while(cin_save_code[tm] != '#'){
seed *= 10;
seed += cin_save_code[tm] - '0';
tm++;
}
clean();
play_melon_field(melon_field,money,seed);
return;
}
void Language_Settings(){//语言设置
clean();
if(lu == 1){
cout << "1.简体中文\n2.繁體中文\n3.English\n请输入指令(只需输入对应的数字)>>>";
}else if(lu == 2){
cout << "1.简体中文\n2.繁體中文\n3.English\n請輸入指令 (只需輸入對應的數字)>>>";
}else{
cout << "1.简体中文\n2.繁體中文\n3.English\nPlease enter the command (Just enter the corresponding number)>>>";
}
cout.flush();
int luop;
safe_cin(luop);
if(luop == 1){
lu = 1;
}else if(luop == 2){
lu = 2;
}else if(luop == 3){
lu = 3;
}
clean();
return;
}
void Settings(){//设置
clean();
int op;
do{
if(lu == 1){
cout << "1.语言\n2.瓜田\n3.图鉴\n其他.返回\n";//简体中文
}else if(lu == 2){
cout << "1.語言\n2.瓜田\n3.圖鑑\n其他.返回\n";//繁體中文
}else{
cout << "1.Language\n2.Melon field\n3.Picture album / Illustrated guide\nOther.Return\n";//English
}
if(lu == 1){
cout << "请输入指令>>>";//简体中文
}else if(lu == 2){
cout << "請輸入指令>>>";//繁體中文
}else{
cout << "Please enter the command>>>";//English
}
safe_cin(op);
if(op == 1){
Language_Settings();
}else if(op == 2){
clean();
int ifelse;
do{
if(flag){
if(lu == 1){
cout << "1.收瓜时自动补种:";
printColor("开\n",2);
}else if(lu == 2){
cout << "1.收瓜時自動補種:";
printColor("開\n",2);
}else{
cout << "1.Auto replant after harvest:";
printColor("On\n",2);
}
}else if(!flag){
if(lu == 1){
cout << "1.收瓜时自动补种:";
printColor("关\n",12);
}else if(lu == 2){
cout << "1.收瓜時自動補種:";
printColor("關\n",12);
}else{
cout << "1.Auto replant after harvest:";
printColor("Off\n",12);
}
}
if(flag2){
if(lu == 1){
cout << "2.成熟时自动收瓜:";
printColor("开\n",2);
}else if(lu == 2){
cout << "2.成熟時自動收瓜:";
printColor("開\n",2);
}else{
cout << "2.Auto-harvest melons when ripe:";
printColor("On\n",2);
}
}else if(!flag2){
if(lu == 1){
cout << "2.成熟时自动收瓜:";
printColor("关\n",12);
}else if(lu == 2){
cout << "2.成熟時自動收瓜:";
printColor("關\n",12);
}else{
cout << "2.Auto-harvest melons when ripe:";
printColor("Off\n",12);
}
}
if(lu == 1){
cout << "其他.返回\n";//简体中文
}else if(lu == 2){
cout << "其他.返回\n";//繁體中文
}else{
cout << "Other.Return\n";//English
}
if(lu == 1){
cout << "请输入指令>>>";//简体中文
}else if(lu == 2){
cout << "請輸入指令>>>";//繁體中文
}else{
cout << "Please enter the command>>>";//English
}
safe_cin(ifelse);
if(ifelse == 1){
flag = !flag;
}
if(ifelse == 2){
flag2 = !flag2;
}
cout.flush();
clean();
}while(ifelse == 1 ||ifelse == 2);
}else if(op == 3){
clean();
if(lu == 1){
cout << "# -> 空地\n. -> 种子\nY -> 西瓜苗\nO -> 生西瓜\nQ -> 西瓜\n";//简体中文
}else if(lu == 2){
cout << "# -> 空地\n. -> 種子\nY -> 西瓜苗\nO -> 生西瓜\nQ -> 西瓜\n";//繁體中文
}else{
cout << "# -> Vacant land\n. -> Seed\nY -> Watermelon seedlings\nO -> Unripe watermelon\nQ -> Watermelon\n";//English
}
string t;
if(lu == 1){
cout << "输入任意内容并回车返回>>>";//简体中文
}else if(lu == 2){
cout << "輸入任意內容並回車返回>>>";//繁體中文
}else{
cout << "Enter any content and press Enter to return>>>";//English
}
cin >>t;
clean();
}else{
clean();
return;
}
}while(op == 1 || op == 2 || op == 3);
return;
}
void Main_Interface(){//主界面程序
while(true){
if(lu == 1){
cout << "欢迎来到种瓜模拟器\n";
printColor("国庆节快乐!\n",12);
cout << "=============\n1.打开\n2.新建\n3.设置\n4.返回\n请输入指令(只需输入对应的数字)>>>";
}else if(lu == 2){
cout << "歡迎來到種瓜模擬器\n";
printColor("國慶節快樂!\n",12);
cout << "=============\n1.開啟\n2.新增\n3.設置\n4.返回\n請輸入指令(只需輸入對應的數字)>>>";
}else{
cout << "Welcome to the Melon Growing Simulator\n";
printColor("Happy National Day!\n",12);
cout << "=============\n1.Open\n2.New\n3.Settings\n4.Return\nPlease enter the command(Just enter the corresponding number)>>>";
}
cout.flush();
int op;
safe_cin(op);
while(op < 1 ||op > 4){
clean();
if(lu == 1){
printColor("请输入1-4的数字",12);
}else if(lu == 2){
printColor("請輸入1-4的數字",12);
}else{
printColor("Please enter a number from 1 to 4",12);
}
cout.flush();
await(5);
clean();
if(lu == 1){
cout << "欢迎来到种瓜模拟器\n";
printColor("国庆节快乐!\n",12);
cout << "=============\n1.打开\n2.新建\n3.设置\n4.返回\n请输入指令(只需输入对应的数字)>>>";
}else if(lu == 2){
cout << "歡迎來到種瓜模擬器\n";
printColor("國慶節快樂!\n",12);
cout << "=============\n1.開啟\n2.新增\n3.設置\n4.返回\n請輸入指令(只需輸入對應的數字)>>>";
}else{
cout << "Welcome to the Melon Growing Simulator\n";
printColor("Happy National Day!\n",12);
cout << "=============\n1.Open\n2.New\n3.Settings\n4.Return\nPlease enter the command(Just enter the corresponding number)>>>";
}
cout.flush();
safe_cin(op);
await(5);
}
if(op == 1){
clean();
open_melon_field();
clean();
}else if(op == 2){
clean();
new_melon_field();
cout.flush();
await(5);
clean();
}else if(op == 3){
Settings();
}else if(op == 4){
clean();
if(lu == 1){
cout << "再见";
}else if(lu == 2){
cout << "再見";
}else{
cout << "Goodbye";
}
break;
}
}
}
signed main(){
Main_Interface();
return 0;
}
//种瓜模拟器0.1.4版本
这里空空如也





















有帮助,赞一个