跳到正文

休闲·娱乐

个人c++小模拟系统

Gary_Gary约 97 分钟
原文
文章信息与版本

文章信息

发布
2024年12月1日
收录
2026年11月26日
更新
2026年11月26日
篇幅
约 97 分钟

版本

  1. v1当前

Windows macOS 兼容版来啦!

C++
#ifdef _WIN32
    #include <windows.h>
    #include <bits/stdc++.h>
#else
    #include <iostream>
    #include <cmath> 
    #include <unistd.h>
    #include <iomanip>
    #include <fstream>
#endif
 
using namespace std;
const char* CREDENTIALS_FILE = "credentials.txt";
const char* DATA_FILE = "data.txt";
const char* JINZIQI_FILE = "井字棋存档.txt";
bool return_1 = false;
float j_win, j_lose, j_shenglv;
char board[3][3]; 
bool playerTurn = true;
int Your,Other;
string daojuname[]={"放大镜","手铐","小刀","烟","饮料"};
double Yourmoney;
int huihe;
bool emoqbq=1;
bool ndqbq=1;

int shi,kong;
int q[10],qlen;
int Rand(int x,int y){
    int A=rand(),B=rand();
    return A*1ll*B%(y-x+1)+x;
}
int T;
int daojulen;
int daoju[10];
int daojulen1;
int daoju1[10];
bool is_zhengshu(double number) {
	bool isInteger = (number == static_cast<int>(number));
	if (isInteger) {
		return 0;
	} else{
    	return 1;
	}
}
void build_gun(){
    kong=Rand(1,4);
    shi=Rand(1,4);
    qlen=0;
    printf("%d发实弹,%d发空弹\n",shi,kong);
    int a1=kong,a2=shi;
    for(int i=1;i<=kong+shi;i++){
        int sum=Rand(1,a1+a2);
        if(sum<=a1){
            a1--;
            q[++qlen]=2;
        }else{
            a2--;
            q[++qlen]=1;
        }
    }
    if(huihe!=1){
        int maxn=min(4,8-daojulen);
        printf("你获得了%d个道具:\n",maxn);
        daojulen+=maxn;
        for(int i=1;i<=maxn;i++){
            int kkk=Rand(0,4);
            daoju[kkk]++;
            cout<<daojuname[kkk];
            if(i!=maxn){
                printf(",");
               }
        }
        printf("\n");
        maxn=min(4,8-daojulen1);
        printf("恶魔获得了%d个道具:\n",maxn);
        daojulen1+=maxn;
        for(int i=1;i<=maxn;i++){
            int kkk=Rand(0,4);
            daoju1[kkk]++;
            cout<<daojuname[kkk];
            if(i!=maxn){
                printf(",");
            }
        }
    }
    printf("\n");
    system("pause");
    system("cls");
}
void IsOver(){
    if(Your<=0){
        printf("你输了\n");
        system("pause");
        exit(0);
    }
    if(Other<=0){
        if(huihe==3){
            Yourmoney/=3;
            printf("你赢了\n你获得了奖金$%.2lf\n",Yourmoney);
            system("pause");
            exit(0);
        }else if(huihe==2){
            printf("进入第三回合\n");
            huihe=3;
            Your=6;
            Other=6;
            system("pause");
            system("cls");
            build_gun(); 
        }else if(huihe==1){
            printf("进入第二回合\n");
            huihe=2;
            Your=4;
            Other=4;
            system("pause");
            system("cls");
            build_gun();
        }
    }
}
void wait(){
    for(int i=1;i<=3;i++){
        Sleep(500);
        printf(".");
    }
    Sleep(500);
}
int Hurt=1;
int shoukao_you;
void Timeyou(){
    int x;
    while(1){
        if(!ndqbq){
            printf("你的生命:@#%&%%&@#%@%*&*\n");
        }else{
            printf("你的生命:%d/%d\n",Your,huihe*2);
        }
        if(!emoqbq){
            printf("恶魔生命:@$%#^%%^%&*&%%$\n");
        }else{
            printf("恶魔生命:%d/%d\n",Other,huihe*2);
        }
        printf("剩余实弹数:%d    剩余空弹数:%d\n",shi,kong);
        if(huihe!=1){
            printf("你现在拥有的道具:\n");
            for(int i=0;i<=4;i++){
                cout<<daojuname[i];
                printf("%d",daoju[i]);
                printf("个");
                if(i!=4){
                    printf(",");
                }
            }
            printf("\n");
            printf("恶魔现在拥有的道具:\n");
            for(int i=0;i<=4;i++){
                cout<<daojuname[i];
                printf("%d",daoju1[i]);
                printf("个");
                if(i!=4){
                    printf(",");
                }
            }    
        }
        printf("\n");
        printf("现在是你的回合\n");
        printf("你要\n1.向恶魔开枪\n2.向自己开枪\n");
        if(huihe!=1){
            for(int i=0;i<=4;i++){
                printf("%d.使用",i+3);
                cout<<daojuname[i]<<'\n';
            }
        }
        scanf("%d",&x);
        if((huihe==1&&1<=x&&x<=2)||(huihe!=1&&1<=x&&x<=7)){
            break;
        }
        printf("输入不合法\n");
        Sleep(1145);
        system("cls");
    }
    if(x==1){
        printf("你决定向恶魔开枪");
        T++;
        wait();
        if(q[qlen]==2){
            Yourmoney+=(double)(2000.0*(Hurt*1.0)*(1+(double)(shi)*1.0/(double)(shi+kong)));
            kong--;
            qlen--;
            Hurt=1;
            printf("是空弹\n");
            if(shoukao_you==1){
                shoukao_you=0;
                printf("因为你使用了手铐,所以可以再来一次\n");
                Sleep(500);
                T--;
            }
        }else{
            Yourmoney+=(double)(5000.0*(Hurt*1.0)*(1+(double)(kong)*1.0/(double)(shi+kong)));
            shi--;
            qlen--;
            Other-=Hurt;
            
            printf("是实弹\n");
            printf("造成了%d点伤害\n",Hurt);
            Hurt=1;
            Sleep(500);
            IsOver();
            if(huihe==3&&Other<=2){
                printf("恶魔的起搏器断开!\n");
                emoqbq=1;
                Yourmoney+=5000.0;
            }
            if(shoukao_you==1){
                shoukao_you=0;
                Yourmoney+=1000.0;
                printf("因为你使用了手铐,所以可以再来一次\n");
                Sleep(500);
                T--;
            }
        }
    }else if(x==2){
        printf("你决定向自己开枪");
        wait();
        if(q[qlen]==2){
            Yourmoney+=(double)(2000.0*(Hurt*1.0)*(1+(double)(kong)*1.0/(double)(shi+kong)));
            kong--;
            qlen--;
            Hurt=1;
            printf("是空弹\n");
        }else{
            Yourmoney+=5000.0*(1+(double)(shi)*1.0/(double)(shi+kong));
            T++;
            shi--;
            qlen--;
            Your-=Hurt;
            printf("是实弹\n");
            printf("造成了%d点伤害\n",Hurt);
            Hurt=1;
            Sleep(500);
            IsOver();
            if(huihe==3&&Your<=2){
                printf("你的起搏器断开!\n");
                ndqbq=1;
            }
            if(shoukao_you==1){
                shoukao_you=0;
                printf("因为你使用了手铐,所以可以再来一次\n");
                Sleep(500);
                T--;
            }
        }
    }else if(x==3){
        if(daoju[0]){
            daoju[0]--;
            daojulen--;
            printf("你使用了放大镜\n");
            wait();
            printf("\n你看到了");
            if(q[qlen]==1){
                printf("实弹\n");
                Yourmoney+=2500.0;
            }else{
                printf("空弹\n");
            }
            Sleep(500);
            printf("\n");
        }else{
            printf("你现在没有放大镜\n");
            Sleep(1145);
            system("cls");
        }
    }else if(x==4){
        if(daoju[1]){
            if(!shoukao_you){
                daoju[1]--;
                daojulen--;
                printf("你使用了手铐\n");
                printf("你获得了连开两枪的机会\n");
                shoukao_you=1;
            }else{
                printf("你已经用过手铐了\n");
            }
            Sleep(1145);
            system("cls"); 
        }else{
            printf("你现在没有手铐\n");
            Sleep(1145);
            system("cls");
        }
    }else if(x==5){
        if(daoju[2]){
            daoju[2]--;
            daojulen--;
            printf("你使用了小刀\n");
            printf("若下一发为实弹则伤害翻倍\n");
            Hurt*=2; 
            Yourmoney+=500.0;
            Sleep(1145);
            system("cls");
        }else{
            printf("你现在没有小刀\n");
            Sleep(1145);
            system("cls");
        }
    }else if(x==6){
        if(daoju[3]){
            if(Your^6){
                daoju[3]--;
                daojulen--;
                printf("你使用了烟\n");
                printf("你回复了一点生命\n");
                Yourmoney+=500.0;
                Your++;
            }else{
                printf("你现在不需要烟\n");
            }
            Sleep(1145);
        }else{
            printf("你现在没有烟\n");
            Sleep(1145);
            system("cls");
        }
    }else{
        if(daoju[4]){
            daoju[4]--;
            daojulen--;
            printf("你使用了饮料\n");
            wait();
            printf("\n");
            printf("你退了一发"); 
            if(q[qlen]==2){
                printf("空弹");
                kong--;
            }else{
                printf("实弹");
                Yourmoney+=500.0;
                shi--;
            }
            qlen--;
            Sleep(500);
        }else{
            printf("你现在没有饮料\n");
            Sleep(1145);
            system("cls");
        }
    }
    Sleep(1000);
    system("cls");
}
int Know;
int shoukaoemo;
void fightyou(){
    printf("恶魔决定向你开枪");
    T++;
    wait();
    if(q[qlen]==2){
        Yourmoney+=(double)(2000.0*(Hurt*1.0)*(1+(double)(kong)*1.0/(double)(shi+kong)));
        kong--;
        qlen--;
        Hurt=1;
        Know=0;
        printf("是空弹\n");
        if(shoukaoemo){
            printf("因为恶魔使用了手铐,所以可以再来一次\n");
            T--;
            Sleep(500);
            shoukaoemo=0;
        }
    }else{
        Yourmoney+=(double)(5000.0*(Hurt*1.0)*(1+(double)(kong)*1.0/(double)(shi+kong)));
        shi--;
        qlen--;
        Your-=Hurt;
        printf("是实弹\n");
        printf("造成了%d点伤害\n",Hurt);
        Hurt=1;
        Know=0;
        Sleep(500);
        IsOver();
        if(huihe==3&&Your<=2){
            printf("你的起搏器断开!\n");
            ndqbq=1;
        }
        if(shoukaoemo){
            printf("因为恶魔使用了手铐,所以可以再来一次\n");
            Yourmoney+=1000.0;
            T--;
            Sleep(500);
            shoukaoemo=0;
        }
    }
}
void fightemo(){
    printf("恶魔决定向自己开枪");
    wait();
    if(q[qlen]==2){
        Yourmoney+=2000.0*(1+(double)(shi)*1.0/(double)(shi+kong));
        kong--;
        qlen--;
        printf("是空弹\n");
        Know=0;
    }else{
        Yourmoney+=5000.0*(1+(double)(kong)*1.0/(double)(shi+kong));
        shi--;
        T++;
        qlen--;
        Other-=Hurt;
        printf("是实弹\n");
        printf("造成了%d点伤害\n",Hurt);
        Hurt=1;
        Know=0;
        Sleep(500);
        IsOver();
        if(huihe==3&&Other<=2){
            printf("恶魔的起搏器断开!\n");
            emoqbq=1;
            Yourmoney+=5000.0;
        }
        if(shoukaoemo){
            printf("因为恶魔使用了手铐,所以可以再来一次\n");
            T--;
            Sleep(500);
            shoukaoemo=0;
        }
    }
}
void Timeother(){
    if(!ndqbq){
        printf("你的生命:@#%&%%&@#%@%*&*\n");
    }else{
           printf("你的生命:%d/%d\n",Your,huihe*2);
    }
    if(!emoqbq){
           printf("恶魔生命:@$%#^%%^%&*&%%$\n");
    }else{
           printf("恶魔生命:%d/%d\n",Other,huihe*2);
    }
    printf("剩余实弹数:%d    剩余空弹数:%d\n",shi,kong);
   if(huihe!=1){
        printf("恶魔现在拥有的道具:\n");
        for(int i=0;i<=4;i++){
            cout<<daojuname[i];
            printf("%d",daoju1[i]);
            printf("个");
            if(i!=4){
                printf(",");
            }
        }    
    }
    printf("现在是恶魔的回合\n");
    Sleep(1500);
    if(Other!=6){
        if(daoju1[3]){
            daoju1[3]--;
            daojulen1--;
            printf("恶魔使用了烟\n");
            printf("恶魔回复了一点生命\n");
            Other++;
            Yourmoney+=500.0;
            Sleep(1145);
            system("cls");
            return ;
        }
    }
    if(Know==0&&kong==0){
        Know=1;
    }
    if(Know==0){
        if(abs(shi-kong)<2&&kong!=0){
            if(daoju1[0]){
                daoju1[0]--;
                daojulen1--;
                printf("恶魔使用了放大镜\n");
                wait();
                printf("\nVery Interesting");
                if(q[qlen]==1){
                    Yourmoney+=2500.0;
                    Know=1;
                }else{
                    Know=2;
                }
                Sleep(1145);
                system("cls");
                return ;
            }
        }
    }else if(Know==1){
        if(daoju1[2]){
            daoju1[2]--;
            daojulen1--;
            Hurt*=2;
            printf("恶魔使用了小刀\n");
            printf("若下一发为实弹则伤害翻倍");
            Yourmoney+=500.0;
            Sleep(1145);
            system("cls");
            return;
        }else{
            if(shi>=kong+1&&daoju1[1]&&shoukaoemo!=1){
                daoju1[1]--;
                daojulen1--;
                shoukaoemo=1;
                printf("恶魔使用了手铐\n");
                printf("恶魔获得了连开两枪的机会\n");
                Sleep(1145);
                system("cls");
                return ;
            }
            fightyou();
            system("cls");
            return ;
        }
    }else{
        if(daoju1[4]){
            daoju1[4]--;
            daojulen1--;
            printf("恶魔使用了饮料\n");
            wait();
            printf("\n");
            printf("恶魔退了一发"); 
            if(q[qlen]==2){
                printf("空弹");
                kong--;
            }else{
                printf("实弹");
                shi--;
            }
            Know=0;
            qlen--;
            Sleep(500);
            Sleep(1145);
            system("cls");
            return ;
        }else{
            fightemo();
            Sleep(1145);
            system("cls");
            return ;
        }
    }
    if(shi>=kong){
        fightyou();
    }else{
        fightemo();
    }
    Sleep(1145);
    system("cls");
}
void Play(){
    while(1){
        if(shi==0){
            build_gun();
            T=0;
            continue;
        }
        if(T%2==0){
            Timeyou();
        }else{
            Timeother();
        }
    }
}
void danrenplay(){
    for(int i=1;i<=3;i++){
        printf(".");
//      Sleep(1000);
    }
    printf("\n");
    printf("又来了一位挑战者...\n");
    Sleep(1000);
    int x;
    while(1){
        printf("准备好参与恶魔的游戏吗?胜者带走奖金,败者将会在此长眠\n1.好的\n2.没问题\n");
        scanf("%d",&x);
        if(x==1||x==2){
            break;
        }
        printf("输入不合法\n");
        Sleep(1145);
        system("cls");
    }
    while(1){
        printf("你清楚我们的规则吗?\n1.清楚\n2.不清楚\n");
        scanf("%d",&x);
        if(x==1||x==2){
            break;
        }
        printf("输入不合法\n");
        Sleep(1145);
        system("cls");
    }
    if(x==2){
        for(int i=1;i<=3;i++){
            printf(".");
            Sleep(1000);
        }
        printf("\n");
        printf("规则:\n");
        printf("你和恶魔都各有6点生命\n") ;
        printf("每轮开始前,你将知道一共有几发实弹,几发空弹\n");
        printf("每轮你可以选择对自己开枪,对恶魔开枪或者使用道具\n");
        printf("如果你对自己开枪,若为空弹,则可以继续行动,否则,停止行动\n");
        printf("如果你对恶魔开枪,无论如何,都将停止行动\n");
        printf("第二、三回合每轮开始前双方都将获得4个道具作为补给(上限为8个)\n");
        printf("到了第三回合,若有一方只剩两点生命,则该方的起搏器将被销毁,无法看见自己血量!\n");
        printf("道具一览:\n"); 
        printf("放大镜:可以知道下一发子弹是空弹还是实弹\n");
        printf("手铐:增加一次本回合的行动次数\n");
        printf("小刀:若下一发子弹为实弹,则伤害翻倍\n");
        printf("烟:可以回复1点体力\n");
        printf("饮料:可以退一发子弹\n");
        system("pause");
        system("cls");
    }
    printf("好吧\n");
    Sleep(1145);
    printf("游戏将要开始了哦\n");
    Sleep(1145);
    huihe=1;
    Your=2;Other=2;
    system("cls");
    Play();
}
void IsOver_duo(){
    if(Your<=0){
        printf("玩家B赢了\n玩家B获得了奖金$%.2lf\n",Yourmoney); 
        system("pause");
        exit(0);
    }else if(Other<=0){
        printf("玩家A赢了\n玩家A获得了奖金$%.2lf\n",Yourmoney); 
        system("pause");
        exit(0);
    }

}
void build_gun_duo(){
    kong=Rand(1,4);
    shi=Rand(1,4);
    qlen=0;
    printf("%d发实弹,%d发空弹\n",shi,kong);
    int a1=kong,a2=shi;
    for(int i=1;i<=kong+shi;i++){
//      Sleep(50);
        int sum=Rand(1,a1+a2);
        if(sum<=a1){
            a1--;
            q[++qlen]=2;
        }else{
            a2--;
            q[++qlen]=1;
        }
    }
    int maxn=min(2,8-daojulen);
    printf("玩家A获得了%d个道具:\n",maxn);
    daojulen+=maxn;
    for(int i=1;i<=maxn;i++){
//      Sleep(50);
        int kkk=Rand(0,4);
        daoju[kkk]++;
        cout<<daojuname[kkk];
        if(i!=maxn){
            printf(",");
        }
    }
    printf("\n");
    maxn=min(2,8-daojulen1);
    printf("玩家B获得了%d个道具:\n",maxn);
    daojulen1+=maxn;
    for(int i=1;i<=maxn;i++){
        int kkk=Rand(0,4);
        daoju1[kkk]++;
        cout<<daojuname[kkk];
        if(i!=maxn){
            printf(",");
        }
    }
    printf("\n");
    system("pause");
    system("cls");
}
void Timeyou_duo(){
    int x;
    while(1){
        printf("玩家A的生命:%d/4\n玩家B的生命:%d/4\n",Your,Other);
        printf("剩余实弹数:%d    剩余空弹数:%d\n",shi,kong);
        printf("玩家A现在拥有的道具:\n");
        for(int i=0;i<=4;i++){
            cout<<daojuname[i];
            printf("%d",daoju[i]);
            printf("个");
            if(i!=4){
                printf(",");
            }
        }
        printf("\n");
        printf("玩家B现在拥有的道具:\n");
        for(int i=0;i<=4;i++){
            cout<<daojuname[i];
            printf("%d",daoju1[i]);
            printf("个");
            if(i!=4){
                printf(",");
            }
        }
        printf("\n");
        printf("现在是玩家A的回合\n");
        printf("玩家A要\n1.向玩家B开枪\n2.向自己开枪\n");
        for(int i=0;i<=4;i++){
            printf("%d.使用",i+3);
            cout<<daojuname[i]<<'\n';
        }
        scanf("%d",&x);
        if(1<=x&&x<=7){
            break;
        }
        printf("输入不合法\n");
        Sleep(1145);
        system("cls");
    }
    if(x==1){
        printf("玩家A决定向玩家B开枪");
        T++;
        wait();
        if(q[qlen]==2){
            Yourmoney+=(double)(2000.0*(Hurt*1.0)*(1+(double)(shi)*1.0/(double)(shi+kong)));
            kong--;
            qlen--;
            Hurt=1;
            printf("是空弹\n");
            if(shoukao_you==1){
                shoukao_you=0;
                printf("因为玩家A使用了手铐,所以可以再来一次\n");
                Sleep(500);
                T--;
            }
        }else{
            Yourmoney+=(double)(5000.0*(Hurt*1.0)*(1+(double)(kong)*1.0/(double)(shi+kong)));
            shi--;
            qlen--;
            Other-=Hurt;
            printf("是实弹\n");
            printf("造成了%d点伤害\n",Hurt);
            Hurt=1;
            Sleep(500);
            IsOver_duo();
            if(shoukao_you==1){
                shoukao_you=0;
                Yourmoney+=1000.0;
                printf("因为玩家A使用了手铐,所以可以再来一次\n");
                Sleep(500);
                T--;
            }
        }
    }else if(x==2){
        printf("玩家A决定向自己开枪");
        wait();
        if(q[qlen]==2){
            Yourmoney+=(double)(2000.0*(Hurt*1.0)*(1+(double)(kong)*1.0/(double)(shi+kong)));
            kong--;
            qlen--;
            Hurt=1;
            printf("是空弹\n");
        }else{
            Yourmoney+=5000.0*(1+(double)(shi)*1.0/(double)(shi+kong));
            T++;
            shi--;
            qlen--;
            Your-=Hurt;
            printf("是实弹\n");
            printf("造成了%d点伤害\n",Hurt);
            Hurt=1;
            Sleep(500);
            IsOver_duo();
            if(shoukao_you==1){
                shoukao_you=0;
                printf("因为玩家A使用了手铐,所以可以再来一次\n");
                Sleep(500);
                T--;
            }
        }
    }else if(x==3){//{"放大镜","手铐","小刀","烟","饮料"};
        if(daoju[0]){
            daoju[0]--;
            daojulen--;
            printf("玩家A使用了放大镜\n");
            wait();
            printf("\n玩家A看到了");
            if(q[qlen]==1){
                printf("实弹\n");
                Yourmoney+=2500.0;
            }else{
                printf("空弹\n");
            }
            Sleep(500);
            printf("\n");
        }else{
            printf("玩家A现在没有放大镜\n");
            Sleep(1145);
            system("cls");
        }
    }else if(x==4){
        if(daoju[1]){
            if(!shoukao_you){
                daoju[1]--;
                daojulen--;
                printf("玩家A使用了手铐\n");
                printf("玩家A获得了连开两枪的机会\n");
                shoukao_you=1;
            }else{
                printf("玩家A已经用过手铐了\n");
            }
            Sleep(1145);
            system("cls"); 
        }else{
            printf("玩家A现在没有手铐\n");
            Sleep(1145);
            system("cls");
        }
    }else if(x==5){
        if(daoju[2]){
            daoju[2]--;
            daojulen--;
            printf("玩家A使用了小刀\n");
            printf("若下一发为实弹则伤害翻倍\n");
            Yourmoney+=500.0;
            Hurt*=2;
            Sleep(1145);
            system("cls");
        }else{
            printf("玩家A现在没有小刀\n");
            Sleep(1145);
            system("cls");
        }
    }else if(x==6){
        if(daoju[3]){
            if(Your^4){
                daoju[3]--;
                daojulen--;
                printf("玩家A使用了烟\n");
                printf("玩家A回复了一点生命\n");
                Yourmoney+=500.0;
                Your++;
            }else{
                printf("玩家A现在不需要烟\n");
            }
            Sleep(1145);
        }else{
            printf("玩家A现在没有烟\n");
            Sleep(1145);
            system("cls");
        }
    }else{
        if(daoju[4]){
            daoju[4]--;
            daojulen--;
            printf("玩家A使用了饮料\n");
            wait();
            printf("\n");
            printf("玩家A退了一发"); 
            if(q[qlen]==2){
                printf("空弹");
                kong--;
            }else{
                printf("实弹");
                Yourmoney+=500.0;
                shi--;
            }
            qlen--;
            Sleep(500);
        }else{
            printf("玩家A现在没有饮料\n");
            Sleep(1145);
            system("cls");
        }
    }
    Sleep(1000);
    system("cls");
}
void Timeother_duo(){
    int x;
    while(1){
        printf("玩家A的生命:%d/4\n玩家B的生命:%d/4\n",Your,Other);
        printf("剩余实弹数:%d    剩余空弹数:%d\n",shi,kong);
        printf("玩家A现在拥有的道具:\n");
        for(int i=0;i<=4;i++){
            cout<<daojuname[i];
            printf("%d",daoju[i]);
            printf("个");
            if(i!=4){
                printf(",");
            }
        }
        printf("\n");
        printf("玩家B现在拥有的道具:\n");
        for(int i=0;i<=4;i++){
            cout<<daojuname[i];
            printf("%d",daoju1[i]);
            printf("个");
            if(i!=4){
                printf(",");
            }
        }
        printf("\n");
        printf("现在是玩家B的回合\n");
        printf("玩家B要\n1.向玩家A开枪\n2.向自己开枪\n");
        for(int i=0;i<=4;i++){
            printf("%d.使用",i+3);
            cout<<daojuname[i]<<'\n';
        }
        scanf("%d",&x);
        if(1<=x&&x<=7){
            break;
        }
        printf("输入不合法\n");
        Sleep(1145);
        system("cls");
    }
    if(x==1){
        printf("玩家B决定向玩家A开枪");
        T++;
        wait();
        if(q[qlen]==2){
            Yourmoney+=(double)(2000.0*(Hurt*1.0)*(1+(double)(shi)*1.0/(double)(shi+kong)));
            kong--;
            qlen--;
            Hurt=1;
            printf("是空弹\n");
            if(shoukaoemo==1){
                shoukaoemo=0;
                printf("因为玩家B使用了手铐,所以可以再来一次\n");
                Sleep(500);
                T--;
            }
        }else{
            Yourmoney+=(double)(5000.0*(Hurt*1.0)*(1+(double)(kong)*1.0/(double)(shi+kong)));
            shi--;
            qlen--;
            Your-=Hurt;
            printf("是实弹\n");
            printf("造成了%d点伤害\n",Hurt);
            Hurt=1;
            Sleep(500);
            IsOver_duo();
            if(shoukaoemo==1){
                shoukaoemo=0;
                Yourmoney+=1000.0;
                printf("因为玩家B使用了手铐,所以可以再来一次\n");
                Sleep(500);
                T--;
            }
        }
    }else if(x==2){
        printf("玩家B决定向自己开枪");
        wait();
        if(q[qlen]==2){
            Yourmoney+=(double)(2000.0*(Hurt*1.0)*(1+(double)(kong)*1.0/(double)(shi+kong)));
            kong--;
            qlen--;
            Hurt=1;
            printf("是空弹\n");
        }else{
            Yourmoney+=5000.0*(1+(double)(shi)*1.0/(double)(shi+kong));
            T++;
            shi--;
            qlen--;
            Other-=Hurt;
            printf("是实弹\n");
            printf("造成了%d点伤害\n",Hurt);
            Hurt=1;
            Sleep(500);
            IsOver_duo();
            if(shoukao_you==1){
                shoukao_you=0;
                printf("因为玩家B使用了手铐,所以可以再来一次\n");
                Sleep(500);
                T--;
            }
        }
    }else if(x==3){
        if(daoju1[0]){
            daoju1[0]--;
            daojulen1--;
            printf("玩家B使用了放大镜\n");
            wait();
            printf("\n玩家B看到了");
            if(q[qlen]==1){
                printf("实弹\n");
                Yourmoney+=2500.0;
            }else{
                printf("空弹\n");
            }
            Sleep(500);
            printf("\n");
        }else{
            printf("玩家B现在没有放大镜\n");
            Sleep(1145);
            system("cls");
        }
    }else if(x==4){
        if(daoju1[1]){
            if(!shoukaoemo){
                daoju1[1]--;
                daojulen1--;
                printf("玩家B使用了手铐\n");
                printf("玩家B获得了连开两枪的机会\n");
                shoukaoemo=1;
            }else{
                printf("玩家B已经用过手铐了\n");
            }
            Sleep(1145);
            system("cls"); 
        }else{
            printf("玩家B现在没有手铐\n");
            Sleep(1145);
            system("cls");
        }
    }else if(x==5){
        if(daoju1[2]){
            daoju1[2]--;
            daojulen1--;
            printf("玩家B使用了小刀\n");
            printf("若下一发为实弹则伤害翻倍\n");
            Yourmoney+=500.0;
            Hurt*=2;
            Sleep(1145);
            system("cls");
        }else{
            printf("玩家B现在没有小刀\n");
            Sleep(1145);
            system("cls");
        }
    }else if(x==6){
        if(daoju1[3]){
            if(Other^4){
                daoju1[3]--;
                daojulen1--;
                printf("玩家B使用了烟\n");
                printf("玩家B回复了一点生命\n");
                Yourmoney+=500.0;
                Other++;
            }else{
                printf("玩家B现在不需要烟\n");
            }
            Sleep(1145);
        }else{
            printf("玩家B现在没有烟\n");
            Sleep(1145);
            system("cls");
        }
    }else{
        if(daoju1[4]){
            daoju1[4]--;
            daojulen1--;
            printf("玩家B使用了饮料\n");
            wait();
            printf("\n");
            printf("玩家B退了一发"); 
            if(q[qlen]==2){
                printf("空弹");
                kong--;
            }else{
                printf("实弹");
                Yourmoney+=500.0;
                shi--;
            }
            qlen--;
            Sleep(500);
        }else{
            printf("玩家B现在没有饮料\n");
            Sleep(1145);
            system("cls");
        }
    }
    Sleep(1000);
    system("cls");
}
int asdasd;
void duorenplay(){
    while(1){
        if(shi==0){
            build_gun_duo();
            T=asdasd;
            asdasd++;
            continue;
        }
        if(T%2==0){
            Timeyou_duo();
        }else{
            Timeother_duo();
        }
    }
}
int game_2(){
    srand(time(0));
    int x;
    while(1){
        printf("请选择你想要的模式:\n1.单人\n2.双人(此模式中,生命值为4,道具补给为2)\n");
        scanf("%d",&x);
        if(x==1||x==2){
            break;
        }
        printf("输入不合法\n");
        Sleep(1145);
        system("cls");
    }
    system("cls");
    if(x==1){
        danrenplay();
    }else{
        Your=Other=4;
        duorenplay();
    }
    return 0;
}
void init() {
    for(int i = 0; i < 3; i++)
        for(int j = 0; j < 3; j++)
            board[i][j] = ' ';
}

