做app還是網(wǎng)站太原百度seo排名軟件
思路主要包括以下幾個部分:
-
角色分配:代碼中通過隨機數(shù)的方式給狼人、平民、預(yù)言家和法師等角色進(jìn)行分配,保證每個角色的數(shù)量和身份的隨機性。
-
游戲進(jìn)行:根據(jù)狼人、平民、預(yù)言家和法師等角色的身份,游戲進(jìn)行了夜晚和白天的交替,每個角色根據(jù)自己的身份進(jìn)行相應(yīng)的行動,比如狼人選擇殺人、預(yù)言家選擇預(yù)言等。
-
游戲結(jié)束條件:游戲根據(jù)角色的行動和玩家的投票,判斷游戲是否結(jié)束,比如狼人全部被殺死或者平民被全部殺死等。
#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(){//主函數(shù)sfs[0].sf="平民";sfs[1].sf="預(yù)言家";sfs[2].sf="法師";sfs[3].sf="狼";cout<<" 狼 :1 平:3 預(yù):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<<"今晚你要預(yù)言幾號";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;//返回值 }