代码
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(int argc, char *argv[])
{
printf("欢迎来到剪刀石头布游戏\n");
char game[3][20] = {"石头","剪刀","布"};
int player = 0,dn = 0,Q = 0,score = 0,i = 0;
printf("0代表石头,1代表剪刀,2表示布\n");
while(scanf("%d",&player))
{
srand(time(NULL));
if(player>2||player<0)
{
printf("sorry!请输入0~2之间的数字\n");
}
else
{
dn = rand()%3;
printf("你出:%s 电脑出:%s",game[player],game[dn]);
Q = player - dn;
printf("\n");
if(Q == -1|| Q == 2)
{
printf("你赢\n");
printf("得分:");
score += 5;
printf("%d",score);
printf("\n");
i += 1;
}
if(Q == 1 || Q == -2)
{
printf("你输了\n");
i += 1;
}
else if(Q == 0)
{
printf("平局\n");
i += 1;
}
if(i == 15)
{
break;
}
if(score == 60)
{
printf("恭喜通关!\n");
break;
}
}
}
return 0;
}