void printBoard() {
	cout << "  0   1   2 " << endl; 
	cout << "  -----------" << endl;
    for (int i = 0; i < 3; i++) {
        cout << i << "| " << board[i][0] << " | " << board[i][1] << " | " << board[i][2] << " |" << endl;
        if (i < 2) cout << " |---|---|---|" << endl;
    }
    cout << "  -----------" << endl;
}

bool checkWin(char player) {
    for (int i = 0; i < 3; i++) {
        if ((board[i][0] == player && board[i][1] == player && board[i][2] == player) || 
            (board[0][i] == player && board[1][i] == player && board[2][i] == player))
            return true;
    }
    if ((board[0][0] == player && board[1][1] == player && board[2][2] == player) || 
        (board[0][2] == player && board[1][1] == player && board[2][0] == player))
        return true;
    return false;
}

bool isBoardFull() {
    for (int i = 0; i < 3; i++)
        for (int j = 0; j < 3; j++)
            if (board[i][j] == ' ')
                return false;
    return true;
}

int playerMove() {
    int x, y, count = 10;
    cout << "请输入行和列(0-2),输入9 9退出: ";
    cin >> x;
	cin >> y;
	if(x == 9 && y == 9) return_1 = true;
    while (x < 0 || x > 2 || y < 0 || y > 2 || board[x][y] != ' ') {
        cout << "无效的位置,请重新输入:";
        cin >> x >> y;
    }
    board[x][y] = 'O';
}
int aiMove() {
    srand(static_cast<unsigned int>(time(NULL)));
    int x, y;
    for(int i = 0; i < 3; i ++) {
    	for(int j = 0; j < 3; j ++) {
    		if(board[i][j] == ' ') {
    			board[i][j] = 'X';
				if(checkWin('X')) {
					return 0;
				}
				board[i][j] = ' ';
			}
		}
	}
	for(int i = 0; i < 3; i ++) {
    	for(int j = 0; j < 3; j ++) {
    		if(board[i][j] == ' ') {
    			board[i][j] = 'O';
				if(checkWin('O')) {
					board[i][j] = 'X';
					return 0;
				}
				board[i][j] = ' ';
			}
		}
	}
    do {
        x = rand() % 3;
        y = rand() % 3;
    } while (board[x][y] != ' ');
    board[x][y] = 'X';
}

