十个人猜拳结果c语言编程,猜拳游戏C语言编程

/*

放假没事就帮你做了,20分太少了,花了我一个上午时间呢!希望满意,程序附上,VS2005编译通过。

*/

#include

#include

#include

#include

#define ORIGINGOLD 100

typedef struct

{

char name[100];

unsigned long score;

} User;

void Menu()

{

system("cls");

printf("========================made by 小恩 =====================\n");

printf("1:start game\n");

printf("2:show order\n");

printf("3:quit game\n");

printf("==========================================================\n");

}

int choise()

{

int ch;

printf("Input your choice(1~3): ");

while(ch=getchar())

{

if('\n'==ch)

continue;

while('\n'!=getchar());

if(ch>'3'||chmaxR)

{

while('\n'!=getchar());

printf("Invide input!Try again:(%d~%d) ",minR,maxR);

}

while('\n'!=getchar());

return showhand;

}

void save(const unsigned long score)

{

FILE *fp;

int num=0;

User gamer={"",0L},temp={"",0L},gm;

if(fopen_s(&fp,"F:\\ ","r+"))

{

if(fopen_s(&fp,"F:\\ ","w"))

{

printf("Error,Can't open file F:\\ for save!\n");

exit(1);

}

while(num++ ore)

{

fseek(fp,-1*(long)sizeof(User),SEEK_CUR);

fwrite(&gm,sizeof(User),1,fp);

fseek(fp,0L,SEEK_CUR);

if(!strcmp( , ))

break;

else

gm=temp;

}

}

}

fclose(fp);

}

void game()

{

const char fist[3][10]={"石头","剪刀","布"};

int fistPC,fistUser,showhand;

int gold=ORIGINGOLD;

srand( (unsigned)time( NULL ) );

do

{

printf("Hi,Man,Show me you prety gold(押注,整数): ");

showhand=getInt(1,gold);

printf("1:石头\n2:剪刀\n3:布\n");

printf("What is your fist:(1~3) ");

fistUser=getInt(1,3);

fistPC=rand();

fistPC=fistPC%3+1;

printf("Player %s VS %s Computer \n",fist[fistUser-1],fist[fistPC-1]);

if(-1==(fistUser-fistPC) || 2==(fistUser-fistPC))

{

gold+=showhand;

printf("\nYou WIN %d golds! %d golds left\n",showhand,gold);

}

else if(fistUser==fistPC)

printf("Hi ,young man,you follow me!\nNO WIN,NO LOST!\n %d golds left\n",gold);

else

{

gold-=showhand;

printf("\nYou LOST %d gold! %d golds left\n",showhand,gold);

}

if(0>=gold)

{

printf("Poor boy,You do not have enough money to continue!\n");

break;

}

}while(agree("Continue?(Y/N):"));

save(gold);

//getUser(gold);

return;

}

void show5order()

{

FILE *fp;

int n=0;

User gamer;

if(fopen_s(&fp,"F:\\ ","r"))

{

printf("Error,Can't open file F:\\ !\n");

exit(1);

}

fseek(fp,0L,SEEK_END);

if( 5*sizeof(User) != (ftell(fp)) )

{

printf("somthing error with the data file F:\\ !\n");

exit(2);

}

fseek(fp,0L,SEEK_SET);

printf("%-13s%20s%20s \n","No。

","Gamer name","Golds");

while(fread(&gamer,sizeof(User),1,fp))

{

if(strcmp( ,""))

{

printf("No。

%-10d%20s%20d GOLDS\n",++n, , ore);

continue;

}

else

break;

}

if(0==n)

printf("No record!\n");

fclose(fp);

return;

}

void byebye()

{

system("cls");

printf("\t=============================Bye-bye============================\n");

printf("\tThis is a simple game program made by 小恩 for Miss 雨记\n\n\n\n");

printf("\t\t\t\tHave a nice day!\n\n\n\n\n");

printf("\t\tCopyright @2009 版权所有,转载请声明出处!\n");

printf("\tThank you for use,Any question contact me:lvcmos@ \n");

printf("\t=============================Bye-bye============================\n");

system("pause");

}

void Hello()

{

system("cls");

printf("\t==============================HELLO=============================\n");

printf("\tThis is a simple game program made by 小恩 for Miss 雨记\n\n\n\n");

printf("\t\t\t\tHave a nice day!\n\n\n\n\n");

printf("\t\tCopyright @2009 版权所有,转载请声明出处!\n");

printf("\tThank you for use,Any question contact me:lvcmos@ \n");

printf("\t==============================HELLO=============================\n");

system("pause");

}

main()

{

int choice;

Hello();

Menu();

while('3'!=(choice=choise()))

{

switch(choice)

{

case '1':

game();

break;

case '2':

show5order();

break;

default:

printf("Something Error\n");

break;

}

if(agree("Show Menu?(Y/N):"))

Menu();

else

system("cls");

}

byebye();

}。

全部

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值