石头剪刀布游戏、不知道哪里错了
#include <stdio.h>#include <stdlib.h>
int pscore=0,cscore=0,count=0;
int cshowfist()
{int show;
srand(time(NULL));
show=rand()%3+1;
switch (show)
{ case 1:
printf("\n电脑出:剪刀");break;
case 2:
printf("\n电脑出:石头");break;
case 3:
printf("\n电脑出:布");break;
}
return show;}
int pshowfist()
{int show;
printf("\n请玩家出拳:1.剪刀 2.石头 3.布<输入相应的数字>");
scanf("%d",&show);
switch (show)
{ case 1:
printf("玩家出:剪刀");break;
case 2:
printf("玩家出: 石头");break;
case 3:
printf("玩家出: 布");break;
}
return show;}
void judge(int a ,int b )
{ if((b==2 && a==2) ||(b==3 && a==3)||(b==1 && a==1))
{printf("\n结果,令人意外!竟以和局收场。");}
else if ( (b==1 && a==3)||(b==2 && a==1)||(b==3 && a==2))
{printf("\n ^_^ 恭喜,玩家赢得胜利!");pscore++; }
else
{printf("\n真笨,输给机器!!!"); cscore++;}
}
void getscore()
{int result;
printf("\n---------------------------------------------------------------------");
printf("\n对战%d次,玩家赢%d次,平%d次,输%d次!",count,pscore,count-pscore-cscore,cscore);
printf("\n-------------------------------------------------------------------");
if(pscore==cscore)
result=1;
else if(pscore>cscore)
result=2;
else
result=3;
if(result==1)
printf("\n结果:打成平手,下次再分高下!");
else if(result==2)
printf("\n结果:玩家获得最终胜利,恭喜!");
else
printf("\n结果:玩家落败,真笨!");
printf("\n");
}
int main(int argc, char *argv[])
{char x='y';int a,b;
while(x=='y')
{
b=pshowfist();
a=cshowfist();
judge(a,b);
count++;
printf("玩家是否继续游戏?(y/n)");
fflush(stdin);
x=getch();
system("cls");
}
getscore();
system("PAUSE");
return 0;
}