当前位置: 首页 > news >正文

c++_游戏_狼人杀

思路主要包括以下几个部分:

  1. 角色分配:代码中通过随机数的方式给狼人、平民、预言家和法师等角色进行分配,保证每个角色的数量和身份的随机性。

  2. 游戏进行:根据狼人、平民、预言家和法师等角色的身份,游戏进行了夜晚和白天的交替,每个角色根据自己的身份进行相应的行动,比如狼人选择杀人、预言家选择预言等。

  3. 游戏结束条件:游戏根据角色的行动和玩家的投票,判断游戏是否结束,比如狼人全部被杀死或者平民被全部杀死等。

    #include <bits/stdc++.h>
    #include <windows.h>
    #include <conio.h>
    #include <stdlib.h>
    #include <stdio.h>
    #define random(a,b) (rand()%(b-a+1)+a)
    using namespace std;//命名空间
    int a[6]={0,0,0,0,0,0};
    struct node{string sf;
    }sfs[4];
    void wolf(){int x;x= random(1,6);a[x-1]=3;return ;
    }
    void yu(){int x,y=0;while(y==0){x= random(1,6);if(a[x-1]==0){y=1;a[x-1]=1;return ;}}
    }
    void fa(){int x,y=0;while(y==0){x= random(1,6);if(a[x-1]==0){y=1;a[x-1]=2;return ;}}
    }
    void printsetence(string &text, int interval) {int n = text.length();for (int i=0; i<n; i++) {cout<<text[i];Sleep(interval);}return;
    }
    int main(){//主函数sfs[0].sf="平民";sfs[1].sf="预言家";sfs[2].sf="法师";sfs[3].sf="狼";cout<<" 狼 :1 平:3 预:1 法:1" <<endl;srand((unsigned)time(NULL));wolf();srand((unsigned)time(NULL));fa();srand((unsigned)time(NULL));yu();system("color 87") ;system("pause") ;system("cls");string text = "你是1号,你的身份是:";printsetence(text,25);cout<<sfs[a[0]].sf<<endl;system("color 87") ;system("pause") ;system("cls");int tian=0; while(1){tian++;cout<<"第"<<tian<<"夜";system("color 87") ;system("pause") ;system("cls");int flag=0;if(a[0]==3){flag=1;int shu;cout<<"你要刀几号?"<<endl;cin>>shu;a[shu-1]+=4;system("color 87") ;system("pause") ;system("cls");}else if(a[0]==2){cout<<"今晚你要毒还是救";string shu1;cin>>shu1;system("color 87") ;system("pause") ;system("cls");if(shu1=="毒"){cout<<"你要毒几号" ;int shu;cin>>shu;a[shu-1]+=4;}else{cout<<"你要救几号" ;int shu; cin>>shu;if(a[shu-1]>=4){a[shu-1]-=4;}}system("color 87") ;system("pause") ;system("cls");}else if(a[0]==1){cout<<"今晚你要预言几号";int shu;cin>>shu;system("color 87") ;system("pause") ;system("cls");cout<<"他的身份是";cout<<sfs[a[shu-1]].sf<<endl;system("color 87") ;system("pause") ;system("cls");}else{int flagg=0;while(flagg==0) {srand((unsigned)time(NULL));int b=random(1,6);if(a[b-1]<4){flagg=1;a[b-1]+=4;}}	} if(flag==0){srand((unsigned)time(NULL));a[random(1,6)-1]+=4;}int sum=0;cout<<"天亮了,过了今晚还剩";for(int i=0;i<6;i++){if(a[i]<4){cout<<i+1<<"号"<<" ";sum++;}else if(i==0){system("pause") ;system("cls");cout<<"你被杀了"<<endl;system("pause") ;system("cls");return 0;}else if(a[i]==7){cout<<"狼死了";system("color 87") ;system("pause") ;system("cls");return 0;}} system("color 87") ;system("pause") ;system("cls");int mx=0,mxx,n,piao[6]={0,0,0,0,0,0};cout<<"请投票"<<endl;cin>> n;piao[n-1]++;sum-=1;while(sum--){srand((unsigned)time(NULL));piao[random(1,6)-1]++;}for(int i=0;i<6;i++){cout<<i+1<<"号:"<<piao[i]<<"票 "; if(mx<piao[i]){mx=piao[i];mxx=i+1;}}cout<<endl;cout<<mxx<<"号出局"<<endl;if(mxx-1==0){system("pause") ;system("cls");cout<<"你被票了"<<endl;system("pause") ;system("cls");return 0;}a[mxx-1]+=4;if(a[mxx-1]==7){cout<<"他是狼"; system("color 87") ;system("pause") ;system("cls");return 0;//返回值}}return 0;//返回值
    }

http://www.lryc.cn/news/418223.html

相关文章:

  • MySQL——数据类型、索引的建立、数据的约束
  • 常见框架漏洞详解③!!
  • 大数据基础知识
  • SQL Server 的透明数据加密
  • Windows图形界面(GUI)-MFC-C/C++ - 列表视图(List Control) - CListCtrl
  • 一机两用的简单介绍
  • uniapp离线打包热更新失败-AndroidStudio离线打包apk后无法下载打开-热更新失败-plus.runtime.install失败
  • 深植根基、蓬勃向上 | openKylin 2.0正式发布!
  • 【Material-UI】按钮组:尺寸与颜色详解
  • app抓包 burp配置
  • 图像与像素:利用ImageJ分析荧光显微镜图像|QuPath基础教程1|24-08-08
  • Prompt Fuzzer:用于增强 GenAI 应用程序的开源工具
  • Vision Pro使用GLFT 加载模型shader错误解决办法
  • Netty技术全解析:MessageToMessageCodec类深度解析
  • Three 【3D车模换肤】
  • 语言模型简介和Ngram模型(1)
  • MessageBox弹框替代系统自带的alert、confirm -- 高仿ElementUI MessageBox
  • 数据结构一排序算法
  • [Leetcode 215][Medium]-数组中的第K个最大元素-快排/小根堆/堆排序
  • 【栈和队列】常见面试题
  • 关于float浮点值二进制存储和运算精度损失的话题
  • python爬虫学习记录-请求模块urllib3
  • 谷粒商城实战笔记-133~135-城业务-商品上架-远程上架接口
  • 【React】详解 App.js 文件
  • 【ML】self-supervised Learning for speech and Image
  • 青岛实训day24(8/8)
  • *算法训练(leetcode)第四十五天 | 101. 孤岛的总面积、102. 沉没孤岛、103. 水流问题、104. 建造最大岛屿
  • 设计模式 由浅入深(待完结)
  • (第34天)645、最大二叉树
  • Python知识点:如何使用Paramiko进行SSH连接与操作