Melon Growing Simula
2026-07-21 10:56:47
发布于:广东
0.0.4版本,350行,纯手写,有兴趣的可以复制代码来玩
代码
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
const int N = 2e5 + 10;
int lu = 3;//Language语言,1.简体中文 2.繁体中文 3.English
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
}
void Refresh(char melon_field[]){
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';
}
tm++;
}
}
}
void new_melon_field(){//新建程序
char melon_field[30];
int money = 500,seed = 25;
for(int i = 1;i <= 25;i++){
melon_field[i] = '#';
}
while(true){
if(lu == 1){
cout << "=========瓜 田=========\n";//简体中文
}else if(lu == 2){
cout << "=========瓜 田=========\n";//繁體中文
}else{
cout << "======melon field======\n";//English
}
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();
int op;
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\nPlease enter the command(Just enter the corresponding number)>>>";//English
}
cout.flush();
cin >> op;
while(op > 5 || op < 1){
clean();
if(lu == 1){
cout << "请输入1-5的数字";
}else if(lu == 2){
cout << "請輸入1-5的數字";
}else{
cout << "Please enter a number from 1 to 5";
}
cout.flush();
await(5);
clean();
cin >> op;
}
if(op == 1){
int x,y;
if(lu == 1){
cout << "请输入x坐标(从1~5)\n>>>";//简体中文
}else if(lu == 2){
cout << "請輸入x座標(從1~5)\n>>>";//繁體中文
}else{
cout << "Please enter the x coordinate (from 1 to 5)\n>>>";//English
}
cout.flush();
cin >> x;
while(x > 5 || x < 1){
clean();
if(lu == 1){
cout << "请输入1-5的数字";
}else if(lu == 2){
cout << "請輸入1-5的數字";
}else{
cout << "Please enter a number from 1 to 5";
}
cout.flush();
await(5);
clean();
if(lu == 1){
cout << "请输入x坐标(从1~5)\n>>>";//简体中文
}else if(lu == 2){
cout << "請輸入x座標(從1~5)\n>>>";//繁體中文
}else{
cout << "Please enter the x coordinate (from 1 to 5)\n>>>";//English
}
cout.flush();
cin >> x;
}
if(lu == 1){
cout << "请输入y坐标(从1~5)\n>>>";//简体中文
}else if(lu == 2){
cout << "請輸入y座標(從1~5)\n>>>";//繁體中文
}else{
cout << "Please enter the y coordinate (from 1 to 5)\n>>>";//English
}
cout.flush();
cin >> y;
while(y > 5 || y < 1){
clean();
if(lu == 1){
cout << "请输入1-5的数字";
}else if(lu == 2){
cout << "請輸入1-5的數字";
}else{
cout << "Please enter a number from 1 to 5";
}
cout.flush();
await(5);
clean();
if(lu == 1){
cout << "请输入y坐标(从1~5)\n>>>";//简体中文
}else if(lu == 2){
cout << "請輸入y座標(從1~5)\n>>>";//繁體中文
}else{
cout << "Please enter the y coordinate (from 1 to 5)\n>>>";//English
}
cout.flush();
cin >> y;
}
if(seed <= 0){
if(lu == 1){
cout << "没有种子了,请购买种子";//简体中文
}else if(lu == 2){
cout << "沒有種子了,請購買種子";//繁體中文
}else{
cout << "No seeds left,please buy seeds";//English
}
}else{
seed--;
melon_field[(x - 1) * 5 + y] = '.';
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);
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);
}
}
}
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;
cin >> luop;
if(luop == 1){
lu = 1;
}else if(luop == 2){
lu = 2;
}else{
lu = 3;
}
clean();
return;
}
void Settings(){
clean();
int op;
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
}
cin >> op;
if(op == 1){
Language_Settings();
return;
}else if(op == 2){
clean();
if(lu == 1){
cout << "此功能暂未实现";
}else if(lu == 2){
cout << "此功能暫未實現";
}else{
cout << "This function has not been implemented yet";
}
cout.flush();
await(5);
clean();
return;
}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();
return;
}else{
clean();
return;
}
}
void Main_Interface(){//主界面程序
while(true){
if(lu == 1){
cout << "欢迎来到种瓜模拟器\n=============\n1.打开\n2.新建\n3.设置\n4.返回\n请输入指令(只需输入对应的数字)>>>";
}else if(lu == 2){
cout << "歡迎來到種瓜模擬器\n=============\n1.開啟\n2.新增\n3.設置\n4.返回\n請輸入指令(只需輸入對應的數字)>>>";
}else{
cout << "Welcome to the Melon Growing Simulator\n=============\n1.Open\n2.New\n3.Settings\n4.Return\nPlease enter the command(Just enter the corresponding number)>>>";
}
cout.flush();
int op;
cin >> op;
while(op < 1 ||op > 4){
clean();
if(lu == 1){
cout << "请输入1-4的数字";
}else if(lu == 2){
cout << "請輸入1-4的數字";
}else{
cout << "Please enter a number from 1 to 4";
}
cout.flush();
await(5);
clean();
if(lu == 1){
cout << "欢迎来到种瓜模拟器\n=============\n1.打开\n2.新建\n3.语言\n4.返回\n请输入指令(只需输入对应的数字)>>>";
}else if(lu == 2){
cout << "歡迎來到種瓜模擬器\n=============\n1.開啟\n2.新增\n3.語言\n4.返回\n請輸入指令(只需輸入對應的數字)>>>";
}else{
cout << "Welcome to the Melon Growing Simulator\n=============\n1.Open\n2.New\n3.Language\n4.Return\nPlease enter the command(Just enter the corresponding number)>>>";
}
cout.flush();
cin >> op;
await(5);
}
if(op == 1){
clean();
if(lu == 1){
cout << "此功能暂未实现";
}else if(lu == 2){
cout << "此功能暫未實現";
}else{
cout << "This function has not been implemented yet";
}
cout.flush();
await(5);
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.0.1更新到0.0.4花了我整整3天
这里空空如也


















有帮助,赞一个