int game_1() {
    init();
    
    cout << "欢迎来到井字棋系统2.0版本,(你是O,AI是X) " << endl;
	#ifdef _WIN32
        system("cls");
    #else
        system("clear");
    #endif
	int choose = 1;
	//cin >> choose;
    if(choose >= 0) {
    	while (1) {
    		
        	printBoard();
    	    playerMove();
    	    if(return_1 == true) {
    	    	break;
			}
      		if (checkWin('O')) {
            	printBoard();
            	cout << "玩家胜利!" << endl;
            	break;
        	}
    	    if (isBoardFull()) {
        	    printBoard();
	            cout << "平局!" << endl;
    	        break;
        	}
        	aiMove();
        	if (checkWin('X')) {
    	        printBoard();
	            cout << "人工智能胜利!" << endl;
            	break;
        	}
    	    if (isBoardFull()) {
	            printBoard();
            	cout << "平局!" << endl;
        	    break;
    	    }
    	    #ifdef _WIN32
                system("cls");
            #else
                system("clear");
            #endif
	    }
	}
    return 0;
}
void terminal() {
    std::string command;
    
    std::cout << "简单的 C++ 终端模拟器" << std::endl;
    std::cout << "输入 'exit' 退出。" << std::endl;
    
    while (true) {
        std::cout << "> ";
        std::getline(std::cin, command);
        if (command == "exit") {
            break;
        }
        int result = system(command.c_str());
        if (result == -1) {
            std::cerr << "执行命令时发生错误。" << std::endl;
            #ifdef _WIN32
                Sleep(1000);
            #else
                usleep(1000000);
            #endif
        }
    }
    
    std::cout << "正在退出终端。" << std::endl;
}

