#include<stdio.h>
#include<stdlib.h>
#include<time.h>
//在【C语言中文社区】公众号回复“C语言”,免费领取200G学习资料。
int main()
{
printf("欢迎来到石头剪刀布游戏世界\n");
printf("我是你无法打败的对手-小布\n");
char game[3][20] = { "石头","剪刀","布" };
/*i表示游戏次数,如果玩家在15次比赛后累计得分60,就获得完全胜利*/
int player = 0, xiaobu = 0,Q= 0,score=0,i=0;
printf("0表示石头,1表示剪刀,2表示布,请在区间【0,2】中任选一个整数输入:\n");
while (scanf_s("%d", &player))
{
srand(time(NULL));
if(player>2||player<0){
printf("sorry!请输入0-2之间的数字\n");
} else{
xiaobu = rand() % 3;
printf("你出:%s\t小布出:%s\t", game[player], game[xiaobu]);
Q = player - xiaobu;
/*会出现的情况*/
/*可能的结果有-1,-2,0,1,2;
当player赢的结果有,shi-jian=-1,jian-bu=-1,bu-shi=2*/
/*如果是平局:0*/
/*如果player输:shi-bu=-2,bu-jian=1,jian-shi=1*/
printf("\n");
if (Q == -1 || Q == 2)
{
printf("你居然赢了我,厉害,赞!\n");
printf("恭喜得分:");
score = 5 + score;
printf("%d", score);
printf("\n");
i = i + 1;
}
if (Q == 1 || Q == -2)
{
printf("嘿嘿嘿,小样,loser!\n");
i = i + 1;
}
else if (Q == 0)
{
printf("可惜了,平局!\n");
i = i + 1;
}
if (i == 15)
{
break;
}
if (score == 60)
{
printf("恭喜玩家通关!");
break;
}
}
}
return 0;
}