【三国杀】C++代码实现 人机 控制台

我是一名业余的C++爱好者

代码主要由vector容器实现,可能会有些许冗余,不具有太高的学习价值

一些牌的功能尚未完成,所以无法使用

武将已经完成【诸葛亮】【司马懿】

后面将不断完善,如有BUG,请在评论区指出

2025.7.10更新:数据存档,商店,货币,游戏大厅

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

vector<string> cards;
vector<string> general_cards_pool = {"诸葛亮", "司马懿", "吕蒙", "张飞", "关羽"};
map<int, string> general = {{1, "诸葛亮"}, {2, "司马懿"}, {3, "吕蒙"}, {4, "张飞"}, {5, "关羽"}};

struct People
{
    int coin; // 不能赋值,否则会导致读入错误
    int token;
    int general_xp;
    int HP = 4;
    int use_SHA = 0;
    int rise_SHA = 0;
    int get_cards = 1;
    int show_cards = 1;
    int scrap[10];
    int jeweller;
    vector<string> hand_cards;
    vector<string> own_general;
    string armor;
    string judge;
    string weapon;
    string game_general;

} player1, player2;

int time_Q;

/*
1 = 蓝色:摸牌;被闪,被无懈
2 = 绿色:技能;结果;回血
4 = 红色:伤害;死亡
5 = 紫色:询问
6 = 黄色:弃牌;出牌
7 = 白色:打印牌
*/

string cut_string(string str);
string cut_string2(string str);
char cut_string3(string str);
void cards_SHUN(int p);
void if_kill();
void player1_ShowCards(int choice);
void player2_ShowCards(int choice);
void start_game();
void print(const string s, int color);
int find(vector<string> array, string target);
void Read()
{
    int g;
    ifstream in("data.txt");
    in >> player1.coin >> player1.token >> player1.general_xp;
    for (int i = 0; i < 5; i++)
    {
        in >> player1.scrap[i];
    }
    while (in >> g)
    {
        player1.own_general.push_back(general[g]);
    }
    in.close();
}
string Roll() // 大浪淘沙抽卡算法
{
    int Eli1 = rand() % 101;
    if (Eli1 <= 25)
    {
        cout << "你获得了武将万能经验*25" << endl;
        player1.general_xp += 25;
    }
    else if (Eli1 > 25 && Eli1 <= 50)
    {
        cout << "你获得了武将万能经验*50" << endl;
        player1.general_xp += 50;
    }
    else if (Eli1 > 50 && Eli1 <= 75)
    {
        cout << "你获得了武将万能经验*100" << endl;
        player1.general_xp += 100;
    }
    else
    {
        int Eli2 = rand() % 1001;
        if (Eli2 <= 500)
        {
            int num = rand() % 10 + 1;
            int Eli3 = rand() % 5 + 1;
            cout << "你获得了" << general[Eli3] << "的武将碎片*" << num << endl;
            player1.scrap[Eli3] += num;
        }
        else
        {
            int Eli4 = rand() % 1001;
            if (Eli4 <= 500)
            {
                int Eli5 = rand() % 5 + 1;
                print("你获得了武将" + general[Eli5] + "\n", 2);
                if (find(player1.own_general, general[Eli5]) == 10086)
                {
                    player1.own_general.push_back(general[Eli5]);
                }
                else
                {
                    cout << "您已经拥有该武将,自动为您转换为宝珠*1" << endl;
                    player1.jeweller++;
                }
            }
            else
            {
                cout << "你获得宝珠*1" << endl;
                player1.jeweller++;
            }
        }
    }
}

void settlement(bool v)
{
    if (v)
    {
        cout << "游戏胜利,获得奖励:金币*10\n";
        player1.coin += 10;
    }
    else
    {
        cout << "游戏失败,获得奖励:金币*2\n";
        player1.coin += 2;
    }
}

void print_data()
{
    cout << "当前数据:" << endl;
    cout << "金币:" << player1.coin << endl;
    cout << "令牌:" << player1.token << endl;
    cout << "武将经验:" << player1.general_xp << endl;
    cout << "宝珠:" << player1.jeweller << endl;
    for (int i = 1; i <= 5; i++)
    {
        cout << general[i] << "的武将碎片" << "*" << player1.scrap[i-1] << endl;
    }
    cout << "拥有武将:" << endl;
    for (int i = 0; i < player1.own_general.size(); i++)
    {
        cout << player1.own_general[i] << endl;
    }
}

void print(const string s, int color)
{
    HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | color);
    printf("%s", s.c_str());
    SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | 7);
}
void Save()
{
    cout << "稍等,您的数据正在保存..." << endl;
    Sleep(500);
    ofstream out("data.txt");
    out << player1.coin << endl
        << player1.token << endl
        << player1.general_xp << endl;

    for (int i = 0; i < 5; i++)
    {
        out << player1.scrap[i] << endl;
    }
    for (int i = 0; i < player1.own_general.size(); i++)
    {
        for (map<int, string>::iterator it = general.begin(); it != general.end(); it++)
        {
            if (it->second == player1.own_general[i])
            {
                out << it->first << endl;
            }
        }
    }
    out.close();
    cout << "保存完毕,您可以退出" << endl;
    exit(0);
}

void store()
{
    cout << "欢迎来到商店" << endl;
    cout << "令牌购买      1" << endl;
    cout << "碎片兑换      2" << endl;
    cout << "宝珠兑换      3" << endl;
    int choice;
    cin >> choice;
    switch (choice)
    {
    case 1:
        cout << "当前金币:" << player1.coin;
        cout << "令牌单价:15金币/个" << endl;
        cout << "请输入购买个数" << endl;
        int num;
        cin >> num;
        if (player1.coin < num * 15)
        {
            cout << "金币不足,无法购买" << endl;
        }
        else
        {
            player1.coin -= num * 15;
            player1.token += num;
            cout << "购买成功!" << endl;
        }
        break;
    case 2:
        cout << "10个武将碎片可以合成1个武将" << endl;
        for (int i = 1; i <=5; i++)
        {
            cout << i << "       " << general[i] << "的武将碎片" << "*" << player1.scrap[i-1] << endl;
        }
        int choice2;
        cin >> choice2;
        if (player1.scrap[choice2] >= 10)
        {
            player1.scrap[choice2]-=10;
            cout << "合成成功,获得武将" << general[choice2] << endl;
            if (find(player1.own_general, general[choice2]) == 10086)
            {
                player1.own_general.push_back(general[choice2]);
            }
            else
            {
                cout << "您已经拥有该武将,自动为您转换为宝珠*1" << endl;
                player1.jeweller++;
            }
        }
        break;
    case 3:
        cout << "目前尚未开放特色武将" << endl;
        Sleep(1000);
        break;
    }
}
void cards_pool()
{
    while (1)
    {
        cout << "欢迎来到武将抽奖池" << endl;
        cout << "当前拥有令牌" << player1.token << endl;
        if (player1.token > 0)
        {
            print("1    单抽·一发入魂\n", 5);
            print("2    十连·群英集萃\n", 5);
            print("3    退出·返回大厅\n", 5);
            int choice;
            cin >> choice;
            if (choice == 1)
            {
                player1.token--;
                cout << "抽奖中..." << endl;
                // Sleep(3000);
                Roll();
            }
            if (choice == 2)
            {
                if (player1.token > 9)
                {
                    player1.token -= 10;
                    cout << "抽奖中..." << endl;
                    // Sleep(3000);
                    for (int i = 1; i <= 10; i++)
                    {
                        Roll();
                    }
                }
                else
                {
                    cout << "令牌不足\n"
                         << endl;
                }
            }
            else
            {
                break;
            }
        }
        else
        {
            cout << "你没有令牌" << endl;
            break;
        }
    }
}
void lobby()
{
    while (1)
    {
        print_data();

        print("1  开始游戏\n", 5);
        print("2  商店\n", 5);
        print("3  抽卡池\n", 5);
        print("4  保存存档,退出", 5);
        print("  一定要存档!!!\n", 4);

        int choice;
        cin >> choice;

        switch (choice)
        {
        case 1:
            start_game();
            break;
        case 2:
            store();
            break;
        case 3:
            cards_pool();
            break;
        case 4:
            Save();
            break;
        }
    }
}

void Skills_ZhuGeLiang_GuanXing()
{
    vector<string> GuanXing_cards;
    if (cards.size() > 4 && player1.game_general == "诸葛亮")
    {
        print("是否发动【观星】你可以观看牌堆顶的4张牌,然后可以调整顺序\n", 5);
        print("1是\n0否\n", 5);

        int choice;
        cin >> choice;
        if (choice)
        {
            print("你已发动【观星】\n", 2);
            cout << "牌堆顶:" << endl;
            for (int i = cards.size() - 1; i > int(cards.size() - 5); i--)
            {
                cout << cards.size() - i << cards[i] << endl;
            }
            Sleep(1000);
            cout << "开始调整顺序:输入序号,由上到下的顺序放" << endl;
            for (int i = cards.size() - 1; i > int(cards.size() - 5); i--)
            {
                print("请输入" + to_string(cards.size() - i) + "张牌", 5);
                int num;
                cin >> num;
                GuanXing_cards.push_back(cards[cards.size() - num]);
            }

            cards[cards.size() - 1] = GuanXing_cards[0];
            cards[cards.size() - 2] = GuanXing_cards[1];
            cards[cards.size() - 3] = GuanXing_cards[2];
            cards[cards.size() - 4] = GuanXing_cards[3];
        }
    }
}

