C语言编写简单游戏:剪刀、石头、布

 我来答
winhkey
2006-06-13 · TA获得超过316个赞
知道小有建树答主
回答量:453
采纳率:0%
帮助的人:380万
展开全部
呵呵,这是我去年初学C语言时写的,当时水平低,高手就不要指责了~~~

#include<time.h>
#include<stdio.h>
#include<conio.h>
#include <stdlib.h>
char x,response;
int y,draw,win,loss;

void main()
{
c: draw = 0,win = 0,loss = 0;
d: system("cls");
printf("欢迎挑战\n\n");
printf("0:石头 1:剪子 2:布\n");
printf("\n请你出拳:");
if((x = getch()) == '0')
printf("石头");
else if(x == '1')
printf("剪子");
else if(x == '2')
printf("布");
else
{
printf("请按0-2\n按任意键继续\n");
getch();
goto d;
}
srand((unsigned)time(NULL));
y = rand()%3;
switch(y)
{
case 0:
printf("\n\n电脑出拳:石头\n\n");
break;
case 1:
printf("\n\n电脑出拳:剪子\n\n");
break;
case 2:
printf("\n\n电脑出拳:布\n\n");
break;
}
if(x == '0')
{
switch(y)
{
case 0:
printf("平局");
draw++;
break;
case 1:
printf("你赢了");
win++;
break;
case 2:
printf("你输了");
loss++;
break;
}
}
else if(x == '1')
{
switch(y)
{
case 0:
printf("你输了");
loss++;
break;
case 1:
printf("平局");
draw++;
break;
case 2:
printf("你赢了");
win++;
break;
}
}
else if(x == '2')
{
switch(y)
{
case 0:
printf("你赢了");
win++;
break;
case 1:
printf("你输了");
loss++;
break;
case 2:
printf("平局");
draw++;
break;
}
}
printf("\n\n你的战况:赢%d局 输%d局 平%d局", win, loss, draw);
if(win <= loss+draw)
{
printf("\n\n还不服气?\nY or N?\n");
response=getch();
if(response == 'Y' || response == 'y' || response == 13)
{
printf("\n战况清零?\nY or N?\n");
response = getch();
if(response == 'Y' || response == 'y' || response == 13)
{
goto c;
}
goto d;
}
}
else
{
printf("\n\n厉害,继续?\nY or N?\n");
response = getch();
if(response == 'Y' || response == 'y' || response == 13)
{
printf("\n战况清零?\nY or N?\n");
response = getch();
if(response == 'Y' || response == 'y' || response == 13)
{
goto c;
}
goto d;
}
}
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式