猜拳小游戏
本帖最后由 乱码zzz 于 2020-4-4 18:28 编辑可以运行,调试的时候也没有出错
但是运行着运行着却会出现图片所示问题(图片在最下方)(正常输入3,但程序却停止了)
这究竟是为什么qwq
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *str[] = {"none","剪刀","石头","布"};
void game(int);
int count = 0;
//机器出拳,并判断输赢
void game(int choice){
int it;
time_t t;
srand((unsigned)time(&t));//真神奇
it = (int)(rand() % 4);
if (it != 0){
if (it == choice){
printf("你出%s,我出%s,咱打平!\n",str,str);
count += 0;
}
else{
switch(choice){
case 1:{
if (it == 2){
printf("你出%s,我出%s,我赢了!\n",str,str);
count -= 1;
}
if (it == 3){
printf("你出%s,我出%s,我输了!\n",str,str);
count += 1;
}
break;
}
case 2:{
if (it == 3){
printf("你出%s,我出%s,我赢了!\n",str,str);
count -= 1;
}
if (it == 1){
printf("你出%s,我出%s,我输了!\n",str,str);
count += 1;
}
break;
}
case 3:{
if (it == 1){
printf("你出%s,我出%s,我赢了!\n",str,str);
count -= 1;
}
if (it == 2){
printf("你出%s,我出%s,我输了!\n",str,str);
count += 1;
}
break;
}
default: break;
}
}
}
else{
game(choice);
}
}
//主函数 用户出拳,调用game()函数
int main(void){
printf("######################\n");
printf("##欢迎来到猜拳小游戏##\n");
printf("######################\n");
int choice;
do{
printf("请出拳(1剪刀/2石头/3布/0退出)-->");
scanf("%d", &choice);
game(choice);
} while(choice != 0);
if(count >= 1){
printf("你赢了\n");
}
if(count == 0){
printf("平局\n");
}
if (count < 0){
printf("你输了\n");
}
return 0;
}
页:
[1]