bool Skills_SiMaYi_FanKui()
{
    if (player1.game_general == "司马懿")
    {
        print("是否发动技能【反馈】\n", 5);
        cout << "1  是" << endl;
        cout << "0  否" << endl;
        int yn;
        cin >> yn;
        if (yn)
        {
            if (player2.hand_cards.size() == 0)
            {
                cout << "敌人没有手牌,无法发动技能【反馈】" << endl;
                return 0;
            }
            print("你已发动【反馈】\n", 2);
            cout << "敌人手牌" << endl;
            for (int i = 0; i < int(player2.hand_cards.size()); i++)
            {
                cout << i + 1 << ":" << endl;
            }
            int choice;
            cin >> choice;
            choice--;
            if (choice < 0 || choice > int(player2.hand_cards.size()))
            {
                print("超出范围,技能发动失败\n", 1);
                Sleep(1000);
            }
            else
            {
                print("你成功的获得了" + player2.hand_cards[choice] + "\n", 2);
                player1.hand_cards.push_back(player2.hand_cards[choice]);
                cout << "已添加" << endl;
                player2.hand_cards.erase(player2.hand_cards.begin() + choice);
                Sleep(1000);

                return 1;
            }
        }
    }
}

string Skills_SiMaYi_GuiCai(string origin)
{
    if (player1.game_general == "司马懿")
    {
        print("是否发动技能【鬼才】\n", 5);
        cout << "1   是" << endl;
        cout << "0   否" << endl;
        int yn;
        cin >> yn;
        if (yn)
        {
            print("你已发动【鬼才】\n", 2);
            Sleep(1000);
            cout << "请选择一张手牌代替判定牌" << endl;
            for (int i = 0; i < player1.hand_cards.size(); i++)
            {
                cout << i + 1 << ":" << player1.hand_cards[i] << endl;
            }
            int choice;
            cin >> choice;
            choice--;
            string ans = player1.hand_cards[choice];
            player1.hand_cards.erase(player1.hand_cards.begin() + choice);
            return ans;
        }
        else
        {
            return origin;
        }
    }
}
void choose_game_general()
{
    if (player1.own_general.size() == 0)
    {
        print("你还没有武将,无法选择,请去抽卡", 1);
        return;
    }
    print("请选择你的武将\n", 5);
    for (int i = 0; i < int(player1.own_general.size()); i++)
    {
        cout << i + 1 << player1.own_general[i] << endl;
    }
    int choice;
    cin >> choice;
    player1.game_general = player1.own_general[choice - 1];
    print("你已选择武将:" + player1.game_general + "\n", 2);
    if (player1.game_general == "诸葛亮")
    {
        print("你获得了技能【观星】【空城】\n", 2);
    }
    if (player1.game_general == "司马懿")
    {
        print("你获得了技能【反馈】【鬼才】\n", 2);
    }
}

void Shuffle()
{
    // 普杀--------------------------------------------
    for (int i = 6; i <= 10; i++)
    {
        cards.push_back("【杀】 方块" + to_string(i));
    }
    cards.push_back("【杀】 方块K");

    // 梅花牌
    for (int i = 2; i <= 7; i++)
    {
        cards.push_back("【杀】 梅花" + to_string(i));
    }
    for (int i = 8; i <= 10; i++)
    {
        for (int j = 1; j <= 2; j++)
        {
            cards.push_back("【杀】 梅花" + to_string(i));
        }
    }
    cards.push_back("【杀】 梅花J");
    cards.push_back("【杀】 梅花J"); // 若需要两张则保留此行

    // 红桃牌
    cards.push_back("【杀】 红桃10");
    cards.push_back("【杀】 红桃10"); // 若需要两张则保留此行,否则删除
    cards.push_back("【杀】 红桃J");

    // 黑桃牌
    cards.push_back("【杀】 黑桃7");
    for (int i = 8; i <= 10; i++)
    {
        for (int j = 1; j <= 2; j++)
        {
            cards.push_back("【杀】 黑桃" + to_string(i));
        }
    }

    // 梅花雷杀
    for (int i = 5; i <= 8; i++)
    {
        cards.push_back("【雷杀】 梅花" + to_string(i));
    }

    // 黑桃雷杀
    for (int i = 4; i <= 8; i++)
    {
        cards.push_back("【雷杀】 黑桃" + to_string(i));
    }
    cards.push_back("【火杀】 方块4");
    cards.push_back("【火杀】 方块5");
    cards.push_back("【火杀】 红桃4");
    cards.push_back("【火杀】 红桃7");
    cards.push_back("【火杀】 红桃10");
    cards.push_back("【闪】 方块2");
    cards.push_back("【闪】 方块2");
    cards.push_back("【闪】 方块3");
    cards.push_back("【闪】 方块4");
    cards.push_back("【闪】 方块5");
    cards.push_back("【闪】 方块6");
    cards.push_back("【闪】 方块6");
    cards.push_back("【闪】 方块7");
    cards.push_back("【闪】 方块7");
    cards.push_back("【闪】 方块8");
    cards.push_back("【闪】 方块8");
    cards.push_back("【闪】 方块10");
    cards.push_back("【闪】 方块10");
    cards.push_back("【闪】 方块J");
    cards.push_back("【闪】 方块J");
    cards.push_back("【闪】 方块J");
    cards.push_back("【闪】 红桃2");
    cards.push_back("【闪】 红桃2");
    cards.push_back("【闪】 红桃8");
    cards.push_back("【闪】 红桃9");
    cards.push_back("【闪】 红桃J");
    cards.push_back("【闪】 红桃Q");
    cards.push_back("【闪】 红桃K");
    cards.push_back("【桃】 方块2");
    cards.push_back("【桃】 方块3");
    cards.push_back("【桃】 方块Q");
    cards.push_back("【桃】 红桃3");
    cards.push_back("【桃】 红桃4");
    cards.push_back("【桃】 红桃5");
    cards.push_back("【桃】 红桃6");
    cards.push_back("【桃】 红桃6");
    cards.push_back("【桃】 红桃7");
    cards.push_back("【桃】 红桃8");
    cards.push_back("【桃】 红桃9");
    cards.push_back("【桃】 红桃Q");
    cards.push_back("【酒】 方块9");
    cards.push_back("【酒】 梅花3");
    cards.push_back("【酒】 梅花3");
    cards.push_back("【酒】 黑桃3");
    cards.push_back("【酒】 红桃9");
    cards.push_back("【桃园结义】 红桃A");
    cards.push_back("【万箭齐发】 红桃A");
    cards.push_back("【借刀杀人】 梅花Q");
    cards.push_back("【借刀杀人】 梅花K");
    cards.push_back("【五谷丰登】 红桃3");
    cards.push_back("【五谷丰登】 红桃4");
    cards.push_back("【南蛮入侵】 梅花7");
    cards.push_back("【南蛮入侵】 黑桃7");
    cards.push_back("【南蛮入侵】 黑桃K");
    cards.push_back("【火攻】 方块Q");
    cards.push_back("【火攻】 红桃2");
    cards.push_back("【火攻】 红桃3");
    cards.push_back("【无中生有】 红桃7");
    cards.push_back("【无中生有】 红桃8");
    cards.push_back("【无中生有】 红桃9");
    cards.push_back("【无中生有】 红桃J");
    cards.push_back("【顺手牵羊】 方块3");
    cards.push_back("【顺手牵羊】 方块4");
    cards.push_back("【顺手牵羊】 黑桃3");
    cards.push_back("【顺手牵羊】 黑桃4");
    cards.push_back("【顺手牵羊】 黑桃J");
    cards.push_back("【过河拆桥】 梅花3");
    cards.push_back("【过河拆桥】 梅花4");
    cards.push_back("【过河拆桥】 黑桃3");
    cards.push_back("【过河拆桥】 黑桃4");
    cards.push_back("【过河拆桥】 红桃Q");
    cards.push_back("【铁索连环】 梅花10");
    cards.push_back("【铁索连环】 梅花J");
    cards.push_back("【铁索连环】 梅花Q");
    cards.push_back("【铁索连环】 梅花K");
    cards.push_back("【无懈可击】 方块Q");
    cards.push_back("【无懈可击】 红桃A");
    cards.push_back("【无懈可击】 红桃K");
    cards.push_back("【无懈可击】 梅花Q");
    cards.push_back("【无懈可击】 梅花K");
    cards.push_back("【无懈可击】 黑桃J");
    cards.push_back("【无懈可击】 黑桃K");
    cards.push_back("【闪电】 红桃Q");
    cards.push_back("【闪电】 黑桃A");
    cards.push_back("【兵粮寸断】 梅花4");
    cards.push_back("【兵粮寸断】 黑桃10");
    cards.push_back("【乐不思蜀】 梅花6");
    cards.push_back("【乐不思蜀】 黑桃6");
    cards.push_back("【乐不思蜀】 红桃6");
    cards.push_back("【诸葛连弩】 方块A");
    cards.push_back("【诸葛连弩】 梅花A");
    cards.push_back("【青釭剑】 黑桃4");
    cards.push_back("【寒冰剑】 黑桃2");
    cards.push_back("【雌雄双股剑】 黑桃2");
    cards.push_back("【古锭刀】 黑桃A");
    cards.push_back("【青龙偃月刀】 黑桃5");
    cards.push_back("【丈八蛇矛】 黑桃Q");
    cards.push_back("【贯石斧】 方块5");
    cards.push_back("【朱雀羽扇】 方块A");
    cards.push_back("【方天画戟】 方块Q");
    cards.push_back("【麒麟弓】 黑桃5");
    cards.push_back("【白银狮子】 梅花A");
    cards.push_back("【仁王盾】 梅花2");
    cards.push_back("【藤甲】 梅花2");
    cards.push_back("【藤甲】 黑桃2");
    cards.push_back("【八卦阵】 梅花2");
    cards.push_back("【八卦阵】 黑桃2");

    random_shuffle(cards.begin(), cards.end());
}
string ChineseStringSubstr(const string &str, int &start, int &end)
{
    /*
     * function:裁剪带中文的字符串.参数1:待裁剪字符串. 参数2:裁剪起始索引值. 参数3:裁剪结果索引值
     * 思路:从字符串头部往后寻找每个字符的idex,直到到达需要裁剪的位置,并对裁剪位置的索引值进行矫正,防止将中文字符从所占字节中间切断.
     */
    string Chinese = "汉";
    int ChineseSize = Chinese.length(); // 判断一个中文占多少字节

    //===矫正start的索引值(防止将中文的字节)
    if (start != 0)
    { // start==0时无需矫正
        int startIdex = 0;
        for (int i = 0; i < int(str.size()); i++)
        {
            if (startIdex >= start)
            { // 到达待矫正idex时,结束
                break;
            }

            if (str[i] & 0x80)
            { // 当前索引位置为中文

                startIdex += ChineseSize;
                i = i + ChineseSize - 1;
            }
            else
            {
                startIdex += 1;
            }
        }
        start = startIdex;
    }

    if (end != int(str.length()))
    {
        int endIdex = 0;
        for (int i = 0; i < int(str.size()); i++)
        {
            if (endIdex >= end)
            {
                break;
            }

            if (str[i] & 0x80)
            {
                endIdex += ChineseSize;
                i = i + ChineseSize - 1;
            }
            else
            {
                if (endIdex >= end)
                {
                    break;
                }
                endIdex += 1;
            }
        }
        end = endIdex;
    }

    string str_caijian = "";
    if (start < 0 || end > int(str.length()) || end <= start)
    {
        str_caijian = str;
        start = 0;
        end = str.length();
    }
    else
    {
        str_caijian = str.substr(start, end - start);
    }

    return str_caijian;
}
string cut_string(string str) // 裁剪牌内容
{
    int len = str.size();
    int start = 0;
    int end = 0;
    if (len == 12 || len == 13)
    {
        end = 6;
    }
    else if (len == 14 || len == 15)
    {
        end = 8;
    }
    else if (len == 16 || len == 17)
    {
        end = 10;
    }
    else if (len == 18 || len == 19)
    {
        end = 12;
    }
    else if (len == 20)
    {
        end = 14;
    }

    return ChineseStringSubstr(str, start, end);
}

