用c语言编写一个剪刀石头布的游戏,简单点最好,不要用太复杂的c语言知识,c语言刚学。
发布网友
发布时间:2022-04-26 10:54
我来回答
共1个回答
热心网友
时间:2023-10-09 10:15
#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;