#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<ctime>
#include<windows.h>
#include<cstring>
using namespace std;
int chance_wj=0,chance_dn=0;//分别代表玩家机会和电脑机会,1有0无
bool game=1;//代表游戏状态,1真0假,状态为真时可正常运行
int wjsl=0,dnsl=0;//分别代表玩家闪亮(登场)、电脑闪亮(登场) 1真0假
int dnnj=1,dnmy=1,wjnj=1,wjmy=1;//分别代表电脑脑浆、电脑门牙、玩家脑浆、玩家门牙 1有0无
int wjqj=1,dnqj=1;//分别代表玩家抢救和电脑抢救状态 1有效0无效
int pos_wj=0,pos_dn=1;//0代表玩家的家,1代表电脑的家,2代表医院,3代表火化场
string success;//判断获胜方
inline void initial()
{
chance_wj=0,chance_dn=0;
game=1;
wjsl=0,dnsl=0;
dnnj=1,dnmy=1,wjnj=1,wjmy=1;
wjqj=1,dnqj=1;
pos_wj=0,pos_dn=1;
string success;
}
inline int random()//随机数函数
{
srand((unsigned)time(NULL));
int res=rand()%3+1;
return res;
}
inline void printstate(int a,int b,int c,int d,int e,int f,int g,int h,int i,int j) //分别代表玩家闪亮a、电脑闪亮b、电脑脑浆c、电脑门牙d、玩家脑浆e、玩家门牙f、玩家抢救g、电脑抢救h、玩家位置i、电脑位置j
{
cout<<"此时的情形如下:"<<endl;
if(a==1)
{
Sleep(100);
cout<<"玩家已闪亮登场,";
}
else
{
Sleep(100);
cout<<"玩家未闪亮登场,";
}
if(e==1)
{
Sleep(100);
cout<<"玩家脑浆还在,";
}
else
{
Sleep(100);
cout<<"玩家脑浆已没,";
}
if(f==1)
{
Sleep(100);
cout<<"门牙还在,";
}
else
{
Sleep(100);
cout<<"门牙已没,";
}
if(g==1)
{
Sleep(100);
cout<<"抢救有效,";
}
else
{
Sleep(100);
cout<<"抢救无效,";
}
Sleep(100);
cout<<"位置在";
switch(i)
{
case 0: cout<<"玩家家";break;
case 1: cout<<"电脑家";break;
case 2: cout<<"医院";break;
case 3: cout<<"火化场";break;
default: cout<<"位置显示错误!";
}
cout<<endl;
if(b==1)
{
Sleep(100);
cout<<"电脑已闪亮登场,";
}
else
{
Sleep(100);
cout<<"电脑未闪亮登场,";
}
if(c==1)
{
Sleep(100);
cout<<"电脑脑浆还在,";
}
else
{
Sleep(100);
cout<<"玩家脑浆已没,";
}
if(d==1)
{
Sleep(100);
cout<<"门牙还在,";
}
else
{
Sleep(100);
cout<<"门牙已没,";
}
if(h==1)
{
Sleep(100);
cout<<"抢救有效,";
}
else
{
Sleep(100);
cout<<"抢救无效,";
}
Sleep(100);
cout<<"位置在";
switch(j)
{
case 0: cout<<"玩家家";break;
case 1: cout<<"电脑家";break;
case 2: cout<<"医院";break;
case 3: cout<<"火化场";break;
default: cout<<"位置显示错误!";
}
cout<<endl;
return;
}
inline void caiquan()//猜拳函数
{
Sleep(1500);
system("cls");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |
FOREGROUND_BLUE);
printstate(wjsl,dnsl,dnnj,dnmy,wjnj,wjmy,wjqj,dnqj,pos_wj,pos_dn);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE);
cout<<"[系统提示]石头剪子布:1代表石头,2代表剪子,3代表布"<<endl;
for( ; ; )
{
int wj;
cin>>wj;
int dn=random();
if(wj==1 and dn==1)
{
Sleep(500);
cout<<"[系统提示]玩家和电脑均出石头,平局,继续";
}
if(wj==2 and dn==2)
{
Sleep(500);
cout<<"[系统提示]玩家和电脑均出剪子,平局,继续";
}
if(wj==3 and dn==3)
{
Sleep(500);
cout<<"[系统提示]玩家和电脑均出布,平局,继续";
}
if(wj==1 and dn==2)
{
Sleep(500);
cout<<"[系统提示]玩家出石头,电脑出剪子,玩家赢"<<endl;
cout<<"[系统提示]玩家获得一次行动机会,请行动"<<endl;
chance_wj++;
}
if(wj==2 and dn==3)
{
Sleep(500);
cout<<"[系统提示]玩家出剪子,电脑出布,玩家赢"<<endl;
cout<<"[系统提示]玩家获得一次行动机会,请行动"<<endl;
chance_wj++;
}
if(wj==3 and dn==1)
{
Sleep(500);
cout<<"[系统提示]玩家出布,电脑出石头,玩家赢"<<endl;
cout<<"[系统提示]玩家获得一次行动机会,请行动"<<endl;
chance_wj++;
}
if(wj==1 and dn==3)
{
Sleep(500);
cout<<"[系统提示]玩家出石头,电脑出布,电脑赢"<<endl;
cout<<"[系统提示]电脑获得一次行动机会"<<endl;
chance_dn++;
}
if(wj==2 and dn==1)
{
Sleep(500);
cout<<"[系统提示]玩家出剪子,电脑出石头,电脑赢"<<endl;
cout<<"[系统提示]电脑获得一次行动机会"<<endl;
chance_dn++;
}
if(wj==3 and dn==2)
{
Sleep(500);
cout<<"[系统提示]玩家出布,电脑出剪子,电脑赢"<<endl;
cout<<"[系统提示]电脑获得一次行动机会"<<endl;
chance_dn++;
}
if(wj!=1 and wj!=2 and wj!=3)
{
Sleep(500);
cout<<"输入无效,请重新输入。"<<endl;
}
putchar('\n');
if(wj!=dn) break;
}
}
int main()
{
START:
system("cls");
initial();
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE);
Sleep(500);
cout<<"[系统提示]准备好了吗?游戏还有5秒即将开始!";
Sleep(1000);
putchar('\n');
system("cls");
cout<<5<<endl;
Sleep(999);
system("cls");
cout<<4<<endl;
Sleep(999);
system("cls");
cout<<3<<endl;
Sleep(999);
system("cls");
cout<<2<<endl;
Sleep(999);
system("cls");
cout<<1<<endl;
Sleep(999);
system("cls");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
while(game==1)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE);
caiquan();
if(chance_wj==1)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
Sleep(500);
cout<<"[系统提示]请行动:1代表闪亮登场,2代表去找人,3代表要进攻,4代表要送人,5代表要踢人,6代表要火化,7代表要前往某地"<<endl;
int wj1;
cin>>wj1;
if(wj1==1)
{
if(wjsl==0)
{
Sleep(500);
cout<<"我:闪亮登场"<<endl;
wjsl=1;
}
else cout<<"[系统提示]你已经闪亮登场了,憋"<<endl;
}
else if(wj1==2 or wj1==3 or wj1==4 or wj1==5 or wj1==6 or wj1==7)
{
if(wjsl==0) cout<<"[系统提示]你还没有闪亮登场,憋"<<endl;
else
{
if(wj1==2)
{
if(pos_wj==pos_dn) cout<<"[系统提示]你和电脑已经在一起了,憋"<<endl;
else
{
Sleep(500);
cout<<"我:找到你"<<endl;
pos_wj=pos_dn;
}
}
if(wj1==3)
{
if(pos_wj!=pos_dn) cout<<"[系统提示]你和电脑不在一起,憋"<<endl;
else
{
Sleep(500);
cout<<"[系统提示]请选择你要进攻的方式:1代表打出脑浆,2代表打掉门牙,3代表抢救无效"<<endl;
int wj2;
cin>>wj2;
if(wj2==1)
{
if(dnnj==0) cout<<"[系统提示]电脑已经没有脑浆了,憋"<<endl;
else
{
Sleep(500);
cout<<"我:打出脑浆"<<endl;
dnnj=0;
}
}
else if(wj2==2)
{
if(dnnj==1) cout<<"[系统提示]电脑脑浆还有,憋" <<endl;
else
{
if(dnmy==0) cout<<"[系统提示]电脑已经没有门牙了,憋"<<endl;
else
{
Sleep(500);
cout<<"我:打掉门牙"<<endl;
dnmy=0;
}
}
}
else if(wj2==3)
{
if(!(pos_wj==2 and pos_dn==2)) cout<<"[系统提示]你和电脑不同时在医院,憋"<<endl;
else
{
if(dnnj==1) cout<<"[系统提示]电脑脑浆还有,憋"<<endl;
else
{
if(dnmy==1) cout<<"[系统提示]电脑门牙还有,憋"<<endl;
else
{
if(dnqj==0) cout<<"[系统提示]电脑已经被抢救无效了,憋"<<endl;
else
{
Sleep(500);
cout<<"我:抢救无效"<<endl;
dnqj=0;
}
}
}
}
}
else cout<<"[系统提示]没有该选项,憋";
}
}
if(wj1==4)
{
if(pos_wj!=pos_dn) cout<<"[系统提示]你和电脑不在一起,憋"<<endl;
else
{
Sleep(500);
cout<<"[系统提示]请选择你要送的目的地:0玩家家,1代表电脑家,2代表医院,3代表火化场"<<endl;
int wj3;
cin>>wj3;
if(wj3==0)
{
if(pos_wj==0) cout<<"[系统提示]你和电脑已经在玩家家了,憋"<<endl;
else
{
Sleep(500);
cout<<"我:送回我家"<<endl;
pos_wj=0;
pos_dn=0;
}
}
else if(wj3==1)
{
if(pos_wj==1) cout<<"[系统提示]你和电脑已经在电脑家了,憋"<<endl;
else
{
Sleep(500);
cout<<"我:送到你家"<<endl;
pos_wj=1;
pos_dn=1;
}
}
else if(wj3==2)
{
if(pos_wj==2) cout<<"[系统提示]你和电脑已经在医院了,憋"<<endl;
else
{
Sleep(500);
cout<<"我:送进医院"<<endl;
pos_wj=2;
pos_dn=2;
}
}
else if(wj3==3)
{
if(pos_wj==3) cout<<"[系统提示]你和电脑已经在火化场了,憋"<<endl;
else
{
Sleep(500);
cout<<"我:送进火化场"<<endl;
pos_wj=3;
pos_dn=3;
}
}
else cout<<"[系统提示]没有该选项,憋"<<endl;
}
}
if(wj1==5)
{
if(pos_wj!=pos_dn) cout<<"[系统提示]你和电脑不在一起,憋";
else
{
Sleep(500);
cout<<"[系统提示]请选择你要踢的目的地:0玩家家,1代表电脑家,2代表医院,3代表火化场"<<endl;
int wj4;
cin>>wj4;
if(wj4==0)
{
if(pos_wj==0) cout<<"[系统提示]你和电脑已经在玩家家了,憋"<<endl;
else
{
Sleep(500);
cout<<"我:踢到我家"<<endl;
pos_dn=0;
}
}
else if(wj4==1)
{
if(pos_wj==1) cout<<"[系统提示]你和电脑已经在电脑家了,憋"<<endl;
else
{
Sleep(500);
cout<<"我:踢回你家"<<endl;
pos_dn=1;
}
}
else if(wj4==2)
{
if(pos_wj==2) cout<<"[系统提示]你和电脑已经在医院了,憋"<<endl;
else
{
Sleep(500);
cout<<"我:踢进医院"<<endl;
pos_dn=2;
}
}
else if(wj4==3)
{
if(pos_wj==3) cout<<"[系统提示]你和电脑已经在火化场了,憋"<<endl;
else
{
Sleep(500);
cout<<"我:踢进火化场"<<endl;
pos_dn=3;
}
}
else cout<<"[系统提示]没有该选项,憋"<<endl;
}
}
if(wj1==6)
{
if(!(pos_wj==3 and pos_dn==3)) cout<<"[系统提示]你和电脑不同时在火化场,憋"<<endl;
else
{
if(!(dnnj==0)) cout<<"[系统提示]电脑脑浆还有,憋"<<endl;
else
{
if(!(dnmy==0)) cout<<"[系统提示]电脑门牙还有,憋"<<endl;
else
{
if(!(dnqj==0)) cout<<"[系统提示]电脑抢救还有效,憋"<<endl;
else
{
Sleep(500);
cout<<"我:火化"<<endl;
success="wj";
game=0;
break;
}
}
}
}
}
if(wj1==7)
{
cout<<"[系统提示]请选择你要前往的目的地:0玩家家,1代表电脑家,2代表医院,3代表火化场"<<endl;
int wj5;
cin>>wj5;
if(wj5==0)
{
if(pos_wj==0) cout<<"[系统提示]你已经在玩家家了,憋"<<endl;
else
{
Sleep(500);
cout<<"我:回到我家"<<endl;
pos_wj=0;
}
}
else if(wj5==1)
{
if(pos_wj==1) cout<<"[系统提示]你已经在电脑家了,憋"<<endl;
else
{
Sleep(500);
cout<<"我:冲进你家"<<endl;
pos_wj=1;
}
}
else if(wj5==2)
{
if(pos_wj==2) cout<<"[系统提示]你已经在医院了,憋"<<endl;
else
{
Sleep(500);
cout<<"我:去医院"<<endl;
pos_wj=2;
}
}
else if(wj5==3)
{
if(pos_wj==3) cout<<"[系统提示]你已经在火化场了,憋"<<endl;
else
{
Sleep(500);
cout<<"我:去火化场"<<endl;
pos_wj=3;
}
}
else cout<<"[系统提示]没有该选项,憋"<<endl;
}
}
}
else cout<<"[系统提示]没有该选项,憋"<<endl;
}
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
if(chance_dn==1)
{
if(dnsl==0)
{
Sleep(500);
cout<<"电脑:闪亮登场"<<endl;
dnsl=1;
}
else
{
if(pos_dn==3 and pos_wj==3 and wjqj==0)
{
Sleep(500);
cout<<"电脑:火化"<<endl;
success="dn";
game=0;
break;
}
if(pos_dn!=pos_wj)
{
Sleep(500);
cout<<"电脑:找到你"<<endl;
pos_dn=pos_wj;
}
else
{
if(wjnj==1)
{
Sleep(500);
cout<<"电脑:打出脑浆"<<endl;
wjnj=0;
}
else
{
if(wjmy==1)
{
Sleep(500);
cout<<"电脑:打掉门牙"<<endl;
wjmy=0;
}
else
{
if(wjqj==0)
{
Sleep(500);
cout<<"电脑:送进火化场"<<endl;
pos_wj=3;
pos_dn=3;
}
if(wjqj==1)
{
if(pos_dn!=2)
{
Sleep(500);
cout<<"电脑:送进医院"<<endl;
pos_dn=2;
pos_wj=2;
}
else
{
Sleep(500);
cout<<"电脑:抢救无效"<<endl;
wjqj=0;
}
}
}
}
}
}
}
chance_wj=0,chance_dn=0;
}
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |
FOREGROUND_GREEN);
putchar('\n');
Sleep(1000);
cout<<"游戏结束了! ";
if(success=="wj") cout<<"玩家获胜!"<<endl;
else if(success=="dn") cout<<"电脑获胜!"<<endl;
ASK:
printf("下一局游戏吗?0代表否,1代表是\n");
int p;
scanf("%d",&p);
if(p==0) return 0;
else if(p==1) goto START;
else
{
Sleep(200);
printf("输入无效,请重新输入。\n");
goto ASK;
}
return 0;
}
上述为闪亮登场升级版代码,欢迎大家复制到自己的本地编译器与电脑大战!我胜率不到20%...