string cut_string2(string str) // 裁剪花色
{
    int len = str.size();
    int start = 0;
    int end;
    if (len == 12 || len == 13)
    {
        start = 7;
        end = 9;
    }
    else if (len == 14 || len == 15)
    {
        start = 9;
        end = 11;
    }
    else if (len == 16 || len == 17)
    {
        start = 11;
        end = 13;
    }
    else if (len == 18 || len == 19)
    {
        start = 13;
        end = 15;
    }
    else if (len == 20)
    {
        start = 15;
        end = 17;
    }
    return ChineseStringSubstr(str, start, end);
}
char cut_string3(string str) // 裁剪点数
{
    int len = str.size();
    int start = 0;
    int end;
    if (len == 12)
    {
        start = 11;
        end = 12;
    }
    else if (len == 13)
    {
        start = 11;
        end = 13;
    }
    else if (len == 14)
    {
        start = 13;
        end = 14;
    }
    else if (len == 15)
    {
        start = 13;
        end = 15;
    }
    else if (len == 16)
    {
        start = 15;
        end = 16;
    }
    else if (len == 17)
    {
        start = 15;
        end = 17;
    }
    else if (len == 18)
    {
        start = 17;
        end = 18;
    }
    else if (len == 19)
    {
        start = 17;
        end = 19;
    }
    else if (len == 20)
    {
        start = 19;
        end = 20;
    }
    string result = ChineseStringSubstr(str, start, end);
    return char(result[0]);
}
int find(vector<string> array, string target)
{

    int len = array.size();
    for (int i = 0; i < len; i++)
    {
        if (cut_string(array[i]) == target)
        {

            return i;
        }
    }
    // cout<<"the Question is here"<<endl;
    return 10086;
}

bool weapon_GUAN(int p)
{
    if (p == 1)
    {
        if (player1.weapon == "【贯石斧】 方块5")
        {
            print("是否发动【贯石斧】技能:弃除两张牌对敌人造成伤害\n", 5);
            cout << "当前手牌" << endl;
            for (int i = 0; i < int(player1.hand_cards.size()); i++)
            {
                cout << i + 1 << ":" << player1.hand_cards[i] << endl;
            }
            Sleep(1000);
            print("1 是\n0 否", 5);
            int choice;
            cin >> choice;
            if (choice)
            {
                print("你发动了【贯石斧】技能", 2);
                print("请弃除两张牌\n", 5);
                for (int i = 1; i <= 2; i++)
                {
                    for (int j = 0; j < int(player1.hand_cards.size()); j++)
                    {
                        cout << j + 1 << ":" << player1.hand_cards[j] << endl;
                    }
                    int choice;
                    cin >> choice;
                    print("你弃除了" + player1.hand_cards[choice - 1] + "\n", 2);
                    player1.hand_cards.erase(player1.hand_cards.begin() + choice - 1);
                }
                return true;
            }
            else
            {
                return false;
            }
        }
        else
        {
            return false;
        }
    }
    else
    {
        if (player2.weapon == "【贯石斧】 方块5" && player2.hand_cards.size() >= 2)
        {

            print("敌人发动【贯石斧】:去除两张牌,强制造成伤害\n", 2);
            Sleep(1000);
            for (int i = 1; i <= 2; i++)
            {
                print("敌人去除了" + player2.hand_cards[0] + "\n", 2);
                player2.hand_cards.erase(player2.hand_cards.begin());
            }
            Sleep(1000);
            return true;
        }
        else
        {
            return false;
        }
    }
}