enum Token {
    NUMBER, PLUS, MINUS, MULTIPLY, DIVIDE, MOD, POWER, LPAREN, RPAREN, FUNCTION, END, INVALID
};
void play_system_sound(const std::string& sound_name) {
    std::string command = "afplay /System/Library/Sounds/" + sound_name;
    system(command.c_str());
}

struct TokenValue {
    Token type;
    double value;
    std::string funcName;

    TokenValue(Token t) : type(t), value(0), funcName("") {}
    TokenValue(Token t, double v) : type(t), value(v), funcName("") {}
    TokenValue(Token t, double v, const std::string& f) : type(t), value(v), funcName(f) {}
};
class Lexer {
public:
    Lexer(const std::string& text) : text(text), index(0) {}

    TokenValue getNextToken() {
        while (index < text.length()) {
            if (std::isspace(text[index])) {
                ++index;
                continue;
            }
            if (std::isdigit(text[index]) || text[index] == '.') {
                return TokenValue(NUMBER, getNumber());
            }
            if (std::isalpha(text[index])) {
                return getFunction();
            }
            switch (text[index]) {
                case '+': ++index; return TokenValue(PLUS);
                case '-': ++index; return TokenValue(MINUS);
                case '*': ++index; return TokenValue(MULTIPLY);
                case '/': ++index; return TokenValue(DIVIDE);
                case '%': ++index; return TokenValue(MOD);
                case '^': ++index; return TokenValue(POWER);
                case '(': ++index; return TokenValue(LPAREN);
                case ')': ++index; return TokenValue(RPAREN);
                case '!': ++index; return TokenValue(FUNCTION, 0, "factorial");
                default: return TokenValue(INVALID);
            }
        }
        return TokenValue(END);
    }

private:
    double getNumber() {
        double value = 0;
        bool decimalPoint = false;
        double decimalFactor = 1;
        if (text[index] == '-') {
            ++index;
        }
        while (index < text.length() && (std::isdigit(text[index]) || text[index] == '.')) {
            if (text[index] == '.') {
                if (decimalPoint) {
                    throw std::runtime_error("无效的数字格式");
                }
                decimalPoint = true;
            } else {
                value = value * 10 + (text[index] - '0');
                if (decimalPoint) {
                    decimalFactor *= 10;
                }
            }
            ++index;
        }
        value /= decimalFactor;
        return value;
    }

