用c语言编写一个剪刀石头布的游戏,简单点最好,不要用太复杂的c语言知识,c语言刚学。
1个回答
2016-04-18 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
/*************\
* 剪刀 石头 布 *
* 最简单小游戏 *
\*************/
int main(void){
char gesture[3][10] = {"scissor","stone","cloth"};
int man, computer, result, ret;
/*随机数初始化函数*/
srand(time(NULL));
while(1){
computer = rand()%3;
printf("\nInput your gesture 0-scissor 1-stone 2-cloth:\n");
ret = scanf("%d", &man);
if(ret !=1 || man<0 || man>2){
printf("Invalid input!\n");
return 1;
}
printf("Your gesture:%s\tComputer's gesture: %s\n",
gesture[man], gesture[computer]
);
result = (man - computer + 4) %3 -1;
if(result > 0)
printf("YOU WIN!\n");
else if(result == 0)
printf("Draw!\n");
else
printf("You lose!\n");
}
return 0;
#include<stdlib.h>
#include<time.h>
/*************\
* 剪刀 石头 布 *
* 最简单小游戏 *
\*************/
int main(void){
char gesture[3][10] = {"scissor","stone","cloth"};
int man, computer, result, ret;
/*随机数初始化函数*/
srand(time(NULL));
while(1){
computer = rand()%3;
printf("\nInput your gesture 0-scissor 1-stone 2-cloth:\n");
ret = scanf("%d", &man);
if(ret !=1 || man<0 || man>2){
printf("Invalid input!\n");
return 1;
}
printf("Your gesture:%s\tComputer's gesture: %s\n",
gesture[man], gesture[computer]
);
result = (man - computer + 4) %3 -1;
if(result > 0)
printf("YOU WIN!\n");
else if(result == 0)
printf("Draw!\n");
else
printf("You lose!\n");
}
return 0;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询