void cards_SHA(int p)
{
    // cout<<"in";
    void if_kill();
    void player1_ShowCards(int choice);
    // cout<<"the Question is here"<<endl;
    if (p == 1)
    {

        if (player1.use_SHA == 0 || (player1.weapon == "【诸葛连弩】 方块A" || player1.weapon == "【诸葛连弩】 梅花A") || (player1.weapon == "【青龙偃月刀】 黑桃5" && time_Q != 0)) // 还有距离;
        {
            player1.use_SHA = 1;
            if (find(player2.hand_cards, "【闪】") != 10086)
            {
                print("你的【杀】被【闪】了!!!\n", 1);
                player2.hand_cards.erase(player2.hand_cards.begin() + find(player2.hand_cards, "【闪】"));
                if (weapon_GUAN(1))
                {
                    if (player1.rise_SHA)
                    {
                        if (player1.weapon == "【古锭刀】 黑桃A" && player2.hand_cards.size() > 0)
                        {
                            player2.HP -= 3;
                            print("【古锭刀】效果生效,敌人没有手牌,杀伤害+1\n", 2);
                            print("【酒】效果生效,敌人血量-3,当前血量:" + to_string(player2.HP) + "\n", 4);
                        }
                        else
                        {
                            player2.HP -= 2;
                            print("【酒】效果生效,敌人血量-2,当前血量:" + to_string(player2.HP) + "\n", 4);
                        }
                    }
                    else
                    {
                        if (player1.weapon == "【古锭刀】 黑桃A" && player2.hand_cards.size() == 0)
                        {
                            player2.HP -= 2;
                            print("古锭刀效果生效,敌人没有手牌,杀伤害+1\n", 2);
                            print("敌人血量-2,当前血量:" + to_string(player2.HP) + "\n", 4);
                        }
                        else
                        {
                            print("敌人血量-1,当前血量:" + to_string(--player2.HP) + "\n", 4);
                        }
                    }

                    if_kill();
                }
                else if (player1.weapon == "【青龙偃月刀】 黑桃5" && find(player1.hand_cards, "【杀】") != 10086)
                {
                    print("是否发动【青龙偃月刀】技能:杀被闪后继续出杀\n1是\n0否\n", 5);
                    int choice;
                    cin >> choice;
                    if (choice)
                    {
                        print("发动【青龙偃月刀】技能,请继续出杀\n", 2);
                        for (int i = 0; i < int(player1.hand_cards.size()); i++)
                        {
                            cout << i + 1 << ":" << player1.hand_cards[i] << endl;
                        }
                        int choice;
                        cin >> choice;
                        choice--;
                        time_Q++;
                        player1_ShowCards(choice);
                    }
                }
            }

            else
            {
                if (player1.rise_SHA)
                {
                    if (player1.weapon == "【古锭刀】 黑桃A" && player2.hand_cards.size() == 0)
                    {
                        player2.HP -= 3;
                        print("【古锭刀】效果生效,敌人没有手牌,杀伤害+1\n", 2);
                        print("【酒】效果生效,敌人血量-3,当前血量:" + to_string(player2.HP) + "\n", 4);
                    }
                    else
                    {
                        player2.HP -= 2;
                        print("【酒】效果生效,敌人血量-2,当前血量:" + to_string(player2.HP) + "\n", 4);
                    }
                }
                else
                {
                    if (player1.weapon == "【古锭刀】 黑桃A" && player2.hand_cards.size() == 0)
                    {
                        player2.HP -= 2;
                        print("【古锭刀】效果生效,敌人没有手牌,杀伤害+1\n", 2);
                        print("敌人血量-2,当前血量:" + to_string(player2.HP) + "\n", 4);
                    }
                    else
                    {
                        print("敌人血量-1,当前血量:" + to_string(--player2.HP) + "\n", 4);
                    }
                }

                time_Q = 0;
                if_kill();
            }
        }
        else
        {
            print("条件不满足,使用失败,牌就不还你了\n", 1);
        }
    }
    else
    {
        // cout<<"in";
        if ((find(player2.hand_cards, "【杀】") != 10086 || find(player2.hand_cards, "【火杀】") != 10086 || find(player2.hand_cards, "【雷杀】") != 10086) && (player2.use_SHA == 0 || (player2.weapon == "【诸葛连弩】 方块A" || player2.weapon == "【诸葛连弩】 梅花A") || (player2.weapon == "【青龙偃月刀】 黑桃5" && time_Q != 0)))
        {

            //  cout<<"the Question is here"<<endl;
            if (player1.game_general == "诸葛亮" && player1.hand_cards.size() == 0)
            {
                print("你使用了技能【空城】,你没有手牌,敌人无法对你出杀\n", 2);
                Sleep(1000);
                return;
            }
            player2.hand_cards.erase(player2.hand_cards.begin() + find(player2.hand_cards, "【杀】"));
            player2.use_SHA = 1;
            print("敌人对你使用了【杀】!!!\n", 6);
            print("你需要打出一张【闪】\n", 5);
            cout << "-1:不出" << endl;
            for (int i = 0; i < int(player1.hand_cards.size()); i++)
            {
                cout << i + 1 << ":" << player1.hand_cards[i] << endl;
            }
            int choice;
            cin >> choice;
            choice--;
            if (choice == -2)
            {
                if (player2.rise_SHA)
                {
                    if (player2.weapon == "【古锭刀】 黑桃A" && player1.hand_cards.size() == 0)
                    {
                        player1.HP -= 3;
                        print("【古锭刀】效果生效,没有手牌,杀伤害+1\n", 2);
                        print("【酒】效果生效,血量-3,当前血量:" + to_string(player1.HP) + "\n", 4);
                    }
                    else
                    {
                        player1.HP -= 2;
                        print("【酒】效果生效,血量-2,当前血量:" + to_string(player1.HP) + "\n", 4);
                    }
                }
                else
                {
                    if (player2.weapon == "【古锭刀】 黑桃A" && player1.hand_cards.size() == 0)
                    {
                        player1.HP -= 2;
                        print("【古锭刀】效果生效,没有手牌,杀伤害+1\n", 2);
                        print("血量-2,当前血量:" + to_string(player1.HP) + "\n", 4);
                    }
                    else
                    {
                        print("血量-1,当前血量:" + to_string(--player1.HP) + "\n", 4);
                    }
                }
                if_kill();
                Skills_SiMaYi_FanKui();
            }
            else if (cut_string(player1.hand_cards[choice]) == "【闪】")
            {
                print("你打出了一张【闪】", 6);
                player1.hand_cards.erase(player1.hand_cards.begin() + choice);
                if (weapon_GUAN(2))
                {
                    if (player2.rise_SHA)
                    {
                        if (player2.weapon == "【古锭刀】 黑桃A" && player1.hand_cards.size() == 0)
                        {
                            player1.HP -= 3;
                            print("【古锭刀】效果生效,没有手牌,杀伤害+1\n", 2);
                            print("【酒】效果生效,血量-3,当前血量:" + to_string(player1.HP) + "\n", 4);
                        }
                        else
                        {
                            player1.HP -= 2;
                            print("【酒】效果生效,血量-2,当前血量:" + to_string(player1.HP) + "\n", 4);
                        }
                    }
                    else
                    {
                        if (player2.weapon == "【古锭刀】 黑桃A" && player1.hand_cards.size() == 0)
                        {
                            player1.HP -= 2;
                            print("【古锭刀】效果生效,没有手牌,杀伤害+1\n", 2);
                            print("血量-2,当前血量:" + to_string(player1.HP) + "\n", 4);
                        }
                        else
                        {
                            print("血量-1,当前血量:" + to_string(--player1.HP) + "\n", 4);
                        }
                    }
                    if_kill();
                    Skills_SiMaYi_FanKui();
                }
                else if (player2.weapon == "【青龙偃月刀】 黑桃5")
                {
                    if (find(player2.hand_cards, "【杀】") != 10086)
                    {
                        print("敌人发动了【青龙偃月刀】技能:杀被闪可以继续出杀\n", 2);
                        time_Q++;
                        cards_SHA(2);
                    }
                }
            }
            else
            {
                if (player2.rise_SHA)
                {
                    if (player2.weapon == "【古锭刀】 黑桃A" && player1.hand_cards.size() == 0)
                    {
                        player1.HP -= 3;
                        print("【古锭刀】效果生效,没有手牌,杀伤害+1\n", 2);
                        print("【酒】效果生效,血量-3,当前血量:" + to_string(player1.HP) + "\n", 4);
                    }
                    else
                    {
                        player1.HP -= 2;
                        print("【酒】效果生效,血量-2,当前血量:" + to_string(player1.HP) + "\n", 4);
                    }
                }
                else
                {
                    if (player2.weapon == "【古锭刀】 黑桃A" && player1.hand_cards.size() == 0)
                    {
                        player1.HP -= 2;
                        print("【古锭刀】效果生效,没有手牌,杀伤害+1\n", 2);
                        print("血量-2,当前血量:" + to_string(player1.HP) + "\n", 4);
                    }
                    else
                    {
                        print("血量-1,当前血量:" + to_string(--player1.HP) + "\n", 4);
                    }
                }
                time_Q = 0;
                if_kill();
                Skills_SiMaYi_FanKui();
            }
        }
    }
}