    TokenValue getFunction() {
        std::string funcName;
        while (index < text.length() && std::isalpha(text[index])) {
            funcName += text[index++];
        }
        if (funcName == "sin" || funcName == "cos" || funcName == "tan" ||
            funcName == "cot" || funcName == "csc" || funcName == "sec" ||
            funcName == "asin" || funcName == "acos" || funcName == "atan" ||
            funcName == "sinh" || funcName == "cosh" || funcName == "tanh" ||
            funcName == "coth" || funcName == "csch" || funcName == "sech" ||
            funcName == "log" || funcName == "log10" || funcName == "exp" ||
            funcName == "abs") {
            return TokenValue(FUNCTION, 0, funcName);
        }
        return TokenValue(INVALID);
    }

    std::string text;
    size_t index;
};
class Parser {
public:
    Parser(Lexer& lexer) : lexer(lexer), currentToken(lexer.getNextToken()) {}

    double parse() {
        double result = expr();
        if (currentToken.type != END) {
            throw std::runtime_error("语法错误:表达式后出现意外的符号");
        }
        return result;
    }

private:
    void eat(Token token) {
        if (currentToken.type == token) {
            currentToken = lexer.getNextToken();
        } else {
            throw std::runtime_error("语法错误:意外的符号");
        }
    }

