3个C++小游戏

我来分享一下,我从csdn上搜集3个小游戏。

1.狼人杀

#include <Windows.h>
#include <conio.h>
#include<bits/stdc++.h> 
using namespace std;
void brc()
{
system("cls");
int jy=1;
int sy=3;
srand((int)time(0));
int n=rand()%15+1;
cout<<" 你是"<<n<<"号"<<endl;
cout<<" 正在分配身份"<<endl;
Sleep(1500);
int m[20];
for(int i=1; i<=15; i++)
m[i]=1;
int s[20]= {0};
int yy[20]= {0};
int l=0,w=0,j=0,p=0;
for(int i=1; i<=15; i++)
{
do
{
int a=rand()%4+1;
if(a==1&&l<2)
{            
l++;
            s[i]=1;
        }
        else if(a==2&&w<2)
        {
            w++;
            s[i]=2;
        }
        else if(a==4&&p<1)
        {
            p++;
            s[i]=4;
        }
        else if(a==3&&j<10)
        {
            j++;
            s[i]=3;
        }
    }
    while(s[i]==0);
}
if(s[n]==1)
    cout<<"                               你是>>杀手<<"<<endl;
else if(s[n]==2)
    cout<<"                               你是>>预言家<<"<<endl;
else if(s[n]==3)
    cout<<"                               你是>>平民<<"<<endl;
else
    cout<<"                               你是>>女巫<<"<<endl;
cout<<"                             游戏将在5秒后开始"<<endl;
Sleep(5000);
int c=15;
int f=0,flag=0;
int day=1;
int lr;
int tp[20]= {0};
do
{
    lr=0;
    system("cls");
    cout<<"                                 第"<<day<<"晚开始"<<endl;
    int x;
    for(int i=1; i<=15; i++)
    {
        if(i==n&&m[n]==1)
        {
            if(s[n]==1)
            {
                cout<<"                                 你是杀手"<<endl;
                for(int j=1; j<=15; j++)
                    if(m[j]==1&&s[j]!=1)
                        cout<<j<<" ";
                cout<<endl;
                cout<<"                                 你选择杀掉"<<endl;
                int a;
                cin>>a;
                m[a]=0;
                cout<<endl;
                cout<<"                                 杀手杀了"<<a<<"号";
                if(s[a]==1)
                    cout<<"(杀手)"<<endl;
                else if(s[a]==2)
                    cout<<"(预言家)"<<endl;
                else if(s[a]==3)
                    cout<<"(平民)"<<endl;
                else
                    cout<<"(女巫)"<<endl;
                c--;
            }
            else if(s[n]==2)
            {
                cout<<"                                 你是预言家"<<endl;
                cout<<"                               ";
                for(int j=1; j<=15; j++)
                    if(m[j]==1)
                        cout<<j<<" ";
                cout<<endl;
                cout<<"                              你选择预言谁的身份"<<endl;
                int a;
                cin>>a;
                if(s[a]==1)
                {
                    cout<<"                        "<<a<<"号是杀手,请注意"<<endl;
                    Sleep(1000);
                }
                else
                    cout<<"                            "<<a<<"号是平民"<<endl;
            }
        }
        else if(s[i]==1&&m[i]==1)
        {
            int a;
            do
            {
                a=rand()%15+1;
            }
            while(a==i||m[a]==0||s[a]==1);
            cout<<"                           杀手杀掉了"<<a<<"号";
            if(s[a]==1)
                cout<<"(杀手)"<<endl;
            else if(s[a]==2)
                cout<<"(预言家)"<<endl;
            else if(s[a]==3)
                cout<<"(平民)"<<endl;
            else
                cout<<"(女巫)"<<endl;
            m[a]=0;
            c--;
        }
        else if(s[i]==2)
        {
            if(flag==0||m[flag]==0)
            {
                int a;
                do
                {
                    a=rand()%15+1;
                }
                while(a==i||m[a]==0);
                if(s[a]==1)
                    yy[a]=1;
                else if(s[a]==3)
                    yy[a]=3;
            }
        }
        else if(s[i]==4)
        {
            f=0;
            while(f==0)
            {
                int a;
                a=rand()%2+1;
                if(a==1)
                {
                    if(sy>0)
                    {
                        sy--;
                        f=1;
                        int b;
                        do
                        {
                            b=rand()%15+1;
                            b=rand()%15+1;
                        }
                        while(b==i||m[b]==0);
                        m[b]=0;
                        cout<<"                           女巫毒死了"<<b<<"号";
                        if(s[b]==1)
                            cout<<"(杀手)"<<endl;
                        else if(s[b]==2)
                            cout<<"(预言家)"<<endl;
                        else if(s[b]==3)
                            cout<<"(平民)"<<endl;
                        c--;
                    }
                }
                else if(a==2&&day>1)
                {
                    if(jy>0)
                    {
                        jy--;
                        f=1;
                        int b;
                        do
                        {
                            b=rand()%15+1;
                        }
                        while(b==i||m[b]==1);
                        c++;
                        cout<<"                           女巫复活了"<<b<<"号"<<endl;
                        m[b]=1;
                    }
                }

            }
        }
    }
    if(s[n]==4)
    {
        cout<<"                                 你是女巫"<<endl;
        cout<<"存活状况:"<<endl;
        for(int j=1; j<=15; j++)
            if(m[j]==1)
                cout<<j<<" ";
        cout<<endl;
        cout<<"                        你选择 1.* 杀 *还是 2.* 救 *"<<endl;
        int a,f=0;
        while(f==0)
        {
            cin>>a;
            if(a==1)
            {
                if(sy>0)
                {
                    sy--;
                    f=1;
                    cout<<"                                你选择了杀人"<<endl;
                    for(int i=1; i<=15; i++)
                        if(m[i]==1)
                            cout<<i<<" ";
                    cout<<endl;
                    int b;
                    cin>>b;
                    if(s[b]==1)
                        cout<<"(杀手)"<<endl;
                    else if(s[b]==2)
                        cout<<"(预言家)"<<endl;
                    else if(s[b]==3)
                        cout<<"(平民)"<<endl;
                    else
                        cout<<"(女巫)"<<endl;
                    m[b]=0;
                    c--;
                }
                else
                {
                    cout<<">>毒药<<不足"<<endl;
                }
            }
            else if(a==2)
            {
                if(jy>0)
                {
                    jy--;
                    f=1;
                    cout<<"你选择了复活"<<endl;
                    cout<<"阵亡名单:"<<endl;
                    for(int i=1; i<=15; i++)
                        if(m[i]==0)
                            cout<<i<<"号,身份:"<<s[i]<<" "<<endl;;
                    int b;
                    cin>>b;
                    m[b]=1;
                    c++;
                }
                else
                {
                    cout<<">>复活药水<<不足"<<endl;
                }
            }
        }
    }


    Sleep(1000);
    double p[20]= {0};
    cout<<"                                 第"<<day<<"晚结束"<<endl;
    cout<<endl;
    if(m[n]==0)
    {
        cout<<"                             你已经>>死<<了";
        break;
    }

    cout<<"                                    存活:"<<endl;
    cout<<"                       ";
    for(int i=1; i<=15; i++)
        if(m[i]==1)
            cout<<i<<" ";
    cout<<endl;
    cout<<"                                    请投票...."<<endl;
    for(int i=1; i<=15; i++)
    {
        if(i==n&&m[n]==1)
        {
            cout<<endl;
            cout<<"                                 你选择投几号"<<endl;
            int a=99;
            while(a==99)
            {
                cin>>a;
                if(a==99)
                    for(int i=1; i<=15; i++)
                        if(m[i]==1)
                            cout<<"                                    "<<i<
  • 5
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值