• 个人简介

    《Charter of the United Nations》

    We the Peoples of the United Nations determined to save succeeding generations from the scourge of war, which twice in our lifetime has brought untold sorrow to mankind, and to reaffirm faith in fundamental human rights, in the dignity and worth of the human person, in the equal rights of men and women and of nations large and small, and to establish conditions under which justice and respect for the obligations arising from treaties and other sources of international law can be maintained, and to promote social progress and better standards of life in larger freedom, and for these ends to practice tolerance and live together in peace with one another as good neighbours, and to unite our strength to maintain international peace and security, and to ensure, by the acceptance of principles and the institution of methods, that armed force shall not be used, save in the common interest, and to employ international machinery for the promotion of the economic and social advancement of all peoples, have resolved to combine our efforts to accomplish these aims.

    《联合国宪章》

    我联合国人民同兹决心,欲免后世再遭今代人类两度身历惨不堪言之战祸,重申基本人权、人格尊严与价值,以及男女与大小各国平等权利之信念,创造适当环境,俾克维持正义,尊重由条约与国际法其他渊源而起之义务,久而弗懈,促成大自由中之社会进步及较善之民生,并为达此目的,力行容恕,彼此以善邻之道,和睦相处,集中力量,以维持国际和平及安全,接受原则,确立方法,以保证非为公共利益,不得使用武力,运用国际机构,以促成全球人民经济及社会之进展,用是发愤立志,务当同心协力,以竟厥功。

    #include<bits/stdc++.h> #include<windows.h> #include<conio.h> #include using namespace std;

    const int game_day=0, game_task=1, game_meeting=2, game_siege=3; int round_num=0, current_phase=game_day; int player_count, my_id; HWND hwnd=GetForegroundWindow();

    const int blue=0,yellow=1,red=2,green=3,purple=4,white=5,cyan=6,orange=7;

    const int crewmate=0, impostor=1, engineer=2, medic=3, detective=4; const int technician=5, watcher=6, spy=7; const int tracker=8, bomber=9, cleaner=10, seer=11; const int alive=0, dead=1, ejected=2;

    const int room_engine=0, room_electric=1, room_security=2, room_medbay=3, room_storage=4; const int room_count=5; bool room_destroyed[room_count]={false}; int current_room=-1;

    int impostor_count=0;
    int engineer_id=-1, medic_id=-1, detective_id=-1; int technician_id=-1, watcher_id=-1, spy_id=-1; int tracker_id=-1, bomber_id=-1, cleaner_id=-1, seer_id=-1; int impostor_ids[5]={-1,-1,-1,-1,-1}; int ejected_player=-1;
    int killed_player=-1;
    int shielded_player=-1;
    int repaired_task=-1;
    bool security_camera_active=false; bool bomb_planted=false; int bomb_room=-1; int bomb_timer=2; int cleaned_body=-1;

    void color(int c){ HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); switch(c){ case red:SetConsoleTextAttribute(hConsole, FOREGROUND_INTENSITY | FOREGROUND_RED);break; case green:SetConsoleTextAttribute(hConsole, FOREGROUND_INTENSITY | FOREGROUND_GREEN);break; case yellow:SetConsoleTextAttribute(hConsole, FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_GREEN);break; case blue:SetConsoleTextAttribute(hConsole, FOREGROUND_INTENSITY | FOREGROUND_BLUE);break; case white:SetConsoleTextAttribute(hConsole, FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_GREEN | FOREGROUND_BLUE);break; case purple:SetConsoleTextAttribute(hConsole, FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_BLUE);break; case cyan:SetConsoleTextAttribute(hConsole, FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_BLUE);break; case orange:SetConsoleTextAttribute(hConsole, FOREGROUND_INTENSITY | FOREGROUND_RED | (FOREGROUND_GREEN/2));break; } }

    void gotoxy(int x,int y){ COORD position; position.X=x; position.Y=y; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), position); }

    void init_window(){ system("mode con lines=60 cols=188"); ShowWindow(hwnd,SW_MAXIMIZE); DeleteMenu(GetSystemMenu(GetConsoleWindow(), FALSE), SC_CLOSE, MF_BYCOMMAND); DrawMenuBar(GetConsoleWindow()); }

    class Player{ public: int role;
    int status;
    int task_progress; int kill_count;
    bool is_visible;
    int current_room; int camera_time; int track_target; int seer_cooldown;

    Player(){ role=-1; status=alive; task_progress=0; kill_count=0; is_visible=false; current_room=0; camera_time=0; track_target=-1; seer_cooldown=0; }

    int get_status(){ return status; } };

    Player players[15];

    bool is_include(int arr[], int val, int len){ for(int i=0;i<len;i++){ if(arr[i]==val) return true; } return false; }

    bool typing_task(){ color(cyan); cout << "\n=== 精准打字任务 ===" << endl; string texts[] = { "repair the electrical system", "check the engine temperature", "calibrate the navigation system", "analyze the oxygen level", "verify the security protocol" };

    string target = texts[rand()%5]; cout << "请准确输入以下内容:" << target << endl; cout << "输入:";

    string input; cin >> ws; getline(cin, input);

    if(input == target){ color(green); cout << "输入正确!任务完成!" << endl; return true; }else{ color(red); cout << "输入错误!任务失败!正确内容:" << target << endl; return false; } }

    string get_room_name(int room_id){ switch(room_id){ case room_engine: return "引擎室"; case room_electric: return "电力室"; case room_security: return "监控室"; case room_medbay: return "医疗室"; case room_storage: return "储藏室"; default: return "未知区域"; } }

    void init_players(){ my_id=rand()%player_count;

    if(player_count<=6) impostor_count=1; else if(player_count<=10) impostor_count=2; else if(player_count<=15) impostor_count=3;

    for(int i=0;i<player_count;i++){ players[i].status=alive; players[i].task_progress=0; players[i].kill_count=0; players[i].is_visible=false; players[i].role=-1; players[i].current_room=rand()%room_count; players[i].camera_time=0; players[i].track_target=-1; players[i].seer_cooldown=0; }

    for(int i=0;i<impostor_count;i++){ int p=rand()%player_count; if(!is_include(impostor_ids, p, 5)){ impostor_ids[i]=p; players[p].role=impostor; }else{ i--; } Sleep(rand()%80+100); }

    if(player_count>=10 && impostor_count>=2){ do{ bomber_id=rand()%player_count; }while(players[bomber_id].role!=-1); players[bomber_id].role=bomber; impostor_ids[impostor_count++] = bomber_id; }

    if(player_count>=12 && impostor_count>=2){ do{ cleaner_id=rand()%player_count; }while(players[cleaner_id].role!=-1); players[cleaner_id].role=cleaner; impostor_ids[impostor_count++] = cleaner_id; }

    do{ engineer_id=rand()%player_count; }while(players[engineer_id].role!=-1); players[engineer_id].role=engineer;

    if(player_count>=8){ do{ medic_id=rand()%player_count; }while(players[medic_id].role!=-1); players[medic_id].role=medic; }

    if(player_count>=10){ do{ detective_id=rand()%player_count; }while(players[detective_id].role!=-1); players[detective_id].role=detective; }

    if(player_count>=9){ do{ technician_id=rand()%player_count; }while(players[technician_id].role!=-1); players[technician_id].role=technician; }

    if(player_count>=11){ do{ watcher_id=rand()%player_count; }while(players[watcher_id].role!=-1); players[watcher_id].role=watcher; }

    if(player_count>=13 && impostor_count>=3){ do{ spy_id=rand()%player_count; }while(players[spy_id].role!=-1); players[spy_id].role=spy; impostor_ids[impostor_count++] = spy_id; }

    if(player_count>=8){ do{ tracker_id=rand()%player_count; }while(players[tracker_id].role!=-1); players[tracker_id].role=tracker; }

    if(player_count>=11){ do{ seer_id=rand()%player_count; }while(players[seer_id].role!=-1); players[seer_id].role=seer; }

    for(int i=0;i<player_count;i++){ if(players[i].role==-1){ players[i].role=crewmate; } }

    players[my_id].is_visible=true; if(players[my_id].roleimpostor || players[my_id].rolespy || players[my_id].rolebomber || players[my_id].rolecleaner){ for(int i=0;i<impostor_count;i++){ players[impostor_ids[i]].is_visible=true; } } }

    void print_game(){ gotoxy(0,0); cout<<"太空杀 | 新增角色+房间系统+精准打字任务";

    gotoxy(90,0); if(current_phasegame_meeting) color(red); else if(current_phasegame_task) color(cyan); else if(current_phase==game_siege) color(orange); else color(blue);

    printf("第%d回合 | ",round_num); if(current_phasegame_day) cout<<"日常阶段"; else if(current_phasegame_task) cout<<"任务阶段"; else if(current_phase==game_meeting) cout<<"紧急会议"; else cout<<"破坏阶段";

    gotoxy(130,0); if(bomb_planted){ color(red); cout<<"【炸弹警告】"<<get_room_name(bomb_room)<<" 剩余"<<bomb_timer<<"回合爆炸!"; }

    gotoxy(0,3); color(blue); cout<<" 我的编号:"<<my_id+1; cout<<" | 当前房间:"<<get_room_name(players[my_id].current_room);

    gotoxy(60,3); color(yellow); cout<<"=== 区域状态 ==="; for(int i=0;i<room_count;i++){ gotoxy(60,4+i); if(room_destroyed[i]){ color(red); cout<<get_room_name(i)<<": 已破坏"; }else{ color(green); cout<<get_room_name(i)<<": 正常"; } }

    for(int i=0;i<player_count;i++){ gotoxy(i*12+1,10); color(blue); cout<<i+1<<"号";

    gotoxy(i*12+1,11);
    if(players[i].get_status()==dead){
        color(red);
        cout<<"已死亡";
    }else if(players[i].get_status()==ejected){
        color(yellow);
        cout<<"被驱逐";
    }else{
        color(green);
        cout<<"存活中";
    }
    
    gotoxy(i*12+1,12);
    color(cyan);
    cout<<"房间:"<<get_room_name(players[i].current_room);
    
    gotoxy(i*12+1,13);
    color(blue);
    if(players[i].is_visible){
        switch(players[i].role){
            case crewmate: cout<<"船员";break;
            case impostor: cout<<"内鬼";break;
            case engineer: cout<<"工程师";break;
            case medic: cout<<"医生";break;
            case detective: cout<<"侦探";break;
            case technician: cout<<"技术员";break;
            case watcher: cout<<"守望者";break;
            case spy: cout<<"间谍(内鬼)";break;
            case tracker: cout<<"追踪者";break;
            case bomber: cout<<"爆破手(内鬼)";break;
            case cleaner: cout<<"清洁工(内鬼)";break;
            case seer: cout<<"预言家";break;
        }
    }else{
        cout<<"未知";
    }
    
    if(players[i].role!=impostor && players[i].role!=spy && players[i].role!=bomber && 
       players[i].role!=cleaner && players[i].get_status()==alive){
        gotoxy(i*12+1,14);
        color(white);
        cout<<"任务:"<<players[i].task_progress<<"%";
    }
    

    }

    gotoxy(0, 20); color(purple); cout<<"=== 监控系统 ="; if(security_camera_active){ cout<<" [已开启]"; color(white); cout<<"\n监控可见玩家位置:"; for(int i=0;i<player_count;i++){ if(players[i].statusalive){ cout<<i+1<<"号("<<get_room_name(players[i].current_room)<<") "; } } }else{ cout<<" [已关闭]"; }

    if(players[my_id].roletracker && players[my_id].track_target!=-1){ gotoxy(0,22); color(orange); cout<<"= 追踪信息 ==="; cout<<"\n你追踪的"<<players[my_id].track_target+1<<"号当前位置:" <<get_room_name(players[players[my_id].track_target].current_room); }

    gotoxy(0,28); color(white); cout<<"________________________"; }

    void impostor_destroy_room(){ color(red); cout<<"\n=== 内鬼破坏阶段 ==="<<endl; Sleep(1000);

    if(players[my_id].roleimpostor || players[my_id].rolespy || players[my_id].rolebomber || players[my_id].rolecleaner){ cout<<"选择要破坏的区域:"<<endl; for(int i=0;i<room_count;i++){ cout<<i+1<<". "<<get_room_name(i)<<" ("<<(room_destroyed[i]?"已破坏":"正常")<<")"<<endl; }

    int choice;
    cin>>choice;
    while(choice<1 || choice>room_count){
        color(yellow);
        cout<<"无效选择!重新输入:";
        cin>>choice;
    }
    choice--;
    
    if(!room_destroyed[choice]){
        room_destroyed[choice]=true;
        color(red);
        cout<<"你破坏了"<<get_room_name(choice)<<"!船员需要尽快修复!"<<endl;
        
        if(choice==room_engine || choice==room_electric){
            color(orange);
            cout<<get_room_name(choice)<<"被破坏!所有船员任务进度停止增长,直到修复!"<<endl;
        }
    }else{
        color(yellow);
        cout<<get_room_name(choice)<<"已经被破坏了!"<<endl;
    }
    

    }else{ int ai_choice; do{ ai_choice=rand()%room_count; }while(room_destroyed[ai_choice]);

    room_destroyed[ai_choice]=true;
    color(red);
    cout<<"内鬼破坏了"<<get_room_name(ai_choice)<<"!"<<endl;
    

    } Sleep(2000); }

    void bomber_plant_bomb(){ if(players[my_id].rolebomber && players[my_id].statusalive && !bomb_planted){ color(red); cout<<"\n=== 爆破手技能 ==="<<endl; cout<<"选择布置炸弹的区域:"<<endl; for(int i=0;i<room_count;i++){ cout<<i+1<<". "<<get_room_name(i)<<endl; }

    int choice;
    cin>>choice;
    while(choice<1 || choice>room_count){
        color(yellow);
        cout<<"无效选择!重新输入:";
        cin>>choice;
    }
    choice--;
    
    bomb_planted=true;
    bomb_room=choice;
    bomb_timer=2;
    color(red);
    cout<<"你在"<<get_room_name(choice)<<"布置了定时炸弹!2回合后爆炸!"<<endl;
    cout<<"船员需要拆除炸弹,否则该区域永久破坏且炸死区域内所有船员!"<<endl;
    

    }else if(bomb_planted && players[my_id].role==bomber){ color(yellow); cout<<"\n炸弹已布置!剩余"<<bomb_timer<<"回合爆炸!"<<endl; } Sleep(2000); }

    void defuse_bomb(){ if(!bomb_planted) return;

    color(orange); cout<<"\n=== 拆除炸弹 ==="<<endl; cout<<get_room_name(bomb_room)<<"发现炸弹!需要拆除!"<<endl; Sleep(1000);

    if(players[my_id].statusalive && players[my_id].current_roombomb_room && players[my_id].role!=impostor && players[my_id].role!=spy && players[my_id].role!=bomber && players[my_id].role!=cleaner){ cout<<"你在炸弹所在房间,是否尝试拆除?(1=是/2=否):"; int choice; cin>>choice;

    if(choice==1){
        color(cyan);
        cout<<"拆除炸弹需要完成精准打字任务!"<<endl;
        if(typing_task()){
            bomb_planted=false;
            bomb_room=-1;
            color(green);
            cout<<"炸弹拆除成功!"<<endl;
        }else{
            color(red);
            cout<<"拆除失败!炸弹继续倒计时!"<<endl;
        }
    }
    

    }

    for(int i=0;i<player_count;i++){ if(i!=my_id && players[i].statusalive && players[i].current_roombomb_room && players[i].role!=impostor && players[i].role!=spy && players[i].role!=bomber && players[i].role!=cleaner){ bool ai_success = (rand()%100)<60; if(players[i].roletechnician || players[i].roleengineer) ai_success=true;

        if(ai_success){
            bomb_planted=false;
            bomb_room=-1;
            color(green);
            cout<<i+1<<"号成功拆除了炸弹!"<<endl;
            break;
        }
    }
    

    } Sleep(1500); }

    void bomb_explode(){ if(!bomb_planted) return;

    bomb_timer--; if(bomb_timer<=0){ color(red); cout<<"\n=== 炸弹爆炸! ==="<<endl; cout<<get_room_name(bomb_room)<<"炸弹爆炸!该区域永久破坏!"<<endl; room_destroyed[bomb_room]=true;

    int kill_count=0;
    for(int i=0;i<player_count;i++){
        if(players[i].status==alive && players[i].current_room==bomb_room && 
           players[i].role!=impostor && players[i].role!=spy && 
           players[i].role!=bomber && players[i].role!=cleaner){
            players[i].status=dead;
            kill_count++;
            cout<<i+1<<"号在爆炸中死亡!"<<endl;
        }
    }
    
    if(kill_count>0){
        color(red);
        cout<<"共"<<kill_count<<"名船员在爆炸中死亡!"<<endl;
    }
    
    bomb_planted=false;
    bomb_room=-1;
    

    } Sleep(2000); }

    void cleaner_clean_body(){ if(killed_player==-1) return;

    if(players[my_id].rolecleaner && players[my_id].statusalive){ color(yellow); cout<<"\n=== 清洁工技能 ==="<<endl; cout<<"是否清理"<<killed_player+1<<"号的尸体?(1=是/2=否):"; int choice; cin>>choice;

    if(choice==1){
        cleaned_body=killed_player;
        color(red);
        cout<<"尸体清理成功!不会触发紧急会议!"<<endl;
        killed_player=-1;
    }
    

    }else if(cleaner_id!=-1 && players[cleaner_id].status==alive && killed_player!=-1){ cleaned_body=killed_player; color(red); cout<<"清洁工清理了"<<killed_player+1<<"号的尸体!"<<endl; killed_player=-1; } Sleep(1500); }

    void tracker_track_target(){ if(players[my_id].roletracker && players[my_id].statusalive){ color(orange); cout<<"\n=== 追踪者技能 ==="<<endl; cout<<"选择要追踪的玩家(可查看其位置):"<<endl;

    int target;
    cin>>target;
    while(target<1 || target>player_count){
        color(yellow);
        cout<<"无效目标!重新输入:";
        cin>>target;
    }
    target--;
    
    players[my_id].track_target=target;
    color(green);
    cout<<"你开始追踪"<<target+1<<"号!本回合可查看其位置!"<<endl;
    players[target].is_visible=true;
    

    } Sleep(1500); }

    void seer_check_role(){ if(players[my_id].roleseer && players[my_id].statusalive && players[my_id].seer_cooldown<=0){ color(purple); cout<<"\n=== 预言家技能 ==="<<endl; cout<<"选择要查验的玩家:"<<endl;

    int target;
    cin>>target;
    while(target<1 || target>player_count){
        color(yellow);
        cout<<"无效目标!重新输入:";
        cin>>target;
    }
    target--;
    
    bool error = (rand()%100)<10;
    color(white);
    cout<<"查验结果:";
    
    if(error){
        if(players[target].role==impostor || players[target].role==spy || 
           players[target].role==bomber || players[target].role==cleaner){
            color(green);
            cout<<target+1<<"号是船员(查验出错)!"<<endl;
        }else{
            color(red);
            cout<<target+1<<"号是内鬼(查验出错)!"<<endl;
        }
    }else{
        if(players[target].role==impostor || players[target].role==spy || 
           players[target].role==bomber || players[target].role==cleaner){
            color(red);
            cout<<target+1<<"号是内鬼!"<<endl;
            players[target].is_visible=true;
        }else{
            color(green);
            cout<<target+1<<"号是船员!"<<endl;
        }
    }
    
    players[my_id].seer_cooldown=2;
    

    }else if(players[my_id].role==seer && players[my_id].seer_cooldown>0){ color(yellow); cout<<"\n预言家技能冷却中!剩余"<<players[my_id].seer_cooldown<<"回合!"<<endl; players[my_id].seer_cooldown--; } Sleep(2000); }

    void repair_room(){ color(green); cout<<"\n=== 修复破坏区域 ==="<<endl; Sleep(1000);

    bool has_destroyed=false; for(int i=0;i<room_count;i++){ if(room_destroyed[i]){ has_destroyed=true; break; } }

    if(!has_destroyed){ cout<<"当前没有被破坏的区域!"<<endl; Sleep(1000); return; }

    if(players[my_id].status==alive && players[my_id].role!=impostor && players[my_id].role!=spy && players[my_id].role!=bomber && players[my_id].role!=cleaner){ cout<<"选择要修复的区域:"<<endl; for(int i=0;i<room_count;i++){ if(room_destroyed[i]){ cout<<i+1<<". "<<get_room_name(i)<<endl; } }

    int choice;
    cin>>choice;
    choice--;
    
    if(room_destroyed[choice]){
        bool success;
        if(players[my_id].role==technician){
            success=true;
        }else{
            success=typing_task();
        }
        
        if(success){
            room_destroyed[choice]=false;
            color(green);
            cout<<"你成功修复了"<<get_room_name(choice)<<"!"<<endl;
            
            if(players[my_id].role==technician){
                players[my_id].task_progress+=20;
                if(players[my_id].task_progress>100) players[my_id].task_progress=100;
                cout<<"技术员加成!任务进度+20%(当前:"<<players[my_id].task_progress<<"%)"<<endl;
            }
        }
    }else{
        color(yellow);
        cout<<"该区域未被破坏!"<<endl;
    }
    

    }

    for(int i=0;i<player_count;i++){ if(i!=my_id && players[i].statusalive && players[i].role!=impostor && players[i].role!=spy && players[i].role!=bomber && players[i].role!=cleaner){ for(int j=0;j<room_count;j++){ if(room_destroyed[j]){ bool ai_success = (rand()%100)<70; if(players[i].roletechnician) ai_success=true;

                if(ai_success){
                    room_destroyed[j]=false;
                    color(green);
                    cout<<i+1<<"号修复了"<<get_room_name(j)<<"!"<<endl;
                    break;
                }
            }
        }
    }
    

    } Sleep(2000); }

    void watcher_activate_camera(){ if(players[my_id].rolewatcher && players[my_id].statusalive){ color(purple); cout<<"\n=== 守望者技能 ==="<<endl; cout<<"是否开启监控室摄像头?(1=是/2=否):";

    int choice;
    cin>>choice;
    if(choice==1){
        security_camera_active=true;
        players[my_id].camera_time=3;
        color(green);
        cout<<"监控已开启!你可以看到所有玩家的位置(持续3回合)"<<endl;
    }else{
        cout<<"你选择不开启监控"<<endl;
    }
    

    } Sleep(1500); }

    int check_game_end(){ int alive_crew=0, alive_impostor=0; int completed_tasks=0; int total_crew=player_count-impostor_count;

    for(int i=0;i<player_count;i++){ if(players[i].get_status()alive){ if(players[i].roleimpostor || players[i].rolespy || players[i].rolebomber || players[i].role==cleaner) alive_impostor++; else alive_crew++; } if((players[i].role!=impostor && players[i].role!=spy && players[i].role!=bomber && players[i].role!=cleaner) && players[i].task_progress>=100){ completed_tasks++; } }

    bool all_destroyed=true; for(int i=0;i<room_count;i++){ if(!room_destroyed[i]){ all_destroyed=false; break; } } if(all_destroyed) return 1;

    if(alive_crew<=alive_impostor && alive_impostor>0) return 1; if(alive_impostor==0) return 2; if(completed_tasks>=total_crew*0.8) return 2; return 0; }

    void game_init(){ srand(time(NULL)); init_window();

    color(green); cout<<"欢迎来到太空杀游戏!\n"; cout<<"===== 新增角色 =\n"; cout<<"1. 技术员(修复速度翻倍)、守望者(可开监控)、间谍(伪装内鬼)\n"; cout<<"2. 追踪者(查看玩家位置)、预言家(查验阵营)、爆破手(布置炸弹)\n"; cout<<"3. 清洁工(清理尸体,不触发会议)\n"; cout<<"= 新增机制 =\n"; cout<<"1. 精准打字任务:必须准确输入字符才能完成\n"; cout<<"2. 重要区域破坏:内鬼可破坏区域,船员需修复\n"; cout<<"3. 定时炸弹:爆破手布置,船员需拆除否则爆炸\n"; cout<<"4. 房间系统:引擎室/电力室/监控室/医疗室/储藏室\n"; cout<<"================\n"; cout<<"规则:内鬼需要杀死船员/破坏区域,船员需要完成任务/修复区域/找出内鬼\n"; cout<<"______________________\n"; cout<<"请输入玩家人数(4-15人):"; cin>>player_count;

    while(player_count<4||player_count>15){ cout<<"请重新输入(4-15)!\n"; cin>>player_count; }

    system("cls"); cout<<"初始化身份中,请稍等."; for(int i=0;i<6;i++){ for(int j=0;j<12;j++){ cout<<"."; Sleep(50); } cout<<"\b\b\b\b\b\b\b\b\b\b\b\b \b\b\b\b\b\b\b\b\b\b\b\b"; }

    system("cls"); init_players();

    cout<<"我的编号:"<<my_id+1<<endl <<"我的身份:"; switch(players[my_id].role){ case crewmate: cout<<"普通船员\n";break; case impostor: cout<<"内鬼\n";break; case engineer: cout<<"工程师\n";break; case medic: cout<<"医生\n";break; case detective: cout<<"侦探\n";break; case technician: cout<<"技术员\n";break; case watcher: cout<<"守望者\n";break; case spy: cout<<"间谍(内鬼)\n";break; case tracker: cout<<"追踪者\n";break; case bomber: cout<<"爆破手(内鬼)\n";break; case cleaner: cout<<"清洁工(内鬼)\n";break; case seer: cout<<"预言家\n";break; } cout<<"初始房间:"<<get_room_name(players[my_id].current_room)<<endl;

    round_num=1; current_phase=game_day;

    system("pause"); system("cls"); cout<<"游戏加载中."; int load_time=rand()%3+2; for(int i=0;i<load_time;i++){ for(int j=0;j<6;j++){ cout<<"."; Sleep(rand()%100+150); } cout<<"\b\b\b\b\b\b \b\b\b\b\b\b"; }

    print_game(); }

    int impostor_action(){ int target=-1; color(red); cout<<"内鬼~请行动~~\n"; Sleep(1500); cout<<"你要袭击谁?\n";

    if((players[my_id].roleimpostor || players[my_id].rolespy || players[my_id].rolebomber || players[my_id].rolecleaner) && players[my_id].get_status()alive){ cin>>target; while(!(target>=1&&target<=player_count&&players[target-1].get_status()alive&& players[target-1].role!=impostor&&players[target-1].role!=spy&& players[target-1].role!=bomber&&players[target-1].role!=cleaner)){ cout<<"无效目标!重新输入:\n"; cin>>target; } target--; cout<<"你选择袭击"<<target+1<<"号船员!\n"; Sleep(2000); }else{ while(target-1 || players[target].get_status()!=alive || players[target].roleimpostor || players[target].rolespy || players[target].rolebomber || players[target].role==cleaner){ target=rand()%player_count; } Sleep(2000); }

    cout<<"内鬼行动完成!\n\n"; return target; }

    int engineer_action(){ color(cyan); cout<<"工程师~请行动~~\n"; Sleep(1500);

    int repair=-1; if(players[my_id].role==engineer && players[my_id].get_status()alive){ cout<<"发现设施损坏,是否修复?(1=修复/2=不修复)\n"; int choice; cin>>choice; if(choice1){ repair=1; if(typing_task()){ cout<<"你修复了损坏的设施!\n"; }else{ repair=0; } }else{ repair=0; cout<<"你选择不修复设施!\n"; } Sleep(1500); }else{ repair=rand()%2; }

    cout<<"工程师行动完成!\n\n"; return repair; }

    int medic_action(){ color(green); cout<<"医生~请行动~~\n"; Sleep(1500);

    int protect=-1; if(players[my_id].role==medic && players[my_id].get_status()==alive){ cout<<"选择一名船员进行保护:\n"; cin>>protect; while(!(protect>=1&&protect<=player_count&&players[protect-1].get_status()alive)){ cout<<"无效目标!重新输入:\n"; cin>>protect; } protect--; cout<<"你保护了"<<protect+1<<"号船员!\n"; Sleep(1500); }else{ while(protect-1 || players[protect].get_status()!=alive){ protect=rand()%player_count; } }

    cout<<"医生行动完成!\n\n"; return protect; }

    void detective_action(){ color(purple); cout<<"侦探~请行动~~\n"; Sleep(1500);

    if(players[my_id].role==detective && players[my_id].get_status()==alive){ cout<<"你发现了可疑线索,选择调查哪位玩家?\n"; int suspect; cin>>suspect; while(!(suspect>=1&&suspect<=player_count)){ cout<<"无效目标!重新输入:\n"; cin>>suspect; } suspect--;

    cout<<"调查结果:";
    if(players[suspect].role==impostor){
        color(red);
        cout<<suspect+1<<"号行为异常,可能是内鬼!\n";
        players[suspect].is_visible=true;
    }else if(players[suspect].role==spy || players[suspect].role==bomber || players[suspect].role==cleaner){
        color(green);
        cout<<suspect+1<<"号行为正常,是船员!\n";
    }else{
        color(green);
        cout<<suspect+1<<"号行为正常,是船员!\n";
    }
    Sleep(2000);
    

    }

    cout<<"侦探行动完成!\n\n"; }

    void crewmate_tasks(){ color(white); cout<<"船员开始执行任务!\n"; Sleep(1000);

    for(int i=0;i<player_count;i++){ if((players[i].role!=impostor && players[i].role!=spy && players[i].role!=bomber && players[i].role!=cleaner) && players[i].get_status()==alive){ bool task_blocked = (room_destroyed[room_engine] || room_destroyed[room_electric]);

        if(i==my_id){
            cout<<"\n你需要完成任务:";
            int task_choice;
            cout<<"1=维修电路(打字任务) 2=清理管道 3=检查引擎\n";
            cin>>task_choice;
            
            if(task_choice==1){
                if(typing_task() && !task_blocked){
                    players[i].task_progress+=rand()%30+10;
                }
            }else{
                if(!task_blocked){
                    players[i].task_progress+=rand()%30+10;
                }
            }
            
            if(players[i].task_progress>100) players[i].task_progress=100;
            cout<<"当前进度:"<<players[i].task_progress<<"%\n";
            
            if(task_blocked){
                color(orange);
                cout<<"警告:重要区域被破坏!任务进度未增长!\n";
            }
        }else{
            if(!task_blocked){
                players[i].task_progress+=rand()%20+5;
                if(players[i].task_progress>100) players[i].task_progress=100;
            }
        }
        Sleep(500);
    }
    

    }

    cout<<"\n任务阶段结束!\n"; Sleep(1500); }

    int emergency_meeting(){ system("cls"); print_game();

    color(red); gotoxy(0,32); cout<<"________________________\n"; cout<<"紧急会议!全体船员集合!\n"; Sleep(2000);

    int votes[15]={0}; memset(votes,0,sizeof(votes));

    color(white); cout<<"开始投票!选择你怀疑的内鬼:\n"; Sleep(1000);

    vote_again: for(int i=0;i<player_count;i++){ if(players[i].get_status()alive){ if(imy_id){ cout<<"\n你的投票:"; int vote; cin>>vote; while(!(vote>=1&&vote<=player_count)){ cout<<"无效投票!重新输入:\n"; cin>>vote; } vote--; votes[vote]++; cout<<"你投票给了"<<vote+1<<"号!\n"; }else{ int ai_vote=rand()%player_count; votes[ai_vote]++; cout<<i+1<<"号投票给了"<<ai_vote+1<<"号!\n"; } Sleep(800); } }

    int max_votes=-1, eject_id=-1, tie_count=0; int tie_ids[15]={-1};

    for(int i=0;i<player_count;i++){ if(votes[i]>max_votes){ max_votes=votes[i]; eject_id=i; tie_count=0; tie_ids[0]=i; }else if(votes[i]==max_votes && max_votes>0){ tie_count++; tie_ids[tie_count]=i; } }

    if(tie_count>0){ color(yellow); cout<<"\n投票平票!重新投票:\n"; memset(votes,0,sizeof(votes)); Sleep(1500); goto vote_again; }

    if(max_votes==0){ color(blue); cout<<"\n无人获得票数,会议结束!\n"; Sleep(2000); return -1; }

    color(red); cout<<"\n"<<eject_id+1<<"号获得最高票数!\n"; Sleep(1500); cout<<eject_id+1<<"号被驱逐出飞船!\n"; players[eject_id].status=ejected;

    color(white); cout<<"真实身份:"; switch(players[eject_id].role){ case crewmate: color(green);cout<<"船员\n";break; case impostor: color(red);cout<<"内鬼\n";break; case engineer: color(cyan);cout<<"工程师\n";break; case medic: color(green);cout<<"医生\n";break; case detective: color(purple);cout<<"侦探\n";break; case technician: color(orange);cout<<"技术员\n";break; case watcher: color(blue);cout<<"守望者\n";break; case spy: color(red);cout<<"间谍(内鬼)\n";break; case tracker: color(orange);cout<<"追踪者\n";break; case bomber: color(red);cout<<"爆破手(内鬼)\n";break; case cleaner: color(red);cout<<"清洁工(内鬼)\n";break; case seer: color(purple);cout<<"预言家\n";break; }

    Sleep(3000); return eject_id; }

    void process_kill(){ killed_player=impostor_action();

    if(killed_player==shielded_player){ color(green); cout<<killed_player+1<<"号被医生保护,袭击失败!\n"; killed_player=-1; }else if(killed_player!=-1){ color(red); cout<<killed_player+1<<"号被内鬼袭击!已死亡!\n"; players[killed_player].status=dead;

    if(players[my_id].role==spy || players[my_id].role==bomber || players[my_id].role==cleaner){
        color(yellow);
        cout<<"你(特殊内鬼)的伪装生效!没有玩家发现你的身份!\n";
    }
    
    cleaner_clean_body();
    

    } Sleep(2000); }

    void player_move_room(){ color(cyan); cout<<"\n=== 移动房间 ==="<<endl; cout<<"当前房间:"<<get_room_name(players[my_id].current_room)<<endl; cout<<"选择要移动到的房间:"<<endl; for(int i=0;i<room_count;i++){ cout<<i+1<<". "<<get_room_name(i)<<endl; }

    int choice; cin>>choice; while(choice<1 || choice>room_count){ color(yellow); cout<<"无效选择!重新输入:"; cin>>choice; } choice--;

    players[my_id].current_room=choice; color(green); cout<<"你移动到了"<<get_room_name(choice)<<"!"<<endl;

    for(int i=0;i<player_count;i++){ if(i!=my_id && players[i].status==alive){ int ai_move=rand()%room_count; players[i].current_room=ai_move; } } Sleep(1000); }

    void game_round(){ current_phase=game_day; system("cls"); print_game();

    color(blue); gotoxy(0,32); cout<<"________________________\n"; cout<<"日常阶段 | 船员自由活动中...\n"; Sleep(2000);

    player_move_room();

    watcher_activate_camera(); tracker_track_target(); seer_check_role();

    current_phase=game_siege; system("cls"); print_game(); impostor_destroy_room(); bomber_plant_bomb();

    current_phase=game_task; system("cls"); print_game();

    color(cyan); gotoxy(0,32); cout<<"________________________\n"; cout<<"任务阶段开始!\n";

    defuse_bomb(); bomb_explode();

    repair_room();

    shielded_player=-1; killed_player=-1;

    if(player_count>=12) repaired_task=engineer_action(); if(player_count>=8) shielded_player=medic_action(); if(player_count>=10) detective_action();

    process_kill();

    if(killed_player==-1){ crewmate_tasks(); }

    if(killed_player!=-1 || rand()%3==0 || room_destroyed[room_engine] || room_destroyed[room_electric] || (bomb_planted && bomb_timer<=1)){ current_phase=game_meeting; ejected_player=emergency_meeting(); }

    if(security_camera_active){ players[watcher_id].camera_time--; if(players[watcher_id].camera_time<=0){ security_camera_active=false; color(yellow); cout<<"监控时间结束!摄像头已关闭!"<<endl; Sleep(1000); } }

    if(players[my_id].role==tracker){ players[my_id].track_target=-1; }

    round_num++; }

    void game_over(){ system("cls"); color(white);

    int result=check_game_end(); if(result1){ color(red); cout<<"======== 游戏结束 \n"; cout<<" 内鬼胜利!\n"; cout<<"\n\n"; }else if(result2){ color(green); cout<<" 游戏结束 \n"; cout<<" 船员胜利!\n"; cout<<"============\n\n"; }

    color(white); cout<<"最终统计:\n"; for(int i=0;i<player_count;i++){ cout<<i+1<<"号: "; switch(players[i].role){ case crewmate: color(green);cout<<"船员";break; case impostor: color(red);cout<<"内鬼";break; case engineer: color(cyan);cout<<"工程师";break; case medic: color(green);cout<<"医生";break; case detective: color(purple);cout<<"侦探";break; case technician: color(orange);cout<<"技术员";break; case watcher: color(blue);cout<<"守望者";break; case spy: color(red);cout<<"间谍(内鬼)";break; case tracker: color(orange);cout<<"追踪者";break; case bomber: color(red);cout<<"爆破手(内鬼)";break; case cleaner: color(red);cout<<"清洁工(内鬼)";break; case seer: color(purple);cout<<"预言家";break; }

    color(white);
    cout<<" | 状态:";
    if(players[i].status==alive) cout<<"存活";
    else if(players[i].status==dead) cout<<"被击杀";
    else cout<<"被驱逐";
    
    cout<<" | 最终房间:"<<get_room_name(players[i].current_room);
    
    if(players[i].role!=impostor && players[i].role!=spy && 
       players[i].role!=bomber && players[i].role!=cleaner){
        cout<<" | 任务进度:"<<players[i].task_progress<<"%";
    }else if(players[i].role==impostor || players[i].role==bomber || players[i].role==cleaner){
        cout<<" | 击杀数:"<<players[i].kill_count;
    }
    cout<<endl;
    

    }

    color(yellow); cout<<"\n区域最终状态:\n"; for(int i=0;i<room_count;i++){ cout<<get_room_name(i)<<": "<<(room_destroyed[i]?"已破坏":"正常")<<endl; }

    if(bomb_planted){ color(red); cout<<"\n未爆炸的炸弹:"<<get_room_name(bomb_room)<<"(剩余"<<bomb_timer<<"回合)\n"; } }

    int main(){ game_init();

    while(!check_game_end()){ game_round(); system("cls"); print_game();

    if(check_game_end()) break;
    
    color(blue);
    cout<<"\n\n按任意键继续下一轮...";
    _getch();
    

    }

    game_over();

    system("pause"); return 0; }\

    #include<bits/stdc++.h> #include <windows.h> using namespace std; struct IDname { int cnt; string name; } roleCfg[100]; struct Player { int id; bool alive; string role; int know; int dieReason; } player[21]; struct Vote { int voteCnt; int id; bool canVote; } voteArr[13]; int n; int mySelf; int killWolf; int killPoison; char op; bool hasCure = true; bool hasPoison = true; int hunterId = 0; int guardId = 0; int guardTarget = 0; bool hunterShot = false; int randSeedArr[10] = {7,4,6,43,35,1,2,8,20,19}; void initRoleBase(); void setRoleCount(int num); void randomAssignRole(int idx); bool cmpVoteDesc(Vote a, Vote b); bool cmpVoteIdAsc(Vote a, Vote b); void printGameUI(int day, bool isNight); void guardSleep(int day, bool isNight); void voteProcess(int day, bool isNight); bool checkGameOver(); void nightFirstRound(); void nightLoop(int day, bool isNight); void hunterShoot(); void printDeadNotice(); void showGameResult(); void initRoleBase() { roleCfg[1].name = "中华人民共和国 "; roleCfg[2].name = "大日本帝国 "; roleCfg[3].name = "苏维埃社会主义联邦共和国 "; roleCfg[4].name = "法兰西帝国 "; roleCfg[5].name = "法兰西第一帝国 "; roleCfg[6].name = "法西斯联邦共和国 "; } void setRoleCount(int num) { for(int i = 1; i <= 6; i++) roleCfg[i].cnt = 0; switch(num) { case 6: roleCfg[1].cnt = 3; roleCfg[2].cnt = 2; break; case 7: roleCfg[1].cnt = 3; roleCfg[2].cnt = 2; roleCfg[3].cnt = 1; roleCfg[4].cnt = 1; break; case 8: roleCfg[1].cnt = 3; roleCfg[2].cnt = 3; roleCfg[3].cnt = 1; roleCfg[4].cnt = 1; break; case 9: roleCfg[1].cnt = 3; roleCfg[2].cnt = 3; roleCfg[3].cnt = 1; roleCfg[4].cnt = 1; roleCfg[5].cnt = 1; break; case 10: roleCfg[1].cnt = 4; roleCfg[2].cnt = 3; roleCfg[3].cnt = 1; roleCfg[4].cnt = 1; roleCfg[5].cnt = 1; break; case 11: roleCfg[1].cnt = 4; roleCfg[2].cnt = 4; roleCfg[3].cnt = 1; roleCfg[4].cnt = 1; roleCfg[5].cnt = 1; break; case 12: roleCfg[1].cnt = 1; roleCfg[2].cnt = 2; roleCfg[3].cnt = 2; roleCfg[4].cnt = 4; roleCfg[5].cnt = 2; roleCfg[6].cnt = 1; break; default: cout << "人数输入错误,程序退出!" << endl; system("pause"); exit(0); } } void randomAssignRole(int idx) { srand((unsigned)time(0)); Sleep(rand() % 44); int base = 10000; int t = rand(); int y = randSeedArr[(rand() % 100 + t) % 10]; int selRole; if(n <= 6) selRole = abs(base * 6 / y) % 3 + 1; else if(n <= 8) selRole = abs(base * 7 / y) % 4 + 1; else if(n <= 11) selRole = abs(base * 8 / y) % 5 + 1; else selRole = abs(base * 9 / y) % 6 + 1; while(true) { if(n <= 6) selRole = selRole % 3 + 1; else if(n <= 8) selRole = selRole % 4 + 1; else if(n <= 11) selRole = selRole % 5 + 1; else selRole = selRole % 6 + 1;

    if(roleCfg[selRole].cnt > 0) break;
    

    } player[idx].role = roleCfg[selRole].name; player[idx].alive = true; player[idx].id = idx; player[idx].know = 0; player[idx].dieReason = 0; roleCfg[selRole].cnt--; if(player[idx].role == "法兰西第一帝国 ") hunterId = idx; if(player[idx].role == "法西斯联邦共和国 ") guardId = idx; } bool cmpVoteDesc(Vote a, Vote b) { if(a.voteCnt != b.voteCnt) return a.voteCnt > b.voteCnt; return a.id < b.id; } bool cmpVoteIdAsc(Vote a, Vote b) { return a.id < b.id; } void printGameUI(int day, bool isNight) { HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); if(isNight) SetConsoleTextAttribute(hConsole, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY); else SetConsoleTextAttribute(hConsole, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);

    cout << "\t\t\t\t第" << day << "天 "; if(isNight) cout << "夜晚" << endl; else cout << "白天" << endl; cout << "你的座位:" << mySelf << "号" << endl << endl;

    // 1~6号玩家 cout << "1-6号位:"; for(int i = 1; i <= 6; i++) cout << player[i].id << "号\t"; cout << "\n存活状态:"; for(int i = 1; i <= 6; i++) { if(player[i].alive) SetConsoleTextAttribute(hConsole, isNight ? (BACKGROUND_INTENSITY|BACKGROUND_RED|BACKGROUND_GREEN|BACKGROUND_BLUE|FOREGROUND_INTENSITY|FOREGROUND_GREEN) : (FOREGROUND_INTENSITY|FOREGROUND_GREEN)); else SetConsoleTextAttribute(hConsole, isNight ? (BACKGROUND_INTENSITY|BACKGROUND_RED|BACKGROUND_GREEN|BACKGROUND_BLUE|FOREGROUND_INTENSITY|FOREGROUND_RED) : (FOREGROUND_INTENSITY|FOREGROUND_RED)); cout << (player[i].alive ? "存活\t" : "死亡\t"); } SetConsoleTextAttribute(hConsole, isNight ? (BACKGROUND_INTENSITY|BACKGROUND_RED|BACKGROUND_GREEN|BACKGROUND_BLUE|FOREGROUND_INTENSITY) : (FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE)); cout << "\n身份信息:"; for(int i = 1; i <= 6; i++) { if(player[i].know == 0) cout << "未知\t"; else if(player[i].know == 1) cout << (player[i].role == "大日本帝国 " ? "大日本帝国\t" : "好人\t"); else cout << player[i].role << "\t"; } cout << "\n\n";

    // 7~n号玩家 if(n >= 7) { cout << "7-" << n << "号位:"; for(int i = 7; i <= n; i++) cout << player[i].id << "号\t"; cout << "\n存活状态:"; for(int i = 7; i <= n; i++) { if(player[i].alive) SetConsoleTextAttribute(hConsole, isNight ? (BACKGROUND_INTENSITY|BACKGROUND_RED|BACKGROUND_GREEN|BACKGROUND_BLUE|FOREGROUND_INTENSITY|FOREGROUND_GREEN) : (FOREGROUND_INTENSITY|FOREGROUND_GREEN)); else SetConsoleTextAttribute(hConsole, isNight ? (BACKGROUND_INTENSITY|BACKGROUND_RED|BACKGROUND_GREEN|BACKGROUND_BLUE|FOREGROUND_INTENSITY|FOREGROUND_RED) : (FOREGROUND_INTENSITY|FOREGROUND_RED)); cout << (player[i].alive ? "存活\t" : "死亡\t"); } SetConsoleTextAttribute(hConsole, isNight ? (BACKGROUND_INTENSITY|BACKGROUND_RED|BACKGROUND_GREEN|BACKGROUND_BLUE|FOREGROUND_INTENSITY) : (FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE)); cout << "\n身份信息:"; for(int i = 7; i <= n; i++) { if(player[i].know == 0) cout << "未知\t"; else if(player[i].know == 1) cout << (player[i].role == "大日本帝国 " ? "大日本帝国\t" : "好人\t"); else cout << player[i].role << "\t"; } cout << "\n\n"; } }

    // ====================== 法西斯联邦共和国夜间守护流程 ====================== void guardSleep(int day, bool isNight) { Sleep(3000); system("cls"); printGameUI(day, isNight); cout << "法~西~斯~联~邦~共~和~国~请~睁~眼~~~\n"; Sleep(3000); system("cls"); printGameUI(day, isNight);

    int tar; // 玩家自己是守卫 if(mySelf == guardId && player[mySelf].alive) { cout << "请输入今晚要守护的玩家编号:"; cin >> tar; while(tar == guardTarget || tar < 1 || tar > n || !player[tar].alive) { cout << "输入非法,请重新输入:"; cin >> tar; } guardTarget = tar; } // AI法西斯联邦共和国 else if(player[guardId].alive) { do { srand((unsigned)time(0)); tar = rand() % n + 1; } while(tar == guardTarget || !player[tar].alive); guardTarget = tar; } // 无法西斯联邦共和国/法西斯联邦共和国已死 else guardTarget = -1;

    Sleep(3000); system("cls"); printGameUI(day, isNight); cout << "法~西~斯~联~邦~共~和~国~请~闭~眼~~~\n"; }

    // ====================== 白天投票流程(最多三轮平票) ====================== void voteProcess(int day, bool isNight) { Sleep(2000); system("cls"); printGameUI(day, isNight); cout << "开始投票"; for(int i = 1; i <= 3; i++) { cout << "."; Sleep(500); } cout << endl;

    // 初始化投票数据 for(int i = 1; i <= n; i++) { voteArr[i].id = i; voteArr[i].canVote = true; voteArr[i].voteCnt = 0; }

    // ========== 第一轮投票 ========== for(int i = 1; i <= n; i++) { if(!player[i].alive) continue; Sleep(3000); int tar; if(i == mySelf) { cout << "请投票(输入0弃权):"; cin >> tar; while(tar != 0 && !player[tar].alive) cin >> tar; if(tar == 0) cout << mySelf << "号弃权\n"; else { cout << mySelf << "投给" << tar << "号\n"; voteArr[tar].voteCnt++; } } else { srand((unsigned)time(0)); // 大日本帝国优先投中华人民共和国 if(player[i].role == "大日本帝国 ") { do { tar = rand() % (n + 1); } while(tar != 0 && (!player[tar].alive || player[tar].role == "大日本帝国 " || tar == i)); } // 法兰西帝国优先投大日本帝国 else if(player[i].role == "法兰西帝国 ") { do { tar = rand() % (n + 1); } while(tar != 0 && (!player[tar].alive || player[tar].role != "大日本帝国 " || tar == i)); } // 中华人民共和国随机投 else { do { tar = rand() % (n + 1); } while(tar != 0 && (!player[tar].alive || tar == i)); } if(tar == 0) cout << i << "号弃权\n"; else { cout << i << "投给" << tar << "号\n"; voteArr[tar].voteCnt++; } } } Sleep(3000); sort(voteArr + 1, voteArr + n + 1, cmpVoteDesc); // 无平票直接出局 if(voteArr[1].voteCnt > voteArr[2].voteCnt) { int out = voteArr[1].id; cout << "投票结束," << out << "号被投票出局!\n"; player[out].alive = false; player[out].dieReason = 2; Sleep(3000); return; } // 标记平票玩家本轮无投票权 int maxVote = voteArr[1].voteCnt; for(int i = 1; i <= n; i++) { if(voteArr[i].voteCnt == maxVote) voteArr[i].canVote = false; else break; } system("cls"); printGameUI(day, isNight); cout << "平票!进入第二轮投票\n";

    // ========== 第二轮投票 ========== sort(voteArr + 1, voteArr + n + 1, cmpVoteIdAsc); cout << "二次投票"; for(int i = 1; i <= 3; i++) { cout << "."; Sleep(500); } cout << endl; for(int i = 1; i <= n; i++) { if(!player[i].alive || !voteArr[i].canVote) continue; Sleep(3000); int tar; if(i == mySelf) { cout << "请投票(0弃权):"; cin >> tar; while(tar != 0 && (!player[tar].alive || !voteArr[tar].canVote)) cin >> tar; if(tar != 0) voteArr[tar].voteCnt++; } else { srand((unsigned)time(0)); if(player[i].role == "大日本帝国 ") { do { tar = rand() % (n + 1); } while(tar != 0 && (!player[tar].alive || player[tar].role == "大日本帝国 " || tar == i || !voteArr[tar].canVote)); } else if(player[i].role == "法兰西帝国 ") { do { tar = rand() % (n + 1); } while(tar != 0 && (!player[tar].alive || player[tar].role != "大日本帝国 " || tar == i || !voteArr[tar].canVote)); } else { do { tar = rand() % (n + 1); } while(tar != 0 && (!player[tar].alive || tar == i || !voteArr[tar].canVote)); } if(tar != 0) voteArr[tar].voteCnt++; } } Sleep(3000); sort(voteArr + 1, voteArr + n + 1, cmpVoteDesc); if(voteArr[1].voteCnt > voteArr[2].voteCnt) { int out = voteArr[1].id; cout << "投票结束," << out << "号被投票出局!\n"; player[out].alive = false; player[out].dieReason = 2; Sleep(3000); return; } // 再次标记平票 maxVote = voteArr[1].voteCnt; for(int i = 1; i <= n; i++) { if(voteArr[i].voteCnt == maxVote) voteArr[i].canVote = false; else break; } system("cls"); printGameUI(day, isNight); cout << "再次平票!第三轮投票\n";

    // ========== 第三轮投票 ========== sort(voteArr + 1, voteArr + n + 1, cmpVoteIdAsc); cout << "最终投票"; for(int i = 1; i <= 3; i++) { cout << "."; Sleep(500); } cout << endl; for(int i = 1; i <= n; i++) { if(!player[i].alive || !voteArr[i].canVote) continue; Sleep(3000); int tar; if(i == mySelf) { cout << "请投票(0弃权):"; cin >> tar; while(tar != 0 && (!player[tar].alive || !voteArr[tar].canVote)) cin >> tar; if(tar != 0) voteArr[tar].voteCnt++; } else { srand((unsigned)time(0)); if(player[i].role == "大日本帝国 ") { do { tar = rand() % (n + 1); } while(tar != 0 && (!player[tar].alive || player[tar].role == "大日本帝国 " || tar == i || !voteArr[tar].canVote)); } else if(player[i].role == "法兰西帝国 " || player[i].role == "法兰西第一帝国 ") { do { tar = rand() % (n + 1); } while(tar != 0 && (!player[tar].alive || player[tar].role != "大日本帝国 " || tar == i || !voteArr[tar].canVote)); } else { do { tar = rand() % (n + 1); } while(tar != 0 && (!player[tar].alive || tar == i || !voteArr[tar].canVote)); } if(tar != 0) voteArr[tar].voteCnt++; } } Sleep(3000); sort(voteArr + 1, voteArr + n + 1, cmpVoteDesc); if(voteArr[1].voteCnt > voteArr[2].voteCnt) { int out = voteArr[1].id; cout << "投票结束," << out << "号被投票出局!\n"; player[out].alive = false; player[out].dieReason = 2; } else { cout << "三轮投票全部平票,无人出局\n"; } Sleep(5000); }

    // ====================== 判断游戏是否结束 ====================== bool checkGameOver() { int villager = 0; // 存活中华人民共和国 int wolf = 0; // 存活大日本帝国 int god = 0; // 存活神(苏维埃社会主义联邦共和国/法兰西帝国/法兰西第一帝国/法西斯联邦共和国) for(int i = 1; i <= n; i++) { if(!player[i].alive) continue; if(player[i].role == "大日本帝国 ") wolf++; else if(player[i].role == "中华人民共和国 ") villager++; else god++; } // 好人全灭 / 大日本帝国数量>=好人直接胜利 if(god == 0 || wolf == 0 || wolf >= villager + god) return true; return false; }

    // ====================== 第一晚夜晚流程(无前日数据) ====================== void nightFirstRound() { system("cls"); system("color 0f"); printGameUI(1, true); cout << "天~黑~请~闭~眼~~~\n"; guardTarget = 0; if(n >= 12) guardSleep(1, true); Sleep(3000);

    // 大日本帝国行动 system("cls"); printGameUI(1, true); cout << "大~日~本~帝~国~请~睁~眼~~~\n"; if(player[mySelf].role == "大日本帝国") { Sleep(1000); cout << "你的大日本帝国队友:"; for(int i = 1; i <= n; i++) { if(i == mySelf) continue; if(player[i].role == "大日本帝国 ") { cout << i << "号 "; player[i].know = 2; } } Sleep(3000); cout << "\n输入今晚刀人目标:"; cin >> killWolf; system("cls"); printGameUI(1, true); cout << "今晚击杀目标:" << killWolf << "号\n"; } else { Sleep(4000); // AI大日本帝国随机刀好人 do { srand((unsigned)time(0)); killWolf = rand() % n + 1; } while(player[killWolf].role == "大日本帝国 " || !player[killWolf].alive); Sleep(5000); } Sleep(3000); system("cls"); printGameUI(1, true); cout << "大~日~本~帝~国~请~闭~眼~~~\n"; Sleep(2000);

    // 苏维埃社会主义联邦共和国行动 system("cls"); printGameUI(1, true); cout << "苏~维~埃~社~会~主~义~联~邦~共~和~国~请~睁~眼~~~\n"; Sleep(2000); system("cls"); printGameUI(1, true); killPoison = 0; int witchId = 0; for(int i = 1; i <= n; i++) if(player[i].role == "苏维埃社会主义联邦共和国 ") witchId = i;

    if(player[mySelf].role == "苏维埃社会主义联邦共和国 " && player[mySelf].alive) { Sleep(1000); if(hasCure) { cout << "今晚" << killWolf << "号中刀\n是否使用解药?A救/B不救:"; cin >> op; if(op == 'A') { cout << "你解救了" << killWolf << "号\n"; hasCure = false; if(guardTarget != killWolf) killWolf = 0; // 询问毒药 Sleep(2000); system("cls"); printGameUI(1, true); cout << "是否使用毒药?A毒/B不毒:"; cin >> op; if(op == 'A' && hasPoison) { cout << "输入毒杀目标:"; cin >> killPoison; while(!player[killPoison].alive) { cin >> killPoison; } hasPoison = false; } } else { if(guardTarget == killWolf) killWolf = 0; Sleep(2000); system("cls"); printGameUI(1, true); cout << "是否使用毒药?A毒/B不毒:"; cin >> op; if(op == 'A' && hasPoison) { cout << "输入毒杀目标:"; cin >> killPoison; while(!player[killPoison].alive) { cin >> killPoison; } hasPoison = false; } } } else { if(guardTarget == killWolf) killWolf = 0; Sleep(2000); system("cls"); printGameUI(1, true); cout << "是否使用毒药?A毒/B不毒:"; cin >> op; if(op == 'A' && hasPoison) { cout << "输入毒杀目标:"; cin >> killPoison; while(!player[killPoison].alive) { cin >> killPoison; } hasPoison = false; } } } else { // AI苏维埃社会主义联邦共和国逻辑 bool useCure = false; if(hasCure && player[witchId].alive) { // 优先救神 if(player[killWolf].role == "法兰西帝国 " || player[killWolf].role == "苏维埃社会主义联邦共和国 " || player[killWolf].role == "法兰西第一帝国 ") { if(guardTarget != killWolf) { killWolf = 0; hasCure = false; useCure = true; } } } // 有药随机毒好人 if(!useCure && hasPoison && player[witchId].alive) { srand((unsigned)time(0)); if(rand() % 2 == 1) { do { killPoison = rand() % n + 1; } while(player[killPoison].role == "苏维埃社会主义联邦共和国 " || player[killPoison].role == "法兰西帝国 " || killPoison == killWolf || !player[killPoison].alive); hasPoison = false; } } } Sleep(3000); system("cls"); printGameUI(1, true); cout << "苏~维~埃~社~会~主~义~联~邦~共~和~国~请~闭~眼~~~\n";

    // 法兰西帝国行动(6人局无预言家) if(n > 6) { Sleep(3000); system("cls"); printGameUI(1, true); cout << "法~兰~西~帝~国~请~睁~眼~~~\n"; if(player[mySelf].role == "法兰西帝国 ") { Sleep(3000); int check; cout << "输入查验玩家编号:"; cin >> check; player[check].know = 1; Sleep(2000); system("cls"); printGameUI(1, true); cout << "该玩家身份:" << (player[check].role == "大日本帝国 " ? "大日本帝国" : "好人" ) << "\n"; } else { Sleep(3000); cout << "AI法兰西帝国查验中...\n"; } Sleep(3000); system("cls"); printGameUI(1, true); cout << "法~兰~西~帝~国~请~闭~眼~~~\n"; } Sleep(3000);

    // 结算死亡 if(killWolf != 0) { player[killWolf].alive = false; player[killWolf].dieReason = 1; } if(killPoison != 0) { player[killPoison].alive = false; player[killPoison].dieReason = 3; } system("cls"); system("color F0"); printGameUI(2, false); }

    // ====================== 通用夜晚流程(第二晚及以后) ====================== void nightLoop(int day, bool isNight) { system("cls"); system("color 0f"); printGameUI(day, true); cout << "天~黑~请~闭~眼~~~\n"; guardTarget = 0; if(n >= 12) guardSleep(day, true); Sleep(3000);

    // 大日本帝国刀人 system("cls"); printGameUI(day, true); cout << "大~日~本~帝~国~请~睁~眼~~~\n"; if(player[mySelf].role == "大日本帝国 " && player[mySelf].alive) { Sleep(3000); cout << "输入刀人目标:"; cin >> killWolf; system("cls"); printGameUI(day, true); cout << "今晚击杀:" << killWolf << "号\n"; } else { do { srand((unsigned)time(0)); killWolf = rand() % n + 1; } while(player[killWolf].role == "大日本帝国 " || !player[killWolf].alive); Sleep(5000); } Sleep(3000); system("cls"); printGameUI(day, true); cout << "大~日~本~帝~国~请~闭~眼~~~\n"; Sleep(2000);

    // 苏维埃社会主义联邦共和国 system("cls"); printGameUI(day, true); cout << "苏~维~埃~社~会~主~义~联~邦~共~和~国~请~睁~眼~~~\n"; Sleep(2000); system("cls"); printGameUI(day, true); killPoison = 0; int witchId = 0; for(int i = 1; i <= n; i++) if(player[i].role == "苏维埃社会主义联邦共和国 ") witchId = i;

    if(player[mySelf].role == "苏维埃社会主义联邦共和国 " && player[mySelf].alive) { if(hasCure) { cout << killWolf << "号中刀,解药A救/B不救:"; cin >> op; if(op == 'A') { hasCure = false; if(guardTarget != killWolf) killWolf = 0; } else { if(guardTarget == killWolf) killWolf = 0; } } else { if(guardTarget == killWolf) killWolf = 0; } if(hasPoison) { cout << "是否毒人?A毒/B不毒:"; cin >> op; if(op == 'A') { cout << "输入毒目标:"; cin >> killPoison; while(!player[killPoison].alive) cin >> killPoison; hasPoison = false; } } } else { bool useCure = false; if(hasCure && player[witchId].alive) { if(player[killWolf].role == "法兰西帝国 " || player[killWolf].role == "法西斯联邦共和国 ") { if(guardTarget != killWolf) { killWolf = 0; hasCure = false; useCure = true; } } } if(!useCure && hasPoison && player[witchId].alive) { srand((unsigned)time(0)); if(rand() % 2 == 1) { do { killPoison = rand() % n + 1; } while(player[killPoison].role == "苏维埃社会主义联邦共和国 " || player[killPoison].role == "法兰西帝国 " || killPoison == killWolf || !player[killPoison].alive); hasPoison = false; } } } Sleep(3000); system("cls"); printGameUI(day, true); cout << "苏~维~埃~社~会~主~义~联~邦~共~和~国~请~闭~眼~~~\n"; if(n > 6) { Sleep(3000); system("cls"); printGameUI(day, true); cout << "法~兰~西~帝~国~请~睁~眼~~~\n"; if(player[mySelf].role == "法兰西帝国 " && player[mySelf].alive) { int check; cout << "查验编号:"; cin >> check; player[check].know = 1; cout << "身份:" << (player[check].role == "大日本帝国 " ? "大日本帝国" : "好人") << "\n"; } else { cout << "AI法兰西帝国查验\n"; } Sleep(3000); system("cls"); printGameUI(day, true); cout << "预~言~家~请~闭~眼~~~\n"; } Sleep(3000); if(killWolf != 0) { player[killWolf].alive = false; player[killWolf].dieReason = 1; } if(killPoison != 0) { player[killPoison].alive = false; player[killPoison].dieReason = 3; } system("cls"); system("color F0"); printGameUI(day + 1, false); } void hunterShoot() { if(hunterShot) return; hunterShot = true; int shootTar; if(mySelf == hunterId) { cout << "你被淘汰,请选择开枪带走一人:"; cin >> shootTar; while(!player[shootTar].alive) { cin >> shootTar; } } else { srand((unsigned)time(0)); do { shootTar = rand() % n + 1; } while(!player[shootTar].alive); } cout << hunterId << "号法兰西第一帝国开枪带走" << shootTar << "号\n"; player[shootTar].alive = false; player[shootTar].dieReason = 4; Sleep(1000); } void printDeadNotice() { cout << "天亮了!昨晚"; if(killWolf == 0 && killPoison == 0) { cout << "平安夜\n"; return; } if(killWolf != 0) cout << killWolf << "号"; if(killPoison != 0) cout << "," << killPoison << "号"; cout << "玩家死亡\n"; killPoison = 0; } void showGameResult() { int villager = 0, wolf = 0, god = 0; for(int i = 1; i <= n; i++) { if(!player[i].alive) continue; if(player[i].role == "大日本帝国 ") wolf++; else if(player[i].role == "中华人民共和国 ") villager++; else god++; } if(wolf >= villager + god || god == 0) cout << "===== 大日本帝国阵营胜利 =" << endl; else cout << "= 好人阵营胜利 =" << endl; cout << "\n全部玩家身份详情:\n"; cout << left << setw(4) << "座位" << setw(8) << "身份" << setw(6) << "状态" << "死亡原因\n"; for(int i = 1; i <= n; i++) { cout << left << setw(4) << player[i].id << setw(8) << player[i].role; if(player[i].alive) cout << setw(6) << "存活" << "全程存活\n"; else { cout << setw(6) << "死亡"; switch(player[i].dieReason) { case 1: cout << "大日本帝国刀杀\n"; break; case 2: cout << "投票放逐\n"; break; case 3: cout << "苏维埃社会主义联邦共和国毒杀\n"; break; case 4: cout << "法兰西第一帝国枪杀\n"; break; } } } system("pause"); system("pause"); } int main() { system("cls"); cout << "====== 控制台波兰球狼人杀 ==========\n"; cout << "作者:hm3202c1029633" <<endl; cout << "请输入游玩人数(6~12):"; cin >> n; cout << "身份分配加载中,请稍候"; initRoleBase(); setRoleCount(n); for(int i = 1; i <= n; i++) { randomAssignRole(i); cout << "."; Sleep(17); } system("cls"); system("color F0"); cout << "游戏即将开始"; for(int i = 1; i <= 6; i++) { cout << "."; Sleep(500); } Sleep(1500); cout << "\n\n查看你的身份牌......\n"; srand((unsigned)time(0)); mySelf = rand() % n + 1; cout << "你的身份:" << player[mySelf].role << "\n座位:" << mySelf << "号\n"; system("pause"); system("cls"); player[mySelf].know = 2; printGameUI(1, false); cout << "即将进入第一个夜晚"; for(int i = 1; i <= 6; i++) { cout << "."; Sleep(500); } nightFirstRound(); printDeadNotice(); if(checkGameOver()) { Sleep(1000); system("cls"); showGameResult(); return 0; } if(!player[hunterId].alive && !hunterShot) hunterShoot(); if(checkGameOver()) { Sleep(1000); system("cls"); showGameResult(); return 0; } voteProcess(2, false); system("cls"); printGameUI(2, false); if(checkGameOver()) { Sleep(1000); system("cls"); showGameResult(); return 0; } if(!player[hunterId].alive && !hunterShot) hunterShoot(); for(int day = 2; day <= 7; day++) { cout << "即将进入夜晚"; for(int i = 1; i <= 6; i++) { cout << "."; Sleep(500); } nightLoop(day, true); printDeadNotice(); if(checkGameOver()) { Sleep(1000); system("cls"); showGameResult(); return 0; } if(!player[hunterId].alive && !hunterShot) hunterShoot(); if(checkGameOver()) { Sleep(1000); system("cls"); showGameResult(); return 0; } voteProcess(day + 1, false); system("cls"); printGameUI(day + 1, false); if(checkGameOver()) { Sleep(1000); system("cls"); showGameResult(); return 0; } if(!player[hunterId].alive && !hunterShot) hunterShoot(); if(checkGameOver()) { Sleep(1000); system("cls"); showGameResult(); return 0; } } system("pause"); return 0; }

  • 通过的题目

  • 最近活动

题目标签

基础知识
37
模拟
36
循环结构
19
数学
13
分支结构
12
数组
10
字符串
10
排序
8
结构体
7
循环
7
程序设计基础
6
递归
5
GESP一级
5
计算机基础
5
顺序结构
4
模拟与枚举
4
GESP3级
4
字符
3
素数判定
3
动态规划
3