    double expr() {
        double result = term();
        while (currentToken.type == PLUS || currentToken.type == MINUS) {
            if (currentToken.type == PLUS) {
                eat(PLUS);
                result += term();
            } else if (currentToken.type == MINUS) {
                eat(MINUS);
                result -= term();
            }
        }
        return result;
    }

    double term() {
        double result = factor();
        while (currentToken.type == MULTIPLY || currentToken.type == DIVIDE || currentToken.type == MOD) {
            if (currentToken.type == MULTIPLY) {
                eat(MULTIPLY);
                result *= factor();
            } else if (currentToken.type == DIVIDE) {
                eat(DIVIDE);
                double divisor = factor();
                if (divisor == 0) {
                    throw std::runtime_error("错误:除以零");
                }
                result /= divisor;
            } else if (currentToken.type == MOD) {
                eat(MOD);
                double divisor = factor();
                if (divisor == 0 || is_zhengshu(divisor) == 1 || is_zhengshu(result) == 1) {
                    throw std::runtime_error("错误:除以零或不是整数");
                }
            	result = (int(result)) % ((int)(divisor));
            } 
        }
        return result;
    }

    double factor() {
        double result;
        if (currentToken.type == NUMBER) {
            result = currentToken.value;
            eat(NUMBER);
        } else if (currentToken.type == FUNCTION) {
            std::string funcName = currentToken.funcName;
            eat(FUNCTION);
            if (funcName == "factorial") {
                result = factorial(expr());
            } else {
                eat(LPAREN);
                result = expr();
                eat(RPAREN);
                result = applyFunction(funcName, result);
            }
        } else if (currentToken.type == LPAREN) {
            eat(LPAREN);
            result = expr();
            eat(RPAREN);
        } else {
            throw std::runtime_error("语法错误:意外的符号");
        }
        while (currentToken.type == POWER) {
            eat(POWER);
            result = std::pow(result, factor());
        }
        return result;
    }