bool cards_WU(int p)
{
    if (p == 1) // 1是玩家;2是人机
    {
        if (find(player2.hand_cards, "【无懈可击】") != 10086)
        {
            player2.hand_cards.erase(player2.hand_cards.begin() + find(player2.hand_cards, "【无懈可击】"));
            print("你出的锦囊牌被敌人的【无懈可击】抵掉了!!!\n", 1);
            if (cards_WU(2))
            {
                // player2.hand_cards.erase(player2.hand_cards.begin() + find(player2.hand_cards, "【无懈可击】"));
                return false;
            }
            return true;
        }
        else
        {
            return true;
        }
    }
    else
    {
        if (find(player1.hand_cards, "【无懈可击】") != 10086)
        {
            print("是否使用一张【无懈可击】\n", 5);
            print("1 : 使用 \n0 : 不使用\n", 5);
            bool choice;
            cin >> choice;
            if (choice)
            {
                player1.hand_cards.erase(player1.hand_cards.begin() + find(player1.hand_cards, "【无懈可击】"));
                print("敌人出的锦囊牌被你的【无懈可击】抵掉了\n", 1);
                if (cards_WU(1))
                {
                    // player1.hand_cards.erase(player1.hand_cards.begin() + find(player1.hand_cards, "【无懈可击】"));
                    Sleep(1000);
                    return false;
                }
            }
            return true;
        }
        else
        {
            return true;
        }
    }
}
void cards_SHUN(int p)
{
    // cout<<"in";
    if (p == 1) // 1是玩家 2 是人机
    {
        if (player2.hand_cards.size() != 0) // 考虑距离
        {
            if (cards_WU(1))
            {
                int i;
                cout << "敌人手牌" << endl;
                for (i = 0; i < int(player2.hand_cards.size()); i++)
                {
                    cout << i + 1 << ":" << endl;
                }
                cout << i + 1 << ":敌人武器:" << player2.weapon << endl;
                cout << i + 2 << ":敌人防具:" << player2.armor << endl;
                int choice;
                cin >> choice;
                choice--;
                if (choice < 0 || choice > int(player2.hand_cards.size()))
                {
                    print("超出范围,使用失败,牌就不还你了\n", 1);
                    Sleep(1000);
                }
                else
                {
                    print("你成功的获得了" + player2.hand_cards[choice] + "\n", 2);
                    player1.hand_cards.push_back(player2.hand_cards[choice]);
                    player2.hand_cards.erase(player2.hand_cards.begin() + choice);
                    Sleep(1000);
                }
            }
        }
        else
        {
            // 装备考虑
            print("敌人没有手牌\n", 1);
            Sleep(1000);
        }
    }
    else if (p == 2)
    {
        if (player1.hand_cards.size() != 0) // 考虑距离
        {
            if (cards_WU(2))
            {
                int chance = rand() % player1.hand_cards.size();
                print("敌人从你那里获得了" + player1.hand_cards[chance] + "\n", 2);
                Sleep(1000);
                player2.hand_cards.push_back(player1.hand_cards[chance]);
                player1.hand_cards.erase(player1.hand_cards.begin() + chance);
                player2.hand_cards.erase(player2.hand_cards.begin() + find(player2.hand_cards, "【顺手牵羊】"));
            }
            else
            {
                print("你用无懈可击抵掉了敌人的牌\n", 2);
                Sleep(1000);
            }
        }
        else
        {
            print("你没有手牌,敌人的牌作废\n", 1);
            player2.hand_cards.erase(player2.hand_cards.begin() + find(player2.hand_cards, "【顺手牵羊】"));
            Sleep(1000);
        }
    }
}
void cards_CHAI(int p) // 1玩家 2人机
{
    if (p == 1)
    {
        if ((player2.hand_cards.size() != 0 || player2.weapon != "" || player2.armor != "") && cards_WU(1)) // 考虑距离
        {
            cout << "敌人手牌" << endl;
            int i;
            for (i = 0; i < int(player2.hand_cards.size()); i++)
            {
                cout << i + 1 << ":" << endl;
            }
            cout << i + 1 << ":敌人武器:" << player2.weapon << endl;
            cout << i + 2 << ":敌人防具:" << player2.armor << endl;
            int choice;
            cin >> choice;
            choice--;
            if (choice < 0 || choice > i + 2)
            {
                print("超出范围,使用失败,牌就不还你了\n", 1);
                Sleep(1000);
            }
            else
            {
                if (choice == i)
                {
                    print("你拆掉了敌人的武器" + player2.weapon + "\n", 2);
                    player2.weapon = "";
                }
                else if (choice == i + 1)
                {
                    print("你拆掉了敌人的防具" + player2.armor + "\n", 2);
                    player2.armor = "";
                }
                else
                {
                    print("你成功的拆掉了" + player2.hand_cards[choice] + "\n", 2);
                    player2.hand_cards.erase(player2.hand_cards.begin() + choice);
                }
            }
        }
        else
        {
            print("敌人没有手牌和装备牌\n", 1);
        }
    }
    else
    {
        // player2.hand_cards.erase(player2.hand_cards.begin() + find(player2.hand_cards, "【过河拆桥】"));

        if ((player1.hand_cards.size() != 0 || player1.weapon != "" || player1.armor != "") && cards_WU(2)) // 考虑距离
        {
            int chance = rand() % player1.hand_cards.size() + 2;
            if (chance == int(player1.hand_cards.size()) + 1)
            {
                print("敌人拆掉了你的武器" + player1.weapon + "\n", 2);
                player1.weapon = "";
            }
            else if (chance == int(player1.hand_cards.size()) + 2)
            {
                print("敌人拆掉了你的防具" + player1.armor + "\n", 2);
                player1.armor = "";
            }
            else
            {
                print("敌人成功的拆掉了你的" + player1.hand_cards[chance] + "\n", 2);
                player1.hand_cards.erase(player1.hand_cards.begin() + chance);
            }
        }
        else
        {
            print("你没有手牌和装备牌\n", 1); // 装备考虑
        }
    }
}
void player1_ShowCards(int choice)
{
    if (cut_string(player1.hand_cards[choice]) == "【杀】")
    {

        print("你使用了" + player1.hand_cards[choice] + "\n", 6);
        player1.hand_cards.erase(player1.hand_cards.begin() + choice);
        cards_SHA(1);
    }
    else if (cut_string(player1.hand_cards[choice]) == "【雷杀】")
    {

        print("你使用了" + player1.hand_cards[choice] + "\n", 6);
        cards_SHA(1); // TODO:考虑元素
        player1.hand_cards.erase(player1.hand_cards.begin() + choice);
    }
    else if (cut_string(player1.hand_cards[choice]) == "【火杀】")
    {

        print("你使用了" + player1.hand_cards[choice] + "\n", 6);
        cards_SHA(1);
        player1.hand_cards.erase(player1.hand_cards.begin() + choice);
    }
    // else if (player1.hand_cards[choice] == "【闪】")
    // {
    //     cout << "使用了闪" << endl;
    // }
    else if (cut_string(player1.hand_cards[choice]) == "【桃】")
    {

        print("你使用了" + player1.hand_cards[choice] + "\n", 6);
        if (player1.HP < 4)
        {
            player1.HP++;
            print("当前血量:" + to_string(player1.HP) + "\n", 2);
        }
        player1.hand_cards.erase(player1.hand_cards.begin() + choice);
    }
    else if (cut_string(player1.hand_cards[choice]) == "【酒】")
    {

        print("你使用了" + player1.hand_cards[choice] + "\n", 6);
        player1.rise_SHA = 1;
        player1.hand_cards.erase(player1.hand_cards.begin() + choice);
    }
    else if (cut_string(player1.hand_cards[choice]) == "【顺手牵羊】")
    {

        print("你使用了" + player1.hand_cards[choice] + "\n", 6);
        player1.hand_cards.erase(player1.hand_cards.begin() + choice);
        cards_SHUN(1);
    }
    else if (cut_string(player1.hand_cards[choice]) == "【过河拆桥】")
    {

        print("你使用了" + player1.hand_cards[choice] + "\n", 6);
        player1.hand_cards.erase(player1.hand_cards.begin() + choice);
        cards_CHAI(1);
    }
    else if (cut_string(player1.hand_cards[choice]) == "【决斗】")
    {

        print("你使用了" + player1.hand_cards[choice] + "\n", 6);
        player1.hand_cards.erase(player1.hand_cards.begin() + choice);
    }
    else if (cut_string(player1.hand_cards[choice]) == "【无中生有】")
    {

        print("你使用了" + player1.hand_cards[choice] + "\n", 6);
        if (cards_WU(1))
        {
            cout << "你摸到了";
            for (int i = 1; i <= 2; i++)
            {
                if (cards.size() == 0)
                {
                    Shuffle();
                }
                player1.hand_cards.push_back(cards[cards.size() - 1]);
                cout << cards[cards.size() - 1] << endl;
                cards.pop_back();
            }
            cout << endl;
        }
        player1.hand_cards.erase(player1.hand_cards.begin() + choice);
    }
    else if (cut_string(player1.hand_cards[choice]) == "【闪电】")
    {

        print("你使用了" + player1.hand_cards[choice] + "\n", 6);
        player2.judge = player1.hand_cards[choice];
        player1.hand_cards.erase(player1.hand_cards.begin() + choice);
    }
    else if (cut_string(player1.hand_cards[choice]) == "【兵粮寸断】")
    {

        print("你使用了" + player1.hand_cards[choice] + "\n", 6);
        player2.judge = player1.hand_cards[choice];
        player1.hand_cards.erase(player1.hand_cards.begin() + choice);
    }
    else if (cut_string(player1.hand_cards[choice]) == "【乐不思蜀】")
    {

        print("你使用了" + player1.hand_cards[choice] + "\n", 6);
        player2.judge = player1.hand_cards[choice];
        player1.hand_cards.erase(player1.hand_cards.begin() + choice);
    }
    else if (cut_string(player1.hand_cards[choice]) == "【借刀杀人】")
    {

        print("你使用了" + player1.hand_cards[choice] + "\n", 6);
        // cards_JIEDAO(1);
        player1.hand_cards.erase(player1.hand_cards.begin() + choice);
    }
    else if (cut_string(player1.hand_cards[choice]) == "【决斗】")
    {

        print("你使用了" + player1.hand_cards[choice] + "\n", 6);
        // cards_JUEDOU(1);
        player1.hand_cards.erase(player1.hand_cards.begin() + choice);
    }
    else if (cut_string(player1.hand_cards[choice]) == "【南蛮入侵】")
    {

        print("你使用了" + player1.hand_cards[choice] + "\n", 6);
        player1.hand_cards.erase(player1.hand_cards.begin() + choice);
    }
    else if (cut_string(player1.hand_cards[choice]) == "【万箭齐发】")
    {

        print("你使用了" + player1.hand_cards[choice] + "\n", 6);
        player1.hand_cards.erase(player1.hand_cards.begin() + choice);
    }
    else if (cut_string(player1.hand_cards[choice]) == "【桃园结义】")
    {

        print("你使用了" + player1.hand_cards[choice] + "\n", 6);
        player1.hand_cards.erase(player1.hand_cards.begin() + choice);
    }
    else if (cut_string(player1.hand_cards[choice]) == "【五谷丰登】")
    {

        print("你使用了" + player1.hand_cards[choice] + "\n", 6);
        player1.hand_cards.erase(player1.hand_cards.begin() + choice);
    }
    // else if (player1.hand_cards[choice] == "【无懈可击】")
    // {
    //     cout << "使用了【无懈可击】" << endl;
    // }
    else if (cut_string(player1.hand_cards[choice]) == "【诸葛连弩】")
    {

        print("你使用了" + player1.hand_cards[choice] + "\n", 6);
        player1.weapon = player1.hand_cards[choice];
        player1.hand_cards.erase(player1.hand_cards.begin() + choice);
    }
    else if (cut_string(player1.hand_cards[choice]) == "【古锭刀】")
    {

        print("你使用了" + player1.hand_cards[choice] + "\n", 6);
        player1.weapon = player1.hand_cards[choice];
        player1.hand_cards.erase(player1.hand_cards.begin() + choice);
    }
    else if (cut_string(player1.hand_cards[choice]) == "【青龙偃月刀】")
    {

        print("你使用了" + player1.hand_cards[choice] + "\n", 6);
        player1.weapon = player1.hand_cards[choice];
        player1.hand_cards.erase(player1.hand_cards.begin() + choice);
    }
    else if (cut_string(player1.hand_cards[choice]) == "【朱雀羽扇】")
    {

        print("你使用了" + player1.hand_cards[choice] + "\n", 6);
        player1.weapon = player1.hand_cards[choice];
        player1.hand_cards.erase(player1.hand_cards.begin() + choice);
    }
    else if (cut_string(player1.hand_cards[choice]) == "【贯石斧】")
    {

        print("你使用了" + player1.hand_cards[choice] + "\n", 6);
        player1.weapon = player1.hand_cards[choice];
        player1.hand_cards.erase(player1.hand_cards.begin() + choice);
    }
    else if (cut_string(player1.hand_cards[choice]) == "【方天画戟】")
    {

        print("你使用了" + player1.hand_cards[choice] + "\n", 6);
        player1.weapon = player1.hand_cards[choice];
        player1.hand_cards.erase(player1.hand_cards.begin() + choice);
    }
    else if (cut_string(player1.hand_cards[choice]) == "【麒麟弓】")
    {

        print("你使用了" + player1.hand_cards[choice] + "\n", 6);
        player1.weapon = player1.hand_cards[choice];
        player1.hand_cards.erase(player1.hand_cards.begin() + choice);
    }
    else if (cut_string(player1.hand_cards[choice]) == "【八卦阵】")
    {

        print("你使用了" + player1.hand_cards[choice] + "\n", 6);
        player1.armor = player1.hand_cards[choice];
        player1.hand_cards.erase(player1.hand_cards.begin() + choice);
    }
    else if (cut_string(player1.hand_cards[choice]) == "【仁王盾】")
    {

        print("你使用了" + player1.hand_cards[choice] + "\n", 6);
        player1.armor = player1.hand_cards[choice];
        player1.hand_cards.erase(player1.hand_cards.begin() + choice);
    }
    else if (cut_string(player1.hand_cards[choice]) == "【藤甲】")
    {

        print("你使用了" + player1.hand_cards[choice] + "\n", 6);
        player1.armor = player1.hand_cards[choice];
        player1.hand_cards.erase(player1.hand_cards.begin() + choice);
    }
    else if (cut_string(player1.hand_cards[choice]) == "【白银狮子】")
    {

        print("你使用了" + player1.hand_cards[choice] + "\n", 6);
        player1.armor = player1.hand_cards[choice];
        player1.hand_cards.erase(player1.hand_cards.begin() + choice);
    }

    // TODO:进攻马防御马
    //  else if (player1.hand_cards[choice] == "【-1】")
    //  {
    //
    //      print(player1.hand_cards[choice]+"\n",6);
    //  }
    //  else if (player1.hand_cards[choice] == "【+1】")
    //  {
    //
    //      cout << "使用了【+1】" << endl;
    //  }
}
void player2_ShowCards()
{
    for (int i = 1; i < 30; i++)
    {
        if (find(player2.hand_cards, "【酒】") != 10086 && find(player2.hand_cards, "【杀】") != 10086 && player2.use_SHA == 0)
        {
            print("敌人使用了" + player2.hand_cards[find(player2.hand_cards, "【酒】")] + "\n", 6);
            player2.rise_SHA = 1;
            player2.hand_cards.erase(player2.hand_cards.begin() + find(player2.hand_cards, "【酒】"));
        }

        if (find(player2.hand_cards, "【桃】") != 10086)
        {
            if (player2.HP < 4)
            {
                print("敌人使用了" + player2.hand_cards[find(player2.hand_cards, "【桃】")] + "\n", 6);
                player2.HP++;
                print("当前血量:" + to_string(player2.HP) + "\n", 2);
                player2.hand_cards.erase(player2.hand_cards.begin() + find(player2.hand_cards, "【桃】"));
            }
        }

        if (find(player2.hand_cards, "【麒麟弓】") != 10086)
        {
            print("敌人使用了" + player2.hand_cards[find(player2.hand_cards, "【麒麟弓】")] + "\n", 6);
            player2.weapon = player2.hand_cards[find(player2.hand_cards, "【麒麟弓】")];
            player2.hand_cards.erase(player2.hand_cards.begin() + find(player2.hand_cards, "【麒麟弓】"));
        }

        if (find(player2.hand_cards, "【贯石斧】") != 10086)
        {
            print("敌人使用了" + player2.hand_cards[find(player2.hand_cards, "【贯石斧】")] + "\n", 6);
            player2.weapon = player2.hand_cards[find(player2.hand_cards, "【贯石斧】")];
            player2.hand_cards.erase(player2.hand_cards.begin() + find(player2.hand_cards, "【贯石斧】"));
        }
        if (find(player2.hand_cards, "【青龙偃月刀】") != 10086)
        {
            print("敌人使用了" + player2.hand_cards[find(player2.hand_cards, "【青龙偃月刀】")] + "\n", 6);
            player2.weapon = player2.hand_cards[find(player2.hand_cards, "【青龙偃月刀】")];
            player2.hand_cards.erase(player2.hand_cards.begin() + find(player2.hand_cards, "【青龙偃月刀】"));
        }

        if (find(player2.hand_cards, "【青釭剑】") != 10086)
        {
            print("敌人使用了" + player2.hand_cards[find(player2.hand_cards, "【青釭剑】")] + "\n", 6);
            player2.weapon = player2.hand_cards[find(player2.hand_cards, "【青釭剑】")];
            player2.hand_cards.erase(player2.hand_cards.begin() + find(player2.hand_cards, "【青釭剑】"));
        }
        if (find(player2.hand_cards, "【寒冰剑】") != 10086)
        {
            print("敌人使用了" + player2.hand_cards[find(player2.hand_cards, "【寒冰剑】")] + "\n", 6);
            player2.weapon = player2.hand_cards[find(player2.hand_cards, "【寒冰剑】")];
            player2.hand_cards.erase(player2.hand_cards.begin() + find(player2.hand_cards, "【寒冰剑】"));
        }
        if (find(player2.hand_cards, "【朱雀羽扇】") != 10086)
        {
            print("敌人使用了" + player2.hand_cards[find(player2.hand_cards, "【朱雀羽扇】")] + "\n", 6);
            player2.weapon = player2.hand_cards[find(player2.hand_cards, "【朱雀羽扇】")];
            player2.hand_cards.erase(player2.hand_cards.begin() + find(player2.hand_cards, "【朱雀羽扇】"));
        }
        if (find(player2.hand_cards, "【古锭刀】") != 10086)
        {
            print("敌人使用了" + player2.hand_cards[find(player2.hand_cards, "【古锭刀】")] + "\n", 6);
            player2.weapon = player2.hand_cards[find(player2.hand_cards, "【古锭刀】")];
            player2.hand_cards.erase(player2.hand_cards.begin() + find(player2.hand_cards, "【古锭刀】"));
        }
        if (find(player2.hand_cards, "【诸葛连弩】") != 10086)
        {

            print("敌人使用了" + player2.hand_cards[find(player2.hand_cards, "【诸葛连弩】")] + "\n", 6);
            player2.weapon = player2.hand_cards[find(player2.hand_cards, "【诸葛连弩】")];
            player2.hand_cards.erase(player2.hand_cards.begin() + find(player2.hand_cards, "【诸葛连弩】"));
        }

        if (find(player2.hand_cards, "【方天画戟】") != 10086)
        {
            print("敌人使用了" + player2.hand_cards[find(player2.hand_cards, "【方天画戟】")] + "\n", 6);
            player2.weapon = player2.hand_cards[find(player2.hand_cards, "【方天画戟】")];
            player2.hand_cards.erase(player2.hand_cards.begin() + find(player2.hand_cards, "【方天画戟】"));
        }

        if (find(player2.hand_cards, "【八卦阵】") != 10086)
        {
            print("敌人使用了" + player2.hand_cards[find(player2.hand_cards, "【八卦阵】")] + "\n", 6);
            player2.armor = player2.hand_cards[find(player2.hand_cards, "【八卦阵】")];
            player2.hand_cards.erase(player2.hand_cards.begin() + find(player2.hand_cards, "【八卦阵】"));
        }

        if (find(player2.hand_cards, "【藤甲】") != 10086)
        {
            print("敌人使用了" + player2.hand_cards[find(player2.hand_cards, "【藤甲】")] + "\n", 6);
            player2.armor = player2.hand_cards[find(player2.hand_cards, "【藤甲】")];
            player2.hand_cards.erase(player2.hand_cards.begin() + find(player2.hand_cards, "【藤甲】"));
        }

        if (find(player2.hand_cards, "【仁王盾】") != 10086)
        {
            print("敌人使用了" + player2.hand_cards[find(player2.hand_cards, "【仁王盾】")] + "\n", 6);
            player2.armor = player2.hand_cards[find(player2.hand_cards, "【仁王盾】")];
            player2.hand_cards.erase(player2.hand_cards.begin() + find(player2.hand_cards, "【仁王盾】"));
        }
        if (find(player2.hand_cards, "【白银狮子】") != 10086)
        {
            print("敌人使用了" + player2.hand_cards[find(player2.hand_cards, "【白银狮子】")] + "\n", 6);
            player2.armor = player2.hand_cards[find(player2.hand_cards, "【白银狮子】")];
            player2.hand_cards.erase(player2.hand_cards.begin() + find(player2.hand_cards, "【白银狮子】"));
        }
        if (find(player2.hand_cards, "【顺手牵羊】") != 10086)
        {
            print("敌人使用了" + player2.hand_cards[find(player2.hand_cards, "【顺手牵羊】")] + "\n", 6);
            cards_SHUN(2);
            player2.hand_cards.erase(player2.hand_cards.begin() + find(player2.hand_cards, "【过河拆桥】"));
        }

        if (find(player2.hand_cards, "【无中生有】") != 10086)
        {
            print("敌人使用了" + player2.hand_cards[find(player2.hand_cards, "【无中生有】")] + "\n", 6);
            player2.hand_cards.erase(player2.hand_cards.begin() + find(player2.hand_cards, "【无中生有】"));
            if (cards_WU(2))
            {
                for (int j = 1; j <= 2; j++)
                {
                    cout << "敌人摸到了2张牌";
                    if (cards.size() == 0)
                    {
                        Shuffle();
                    }
                    player2.hand_cards.push_back(cards[cards.size() - 1]);
                    cards.pop_back();
                }
                cout << endl;
            }
        }

        if (find(player2.hand_cards, "【过河拆桥】") != 10086)
        {
            print("敌人使用了" + player2.hand_cards[find(player2.hand_cards, "【过河拆桥】")] + "\n", 6);
            cards_CHAI(2);
            player2.hand_cards.erase(player2.hand_cards.begin() + find(player2.hand_cards, "【过河拆桥】"));
        }
        if (find(player2.hand_cards, "【闪电】") != 10086)
        {
            print("敌人使用了" + player2.hand_cards[find(player2.hand_cards, "【闪电】")] + "\n", 6);
            player1.judge = player2.hand_cards[find(player2.hand_cards, "【闪电】")];
            player2.hand_cards.erase(player2.hand_cards.begin() + find(player2.hand_cards, "【闪电】"));
        }

        if (find(player2.hand_cards, "【乐不思蜀】") != 10086)
        {
            print("敌人使用了" + player2.hand_cards[find(player2.hand_cards, "【乐不思蜀】")] + "\n", 6);
            player1.judge = player2.hand_cards[find(player2.hand_cards, "【乐不思蜀】")];
            player2.hand_cards.erase(player2.hand_cards.begin() + find(player2.hand_cards, "【乐不思蜀】"));
        }
        if (find(player2.hand_cards, "【兵粮寸断】") != 10086)
        {
            print("敌人使用了" + player2.hand_cards[find(player2.hand_cards, "【兵粮寸断】")] + "\n", 6);
            player1.judge = player2.hand_cards[find(player2.hand_cards, "【兵粮寸断】")];
            player2.hand_cards.erase(player2.hand_cards.begin() + find(player2.hand_cards, "【兵粮寸断】"));
        }
        if (find(player2.hand_cards, "【决斗】") != 10086)
        {
            print("敌人使用了" + player2.hand_cards[find(player2.hand_cards, "决斗】")] + "\n", 6);
            // cards_JUEDOU(2);
            player2.hand_cards.erase(player2.hand_cards.begin() + find(player2.hand_cards, "【决斗】"));
        }

        cards_SHA(2); // TODO:元素杀,辨别装备出杀,更加智能
    }
}
void get_hand_cards(int cnt)
{
    cout << "到你摸牌,你摸到了:" << endl;
    for (int i = 1; i <= cnt; i++)
    {
        if (cards.size() == 0)
        {
            Shuffle();
        }
        player1.hand_cards.push_back(cards[cards.size() - 1]);
        cout << cards[cards.size() - 1] << ' ';
        cards.pop_back();
    }

    cout << endl;
}
void if_kill()
{
    if (player1.HP <= 0)
    {
        cout << "您已濒死,需要使用酒或桃回血,否则阵亡" << endl;
        cout << "-1:不使用" << endl;
        for (int i = 0; i < int(player1.hand_cards.size()); i++)
        {
            cout << i + 1 << ":" << player1.hand_cards[i] << endl;
        }
        int choice;
        cin >> choice;
        if (choice == -1)
        {
            cout << "您已阵亡" << endl;
            cout << "游戏结束,敌人获胜" << endl;
            Sleep(1000);
            settlement(0);
            cout << "5秒后回到游戏大厅..." << endl;
            Sleep(5000);
            lobby();
        }
        choice--;
        if (player1.hand_cards[choice] == "【桃】" || player1.hand_cards[choice] == "【酒】")
        {
            player1.HP++;
            cout << "您恢复1点体力" << endl;
            player1.hand_cards.erase(player1.hand_cards.begin() + choice);
            if_kill();
        }
    }
    else if (player2.HP <= 0)
    {
        cout << "敌人已濒死" << endl;
        if (find(player2.hand_cards, "【桃】") != 10086)
        {
            player2.HP++;
            cout << "敌人使用了【桃】恢复1点体力" << endl;
            player2.hand_cards.erase(player2.hand_cards.begin() + find(player2.hand_cards, "【桃】"));
            if_kill();
        }
        else if (find(player2.hand_cards, "【酒】") != 10086)
        {
            player2.HP++;
            cout << "敌人使用了【酒】恢复1点体力" << endl;
            player2.hand_cards.erase(player2.hand_cards.begin() + find(player2.hand_cards, "【酒】"));
            if_kill();
        }
        else
        {
            cout << "敌人已经阵亡,您获胜" << endl;
            Sleep(1000);
            settlement(1);
            cout << "5秒后回到游戏大厅..." << endl;
            Sleep(5000);
            lobby();
        }
    }
}
void player1_judge()
{
    if (cut_string(player1.judge) == "【乐不思蜀】")
    {
        string judge_card = cards[cards.size() - 1];
        print("判定牌为:" + judge_card + "\n", 6);
        if (player1.game_general == "司马懿")
        {
            judge_card = Skills_SiMaYi_GuiCai(judge_card);
        }
        Sleep(1000);
        if (cut_string2(judge_card) == "红")
        {
            print("于你判定区内的" + player1.judge + "判定失效" + "\n", 1);
            Sleep(1000);
        }
        else
        {
            if (cards_WU(2))
            {
                print("于你判定区内的" + player1.judge + "判定生效,这回合你将无法出牌" + "\n", 2);
                player1.show_cards = 0;
                Sleep(1000);
            }
        }
        player1.judge = "";
        cards.pop_back();
    }
    if (cut_string(player1.judge) == "【兵粮寸断】")
    {
        string judge_card = cards[cards.size() - 1];
        print("判定牌为:" + judge_card + "\n", 6);
        if (player1.game_general == "司马懿")
        {
            judge_card = Skills_SiMaYi_GuiCai(judge_card);
        }
        Sleep(1000);
        if (cut_string2(judge_card) == "梅")
        {
            print("于你判定区内的" + player1.judge + "判定失效" + "\n", 1);
            Sleep(1000);
        }
        else
        {
            if (cards_WU(2))
            {
                print("于你判定区内的" + player1.judge + "判定生效,这回合你将无法摸牌" + "\n", 2);
                player1.get_cards = 0;
                Sleep(1000);
            }
        }
        player1.judge = "";
        cards.pop_back();
    }
    if (cut_string(player1.judge) == "【闪电】")
    {
        string judge_card = cards[cards.size() - 1];
        print("判定牌为:" + judge_card + "\n", 6);
        if (player1.game_general == "司马懿")
        {
            judge_card = Skills_SiMaYi_GuiCai(judge_card);
        }
        Sleep(1000);
        if (cut_string2(judge_card) == "黑" && cut_string3(judge_card) >= '2' && cut_string3(judge_card) <= '9')
        {
            if (cards_WU(2))
            {
                print("于你判定区的" + player1.judge + "判定生效,你扣3滴血" + "\n", 2);
                Sleep(1000);
                player1.HP -= 3;
                print("你受到了3点伤害,当前血量:" + to_string(player1.HP) + "\n", 4);
                if_kill();
            }
        }
        else
        {
            print("于你判定区内的" + player2.judge + "判定失效" + "\n", 1);
            Sleep(1000);
        }
        player1.judge = "";
        cards.pop_back();
    }
}

