猜拳游戏的游戏结构
# include & ltstdio.h & gt
# include & ltstdlib.h & gt
# include & lttime.h & gt
int?isWin(int,int);//返回:0:平均值。1:玩家赢。2:玩家输了
int?主()
{
夏尔?p,name[3][5]={ "石头","剪刀","布" };
int?n;
srand(time(NULL));
while(1)
{
Printf("请输入你出拳对应的数字:0,石头。1,剪刀。2.布料。\ n ");
scanf("%[0-2]",& ampp);
getchar();
n = rand()% 3;
Printf("计算机:%s?!\ n播放器:%s?!\n ",name[n],name[(p-' 0 ')]);
开关(isWin(n,p-'0 '))
{
案子?0:printf("玩家输了!\ n \ n ");打破;
案子?1:printf("玩家赢了!\ n \ n ");打破;
案子?2:printf ("tie!\ n \ n ");打破;
违约?:?printf(" error \ n \ n ");
}
}
回归?0;
}
int?isWin(int?n1,int?N2)//n1:电脑打卡。N2:玩家出拳。回报:2:一般。1:玩家赢。2:玩家输了
{
if(n1==n2)
回归?2;
if(n2-n1==-1?||?n2-n1==2)
回归?1;
if(n2-n1==1?||?n2-n1==-2)
回归?0;
回归?-1;
}