    double applyFunction(const std::string& funcName, double value) {
        if (funcName == "sin") {
            return std::sin(value);
        } else if (funcName == "cos") {
            return std::cos(value);
        } else if (funcName == "tan") {
            return std::tan(value);
        } else if (funcName == "cot") {
            return 1.0 / std::tan(value);
        } else if (funcName == "csc") {
            return 1.0 / std::sin(value);
        } else if (funcName == "sec") {
            return 1.0 / std::cos(value);
        } else if (funcName == "asin") {
            if (value < -1 || value > 1) {
                throw std::runtime_error("域错误:asin 函数参数超出范围");
            }
            return std::asin(value);
        } else if (funcName == "acos") {
            if (value < -1 || value > 1) {
                throw std::runtime_error("域错误:acos 函数参数超出范围");
            }
            return std::acos(value);
        } else if (funcName == "atan") {
            return std::atan(value);
        } else if (funcName == "sinh") {
            return std::sinh(value);
        } else if (funcName == "cosh") {
            return std::cosh(value);
        } else if (funcName == "tanh") {
            return std::tanh(value);
        } else if (funcName == "coth") {
            double sinhValue = std::sinh(value);
            if (sinhValue == 0) {
                throw std::runtime_error("错误:coth 函数除以零");
            }
            return 1.0 / sinhValue;
        } else if (funcName == "csch") {
            double sinhValue = std::sinh(value);
            if (sinhValue == 0) {
                throw std::runtime_error("错误:csch 函数除以零");
            }
            return 1.0 / sinhValue;
        } else if (funcName == "sech") {
            double coshValue = std::cosh(value);
            if (coshValue == 0) {
                throw std::runtime_error("错误:sech 函数除以零");
            }
            return 1.0 / coshValue;
        } else if (funcName == "log") {
            return std::log(value);
        } else if (funcName == "log10") {
            return std::log10(value);
        } else if (funcName == "exp") {
            return std::exp(value);
        } else if (funcName == "abs") {
            return std::fabs(value);
        } else {
            throw std::runtime_error("未知函数:" + funcName);
        }
    }

    double factorial(double value) {
        if (value < 0 || value != std::floor(value)) {
            throw std::runtime_error("错误:非整数或负数的阶乘");
        }
        double result = 1;
        for (int i = 1; i <= static_cast<int>(value); ++i) {
            result *= i;
        }
        return result;
    }

    Lexer& lexer;
    TokenValue currentToken;
};
void saveCredentials(const std::string& username, const std::string& password) {
    std::ofstream file(CREDENTIALS_FILE);
    if (file.is_open()) {
        file << username << '\n' << password;
        file.close();
    } else {
        throw std::runtime_error("无法保存凭据");
    }
}
std::pair<std::string, std::string> loadCredentials() {
    std::ifstream file(CREDENTIALS_FILE);
    if (!file.is_open()) {
        throw std::runtime_error("无法读取凭据文件");
    }
    std::string username, password;
    std::getline(file, username);
    std::getline(file, password);
    return std::pair<std::string, std::string>(username, password);
}
bool authenticate() {
    std::string username, password;
    std::cout << "请输入用户名: ";
    std::cin >> username;
    std::cout << "请输入密码: ";
    std::cin >> password;

    try {
        std::pair<std::string, std::string> credentials = loadCredentials();
        if (credentials.first == username && credentials.second == password) {
            #ifdef _WIN32
            system("cls");
        #else
            system("clear");
        #endif
            return true;
        } else {
            return false;
        }
    } catch (const std::runtime_error&) {
        std::cout << "凭据文件不存在,设置新的凭据。\n";
        saveCredentials(username, password);
        return true;
    }
}
void runCalculator() {
    std::string input;
    while (true) {
        std::cout << "请输入表达式(输入 'exit' 退出):";
        std::getline(std::cin, input);
        if (input == "exit") {
            break;
        }
        Lexer lexer(input);
        Parser parser(lexer);
        try {
            double result = parser.parse();
            std::cout << "结果:" << result << std::endl;
            #ifdef _WIN32
                Sleep(1000);
            #else
                usleep(1000000);
            #endif
        } catch (const std::runtime_error& e) {
            std::cerr << "错误:" << e.what() << std::endl;
            #ifdef _WIN32
                Sleep(1000);
            #else
                usleep(1000000);
            #endif
            #ifdef _WIN32
                system("cls");
            #else
                system("clear");
            #endif
        }
    }
}
void Calculator() {
	std::string choice;
    while (true) {
        #ifdef _WIN32
            system("cls");
        #else
            system("clear");
        #endif
        std::cout << "请选择操作:\n1. 计算\n2. 解方程\n3.退出\n";
        std::getline(std::cin, choice);

        if (choice == "1") {
            runCalculator();
        } else if (choice == "2") {
//            runSolute();
        } else if (choice == "3") {
            break;
        } else {
            std::cerr << "无效的选择。请重试。\n";
            #ifdef _WIN32
				Sleep(1000); 
			#else
				usleep(1000000);
			#endif
        }
    } 
} 