void player2_judge()
{
    if (cut_string(player2.judge) == "【乐不思蜀】")
    {
        string judge_card = cards[cards.size() - 1];
        print("判定牌为:" + judge_card + "\n", 6);
        Sleep(1000);
        if (player1.game_general == "司马懿")
        {
            judge_card = Skills_SiMaYi_GuiCai(judge_card);
        }
        Sleep(1000);
        if (cut_string2(judge_card) == "红")
        {
            print("于敌人判定区内的" + player2.judge + "判定失效" + "\n", 1);
        }
        else
        {
            if (cards_WU(1))
            {
                print("于敌人判定区内的" + player2.judge + "判定生效,这回合敌人将无法出牌" + "\n", 2);
                player2.show_cards = 0;
                Sleep(1000);
            }
        }
        player2.judge = "";
        cards.pop_back();
    }
    if (cut_string(player2.judge) == "【兵粮寸断】")
    {
        string judge_card = cards[cards.size() - 1];
        print("判定牌为:" + judge_card + "\n", 6);
        if (player1.game_general == "司马懿")
        {
            judge_card = Skills_SiMaYi_GuiCai(judge_card);
        }
        Sleep(1000);
        if (cut_string2(judge_card) == "梅")
        {
            print("于敌人判定区内的" + player2.judge + "判定失效" + "\n", 1);
            Sleep(1000);
        }
        else
        {
            if (cards_WU(1))
            {
                print("于敌人判定区内的" + player2.judge + "判定生效,这回合敌人将无法摸牌" + "\n", 2);
                player2.get_cards = 0;
                Sleep(1000);
            }
        }
        player2.judge = "";
        cards.pop_back();
    }
    if (cut_string(player2.judge) == "【闪电】")
    {
        string judge_card = cards[cards.size() - 1];
        print("判定牌为:" + judge_card + "\n", 6);
        if (player1.game_general == "司马懿")
        {
            judge_card = Skills_SiMaYi_GuiCai(judge_card);
        }
        Sleep(1000);
        if (cut_string2(judge_card) == "黑" && cut_string3(judge_card) >= '2' && cut_string3(judge_card) <= '9')
        {
            if (cards_WU(1))
            {
                print("于敌人判定区的" + player2.judge + "判定生效,敌人扣3滴血" + "\n", 2);
                Sleep(1000);
                player2.HP -= 3;
                print("敌人受到了3点伤害,当前血量:" + to_string(player2.HP) + "\n", 4);
                if_kill();
            }
        }
        else
        {
            print("于敌人判定区内的" + player2.judge + "判定失效" + "\n", 1);
            Sleep(1000);
        }
        player2.judge = "";
        cards.pop_back();
    }
}
void player1_discard()
{
    if (int(player1.hand_cards.size()) > player1.HP)
    {
        cout << "你手牌数量超出你的血量!!!请弃除" << player1.hand_cards.size() - player1.HP << "张牌" << endl;
        while (int(player1.hand_cards.size()) > player1.HP)
        {
            cout << "当前手牌:" << endl;
            for (int j = 0; j < int(player1.hand_cards.size()); j++)
            {
                cout << j + 1 << ':' << player1.hand_cards[j] << endl;
            }
            int choice;
            cin >> choice;
            choice--;
            if (choice >= 0 && choice < int(player1.hand_cards.size()))
            {
                player1.hand_cards.erase(player1.hand_cards.begin() + choice);
            }
            else
            {
                cout << "无效选择,请重新选择一张要弃的牌" << endl;
            }
        }
    }
    else
    {
        cout << "已跳过弃牌阶段" << endl;
    }
}
void player2_discard()
{
    while (int(player2.hand_cards.size()) > player2.HP)
    {
        cout << endl;
        cout << "敌人弃除了";
        cout << player2.hand_cards[0] << endl;
        player2.hand_cards.erase(player2.hand_cards.begin());
    }
}

