c++小游戏大集结【免费复制源码】

代码来了!!!

1.狼人杀

        这是一个小游戏,感兴趣的可以看看

                代码如下:

#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<windows.h>
using namespace std;
struct IDname
{
    int geshu;
    string NAME;
};
IDname jue_se[100];
struct ID
{
    int num;
    bool life;
    string name;
    int know;
    int how;
};
ID player[21];
int n, MY, kill1, kill2;
char a;
bool jieyao = 1, duyao = 1;
int lieren, shouwei = 0;
void init1()
{
    jue_se[1].NAME = "村民 ";
    jue_se[2].NAME = "狼人 ";
    jue_se[3].NAME = "女巫 ";
    jue_se[4].NAME = "预言家 ";
    jue_se[5].NAME = "猎人 ";
    jue_se[6].NAME = "守卫 ";
}
void init2(int nn)
{
    switch (nn)
    {
    case 6:
        jue_se[1].geshu = 3;
        jue_se[2].geshu = 2;
        jue_se[3].geshu = 1;
        jue_se[4].geshu = 0;
        jue_se[5].geshu = 0;
        jue_se[6].geshu = 0;
        break;
    case 7:
        jue_se[1].geshu = 3;
        jue_se[2].geshu = 2;
        jue_se[3].geshu = 1;
        jue_se[4].geshu = 1;
        jue_se[5].geshu = 0;
        jue_se[6].geshu = 0;
        break;
    case 8:
        jue_se[1].geshu = 3;
        jue_se[2].geshu = 3;
        jue_se[3].geshu = 1;
        jue_se[4].geshu = 1;
        jue_se[5].geshu = 0;
        jue_se[6].geshu = 0;
        break;
    case 9:
        jue_se[1].geshu = 3;
        jue_se[2].geshu = 3;
        jue_se[3].geshu = 1;
        jue_se[4].geshu = 1;
        jue_se[5].geshu = 1;
        jue_se[6].geshu = 0;
        break;
    case 10:
        jue_se[1].geshu = 4;
        jue_se[2].geshu = 3;
        jue_se[3].geshu = 1;
        jue_se[4].geshu = 1;
        jue_se[5].geshu = 1;
        jue_se[6].geshu = 0;
        break;
    case 11:
        jue_se[1].geshu = 4;
        jue_se[2].geshu = 4;
        jue_se[3].geshu = 1;
        jue_se[4].geshu = 1;
        jue_se[5].geshu = 1;
        jue_se[6].geshu = 0;
        break;
    case 12:
        jue_se[1].geshu = 4;
        jue_se[2].geshu = 4;
        jue_se[3].geshu = 1;
        jue_se[4].geshu = 1;
        jue_se[5].geshu = 1;
        jue_se[6].geshu = 1;
        break;
    default:
        cout << "输入错误,再见" << endl;
        exit(0);
        break;
    }
}
int van[10] = { 7,4,6,43,35,1,2,8,20,19 };
void init3(int nn)
{
    srand(time(0));
    Sleep(rand() % 44);
    int x = 10000;
    int t = rand();
    srand(time(NULL));
    int y = van[(rand() % 100 * van[rand() % 10] + t) % 10];
    if (nn <= 6)
        x = abs(x * 6 / y) % 3 + 1;
    else if (nn <= 8)
        x = abs(x * 7 / y) % 4 + 1;
    else if (nn <= 11)
        x = abs(x * 8 / y) % 5 + 1;
    else if (nn <= 14)
        x = abs(x * 9 / y) % 6 + 1;
    do
    {
        if (nn <= 6)
            x = x % 3 + 1;
        else if (nn <= 8)
            x = x % 4 + 1;
        else if (nn <= 11)
            x = x % 5 + 1;
        else if (nn <= 14)
            x = x % 6 + 1;
        if (jue_se[x].geshu > 0)
        {
            player[nn].name = jue_se[x].NAME;
            if (player[nn].name == "猎人 ")
                lieren = nn;
            if (player[nn].name == "守卫 ")
                shouwei = nn;
            player[nn].life = 1;
            player[nn].num = nn;
            player[nn].know = 0;
            jue_se[x].geshu--;
            player[nn].how = 0;
            break;
        }
    } while (jue_se[x].geshu == 0);
}
void printhhh()
{
    int cm = 0;
    int sz = 0;
    for (int i = 1; i <= n; i++)
    {
        if (player[i].life == 0)
            continue;
        else if (player[i].name == "村民 ")
            cm++;
        else if (player[i].name == "女巫 " || player[i].name == "预言家 " || player[i].name == "猎人 " || player[i].name == "守卫 ")
            sz++;
    }
    if (sz == 0 || cm == 0)
        cout << "狼人阵营胜利" << endl;
    else
        cout << "好人阵营胜利" << endl;
    for (int i = 1; i <= n; i++)
    {
        cout << left << setw(3) << player[i].num << ": " << player[i].name << " ";
        if (player[i].life == 0)
            cout << "死亡" << "\t";
        else
            cout << "存活" << "\t";
        if (player[i].how == 0)
            cout << "最终存活 " << endl;
        else if (player[i].how == 1)
            cout << "最终被狼人杀死" << endl;
        else if (player[i].how == 2)
            cout << "最终被投票投死" << endl;
        else if (player[i].how == 3)
            cout << "最终被女巫毒死" << endl;
        else if (player[i].how == 4)
            cout << "最终被猎人射杀" << endl;
    }
    system("pause");
    system("pause");
    system("pause");
}
void print(int day, int ti)
{
    HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
    if (ti == 0)
        SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY);
    else
        SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
    cout << "\t\t\t\t第" << day << "天 ";
    if (ti == 0)
        cout << "白天" << endl;
    else
        cout << "夜晚" << endl;
    cout << "我的位置:" << MY << "号" << endl;
    for (int i = 1; i <= 6; i++)
    {
        cout << player[i].num << "号位 ";
    }
    cout << endl;
    for (int i = 1; i <= 6; i++)
    {
        if (player[i].life == 1)
        {
            if (ti == 0)
                SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY | FOREGROUND_GREEN);
            else
                SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_GREEN);
            cout << "存活 ";
        }
        else
        {
            if (ti == 0)
                SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY | FOREGROUND_RED);
            else
                SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED);
            cout << "已死亡 ";
        }
    }
    if (ti == 0)
        SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY);
    else
        SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
    cout << endl;
    for (int i = 1; i <= 6; i++)
    {
        if (player[i].know == 0)
            cout << "未知 ";
        else if (player[i].know == 1)
        {
            if (player[i].name == "狼人 ")
                cout << "狼人 ";
            else
                cout << "好人 ";
        }
        else if (player[i].know == 2)
            cout << player[i].name << " ";
    }
    cout << endl << endl;
    for (int i = 7; i <= n; i++)
    {
        if (i < 10)
            cout << player[i].num << "号位 ";
        else
            cout << player[i].num << "号位 ";
    }
    cout << endl;
    for (int i = 7; i <= n; i++)
    {
        if (player[i].life == 1)
        {
            if (ti == 0)
                SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY | FOREGROUND_GREEN);
            else
                SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_GREEN);
            cout << "存活 ";
        }
        else
        {
            if (ti == 0)
                SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY | FOREGROUND_RED);
            else
                SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED);
            cout << "已死亡 ";
        }
    }
    if (ti == 0)
        SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY);
    else
        SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
    cout << endl;
    for (int i = 7; i <= n; i++)
    {
        if (player[i].know == 0)
            cout << "未知 ";
        else if (player[i].know == 1)
        {
            if (player[i].name == "狼人 ")
                cout << "狼人 ";
            else
                cout << "好人 ";
        }
        else if (player[i].know == 2)
            cout << player[i].name << " ";
    }
    cout << endl << endl;
}
int shou = 0;
void shoushui(int hhh, int hhhh)
{
    int x;
    Sleep(3000);
    system("cls");
    print(hhh, hhhh);
    cout << "守~卫~请~睁~眼~~~" << endl;
    Sleep(3000);
    system("cls");
    print(hhh, hhhh);
    if (MY == shouwei && player[MY].life == 1)
    {
        cout << "请问你要守护谁?" << endl << "输入:";
        cin >> x;
        while (x == shou || x<1 || x>n || player[x].life == 0)
        {
            cout << "输入错误,请重新输入" << endl << "输入:";
            cin >> x;
        }
        shou = x;
    }
    else if (player[shouwei].life == 1)
    {
        cout << "请问你要守护谁?" << endl;
        Sleep(rand() % 98);
        srand(time(0));
        x = rand() % n + 1;
        while (x == shou || player[x].life == 0)
        {
            Sleep(rand() % 98);
            srand(time(0));
            x = rand() % n + 1;
        }
        shou = x;
    }
    else
    {
        cout << "请问你要守护谁?" << endl;
        Sleep(3000);
        shou = -1;
    }
    Sleep(3000);
    system("cls");
    print(hhh, hhhh);
    cout << "守~卫~请~闭~眼~~~" << endl;
}
struct tou
{
    int xxx;
    int num;
    int toupiaoquan;
};
tou TOU[13];
bool cmp(tou x, tou y)
{
    if (x.xxx == y.xxx)
        return x.num < y.num;
    return x.xxx > y.xxx;
}
bool cmp1(tou x, tou y)
{
    return x.num < y.num;
}
void toupiao(int ddd, int nnn)
{
    //--------1--------
    int x;
    Sleep(2000);
    system("cls");
    print(ddd, nnn);
    cout << "现在大家请投票";
    for (int i = 1; i <= 3; i++)
    {
        cout << ".";
        Sleep(500);
    }
    cout << endl;
    for (int i = 1; i <= n; i++)
    {
        TOU[i].num = i;
        TOU[i].toupiaoquan = 1;
        TOU[i].xxx = 0;
    }
    for (int i = 1; i <= n; i++)
    {
        if (player[i].life == 1)
        {
            Sleep(3000);
            if (i == MY)
            {
                cout << "请投票...(0弃权)" << endl;
                cin >> x;
                while (player[x].life == 0 && x != 0)
                {
                    cin >> x;
                }
                if (x == 0)
                    cout << MY << "号玩家弃权" << endl;
                else
                    cout << MY << "

  • 6
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值