void createDocument() {
    std::string fileName;
    std::cout << "请输入新文档的名称(包括文件扩展名,如 'document.txt'):";
    std::getline(std::cin, fileName);
	char *c = (char*)fileName.data(); 
    std::ofstream file(c);
    if (file.is_open()) {
        std::cout << "文档已创建。\n";
        file.close();
    } else {
        std::cerr << "创建文档时出错。\n";
    }
}

void deleteDocument() {
    std::string fileName;
    std::cout << "请输入要删除的文档名称(包括文件扩展名):";
    std::getline(std::cin, fileName);
    if (std::remove(fileName.c_str()) == 0) {
        std::cout << "文档已删除。\n";
    } else {
        std::cerr << "删除文档时出错。请确保文件存在。\n";
    }
}

void editDocument() {
    std::string fileName;
    std::cout << "请输入要编辑的文档名称(包括文件扩展名):";
    std::getline(std::cin, fileName);
    char *c = (char*)fileName.data();
    std::ofstream file(c);
    if (file.is_open()) {
        std::string line;
        std::cout << "请输入要添加的文本(输入 'exit' 以结束编辑):\n";
        while (true) {
            std::getline(std::cin, line);
            if (line == "exit") {
                break;
            }
            file << line << std::endl;
        }
        file.close();
        std::cout << "文档已更新。\n";
        Sleep(1000);
    } else {
        std::cerr << "打开文档时出错。\n";
    }
}

void openDocument() {
//    std::string fileName;
//    std::cout << "请输入要打开的文档名称(包括文件扩展名):";
//    std::getline(std::cin, fileName);
//    char *c = (char*)fileName.data();
//    std::ofstream file(c);
//    if (file.is_open()) {
//        std::string line;
//        std::cout << "文档内容:\n";
//        while (std::getline(cin, line)) {
//            std::cout << line << std::endl;
//        }
//        file.close();
//    } else {
//        std::cerr << "打开文档时出错。请确保文件存在。\n";
//    }
}

void useWordProcessor() {
    std::string choice;
    while (true) {
        #ifdef _WIN32
            system("cls");
        #else
            system("clear");
        #endif
        std::cout << "文字处理器\n";
        std::cout << "请选择操作:\n";
        std::cout << "1. 新建文档\n";
        std::cout << "2. 删除文档\n";
        std::cout << "3. 编辑文档\n";
        std::cout << "4. 打开文档\n";
        std::cout << "5. 退出\n";
        std::getline(std::cin, choice);
        
        if (choice == "1") {
            createDocument();
        } else if (choice == "2") {
            deleteDocument();
        } else if (choice == "3") {
            editDocument();
        } else if (choice == "4") {
            openDocument();
        } else if (choice == "5") {
            break;
        } else {
            std::cerr << "无效的选择。请重试。\n";
            #ifdef _WIN32
                Sleep(1000);
            #else
                usleep(1000000);
            #endif 
        }
    }
}
void displayTime() {
time_t t = time(NULL);
    tm* localTime = localtime(&t);
    std::cout << "当前时间: "
              << (localTime->tm_year + 1900) << "-"
              << (localTime->tm_mon + 1) << "-"
              << localTime->tm_mday << " "
              << localTime->tm_hour << ":"
              << localTime->tm_min << ":"
              << localTime->tm_sec << std::endl;
	#ifdef _WIN32
        Sleep(1000);
    #else
        usleep(1000000);
    #endif
}
void displaytime(int seconds) {
    int remainingSeconds = seconds % 60;
    int hours=seconds / 3600;
    int minutes = (seconds - 3600 * hours) / 60;

    std::cout << "\r剩余时间: " << std::setw(2) << std::setfill('0') << hours 
              << ":"<< std::setw(2) << std::setfill('0') << minutes 
              << ":" << std::setw(2) << std::setfill('0') << remainingSeconds 
              << std::flush;
}

void downtime() {
    int countdownTime;
    std::cout << "请输入倒计时时间(秒):";
    std::cin >> countdownTime;
    while(countdownTime <= 0)
    {
        std::cerr << "输入时间无效。请输入一个正整数。" << std::endl;
        std::cin >> countdownTime;
    }

    while (countdownTime > 0) {
        displaytime(countdownTime);
        #ifdef _WIN32
            Sleep(1000);
        #else
            usleep(1000000);
        #endif
        --countdownTime;
        
    }

    std::cout << "\n时间到!" << std::endl;
    std::string sound_name = "Submarine.aiff"; 
    play_system_sound(sound_name);
}
void Time() {
    std::string choice;
    while (true) {
        #ifdef _WIN32
            system("cls");
        #else
            system("clear");
        #endif
        std::cout << "请选择操作:\n1. 计时\n2. 当前时间\n3. 退出\n";
        std::getline(std::cin, choice);
        if (choice == "1") {
            downtime();
        } else if (choice == "2") {
            displayTime();
        } else if (choice == "3") {
            break;
        } else {
            std::cerr << "无效的选择。请重试。\n";
            #ifdef _WIN32
                Sleep(1000);
            #else
                usleep(1000000);
            #endif
        }
    }
}

int main() {
    if (!authenticate()) {
        std::cerr << "认证失败。\n";
        return 1;
    }

    std::string choice;
    while (true) {
        #ifdef _WIN32
            system("cls");
        #else
            system("clear");
        #endif
        std::cout << "请选择操作:\n1. 计算器\n2. 文字处理器\n3. 时钟\n4. 终端\n5. 游戏\n6.退出\n";
        std::getline(std::cin, choice);

        if (choice == "1") {
            runCalculator();
        } else if (choice == "2") {
            useWordProcessor();
        } else if (choice == "3") {
            Time();
        } else if (choice == "4") {
            terminal();
        } else if (choice == "5") {
            game_2();
        } else if (choice == "6") {
            break;
        } else {
            std::cerr << "无效的选择。请重试。\n";
            #ifdef _WIN32
                Sleep(1000);
            #else
                usleep(1000000);
            #endif
        }
    } 

    return 0;
}

原文