void InProgress()
{
    while (1)
    {
        player1.rise_SHA = 0;
        player2.rise_SHA = 0;
        player1.use_SHA = 0;
        player2.use_SHA = 0;
        player1.show_cards = 1;
        player2.show_cards = 1;
        player1.get_cards = 1;
        player2.get_cards = 1;

        Skills_ZhuGeLiang_GuanXing();
        player1_judge();

        if (player1.get_cards)
        {
            get_hand_cards(2);
        }
        if (player1.show_cards)
        {
            cout << "请出牌" << endl;
            while (1)
            {
                cout << "-1:结束出牌阶段" << endl;
                for (int i = 0; i < int(player1.hand_cards.size()); i++)
                {
                    cout << i + 1 << ":" << player1.hand_cards[i] << endl;
                }
                int choice;
                cin >> choice;
                if (choice == -1)
                {
                    cout << "出牌阶段已结束" << endl;
                    break;
                }
                choice--;
                player1_ShowCards(choice);
            }
        }
        player1_discard();
        print("进入敌人回合\n", 1);
        player2_judge();
        if (player2.get_cards)
        {
            for (int i = 1; i <= 2; i++)
            {
                player2.hand_cards.push_back(cards[cards.size() - 1]);
                cards.pop_back();
            }
        }
        if (player2.show_cards)
        {
            player2_ShowCards();
        }
        cout << endl
             << "敌人结束了出牌阶段" << endl;
        Sleep(1000);
        player2_discard();
        Sleep(1000);
    }
}
void GameSetUp()
{
    print("现在开始游戏\n", 1);
    Sleep(1000);
    Shuffle(); // TODO:不同的牌堆
    cout << "你的初始手牌为" << endl;
    for (int i = 1; i <= 4; i++)
    {
        player1.hand_cards.push_back(cards[cards.size() - 1]);
        cards.pop_back();
    }
    // player1.hand_cards.push_back("【乐不思蜀】 红桃3");
    for (int i = 0; i < int(player1.hand_cards.size()); i++)
    {
        cout << player1.hand_cards[i] << endl;
    }
    cout << endl; //<< "敌人手牌:" << endl;
    for (int i = 1; i <= 4; i++)
    {
        player2.hand_cards.push_back(cards[cards.size() - 1]);
        cards.pop_back();
    }
    cout << endl;
    Sleep(1000);
}
// void GameMode_Tutorial()
// {
//     cout << "新手教程开始" << endl;
//     cout << "先介绍一下最最最基本的牌——基本牌" << endl;
//     cout << "基本牌:" << endl;
//     print("【杀】:使用后可以对敌人造成1滴血伤害\n", 2);
//     print("注意:一回合只能用一张【杀】,除非你有诸葛连弩(【诸葛连弩】:你使用【杀】无次数限制)\n", 4);
//     Sleep(1000);
//     print("【闪】:如果敌人对你出杀,你需要出闪,否则你将受到伤害\n", 2);
//     Sleep(1000);
//     print("【桃】:使用后你可以恢复一滴血\n", 2);
//     Sleep(1000);
//     print("【酒】:在这回合内,你出的杀伤害+1滴血\n", 2);
//     cout << "下面就来练习一下吧!把敌人干掉获得胜利!(PS:每个人初始有4滴血)" << endl;
//     Sleep(1000);
//     cout << "PS:开始游戏时,每个人都会有4张牌,之后每个人出牌之前摸2张牌" << endl;
//     Sleep(1000);
//     player1.hand_cards.push_back("【杀】 花色1");
//     player1.hand_cards.push_back("【杀】 花色2");
//     player1.hand_cards.push_back("【闪】 花色3");
//     player1.hand_cards.push_back("【闪】 花色4");
//     cout << "你的初始手牌" << endl;
//     for (int i = 0; i < player1.hand_cards.size(); i++)
//     {
//         cout << player1.hand_cards[i] << endl;
//     }
//     while(1)
//     {
//         cout << "你的回合,你摸到了【酒】 【闪】" << endl;
//         cout<<"PS:在新手教程里,你摸的牌都是一样的,在正常的模式里就不是了"<<endl;
//         player1.hand_cards.push_back("【酒】 花色5");
//         player1.hand_cards.push_back("【闪】 花色6");
//         Sleep(1000);
//         cout << "请出牌" << endl;
//         while (1)
//         {
//             cout << "-1:结束出牌阶段" << endl;
//             for (int i = 0; i < int(player1.hand_cards.size()); i++)
//             {
//                 cout << i + 1 << ":" << player1.hand_cards[i] << endl;
//             }
//             int choice;
//             cin >> choice;
//             if (choice == -1)
//             {
//                 cout << "出牌阶段已结束" << endl;
//                 break;
//             }
//             choice--;
//             player1_ShowCards(choice);

