r语言编程游戏逻辑

//用C语言写的,玩石头剪刀布的小游戏。下面是源代码。

# include & ltstdio.h & gt

# include & ltstdlib.h & gt

int main()

{

Char cq[][10]={ "石头","剪刀","布" };

int guess=-1,r,youwin=0,mewin=0,daping=0,total = 0;

srand(time(NULL));

while(1)

{

r =(int)((RAND()/(RAND _ MAX+1.0))* 3);

Printf("0,Stone \n1,剪刀\n2,布\n3,退出\ nI'm out,please:");

scanf("%d ",& amp猜测);

if(3==guess)

{

打破;

}

其他

{

total++;

Printf("这次你给了%s,我给了%s,所以",cq[guess],CQ[r]);

if(0 = = guess & amp;& amp1==r ||& amp2 = = r | | 2 = = guess & amp& amp0==r)

{

you win++;

Printf("你赢了!\ n ");

}

else if(guess==r)

{

大平++;

Printf("我们扯平了!\ n ");

}

其他

{

mewin++;

Printf("我赢了!\ n ");

}

}

}

Printf("一共玩了%d次,你赢了%d次,我赢了%d次,平了%d次!\n”、total、youwin、mewin、大平);

系统(“暂停”);

返回EXIT _ SUCCESS

}