用C语言编一个小游戏,注明编码,(简单易懂的游戏,不要复杂) 20
1个回答
展开全部
//C语言写的,一个玩石头、剪刀、布的小游戏。下面是源码。
#include<stdio.h>
#include<stdlib.h>
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、石头\n1、剪刀\n2、布\n3、退出\n我已出,请你出:");
scanf("%d",&guess);
if(3==guess)
{
break;
}
else
{
total++;
printf("这一次你出的是%s,我出的是%s,所以",cq[guess],cq[r]);
if(0==guess&&1==r || 1==guess&&2==r || 2==guess&&0==r)
{
youwin++;
printf("你赢了!\n");
}
else if(guess==r)
{
daping++;
printf("我们打平了!\n");
}
else
{
mewin++;
printf("我赢了!\n");
}
}
}
printf("总共玩了%d次,你赢了%d次,我赢了%d次,打平%d次!\n",total,youwin,mewin,daping);
system("PAUSE");
return EXIT_SUCCESS;
}
#include<stdio.h>
#include<stdlib.h>
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、石头\n1、剪刀\n2、布\n3、退出\n我已出,请你出:");
scanf("%d",&guess);
if(3==guess)
{
break;
}
else
{
total++;
printf("这一次你出的是%s,我出的是%s,所以",cq[guess],cq[r]);
if(0==guess&&1==r || 1==guess&&2==r || 2==guess&&0==r)
{
youwin++;
printf("你赢了!\n");
}
else if(guess==r)
{
daping++;
printf("我们打平了!\n");
}
else
{
mewin++;
printf("我赢了!\n");
}
}
}
printf("总共玩了%d次,你赢了%d次,我赢了%d次,打平%d次!\n",total,youwin,mewin,daping);
system("PAUSE");
return EXIT_SUCCESS;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询