//         }
//         cout<<"进入敌人回合"<<endl;
//         cout<<"敌人对你使用了【杀】"<<endl;
//         cards_SHA(2);
//         Sleep(1000);
//         cout<<"敌人结束了出牌阶段"<<endl;
//     }
// }
void GameMode1()
{
    GameSetUp();
    InProgress();
}
void GameMode2()
{
    choose_game_general();
    GameSetUp();
    InProgress();
}
void Internet_Gamemode()
{
    
}
void start_game()
{
    print("请选择游戏模式\n", 5);
    // print("2130   【新手教程,你包看的】           \n", 1);
    print("1      【千军万马,血战到底】无武将\n", 1);
    print("2      【纷争四起,一骑绝尘】有武将\n", 1);
    print("3      【联机对决,一分高下】有武将\n", 1);
    int choice;
    cin >> choice;
    if (choice == 1)
    {
        GameMode1();
    }
    else if (choice == 2)
    {
        GameMode2();
    }
    else
    {
        Internet_Gamemode();
    }
}

int main()
{
    srand(time(0));
    print("欢迎回来!正在读取存档...\n", 2);
    Read();
    Sleep(1000);
    print("读取完毕,开始您的旅程吧!!!\n\n\n", 2);
    print("警告:退出游戏前一定要存档!!!", 4);
    lobby();
    return 0;
}

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值