猜拳游戏C语言编程
猜拳游戏 游戏包括“开始游戏”、“排行榜查看”2个主要功能。 (1)开始游戏 每个用户有初始积分为100金币。 1)每一轮猜拳游戏,用户首先输入押入这轮的金币数(最大不可超过剩余金币数),如果赢得本轮,获得相应金币数,若输,损失相应金币数。 2)提示信息让用户输入一个1~3之间的值,其值事先设定为: 1表示石头 2表示剪刀 3表示布。程序随机生产1~3的其中之一,然后与用户输入的值进行比较,根据猜拳游戏规则来判定,输出显示胜或败,并调整金币值。 3)提示是否还要继续完游戏?如果输入Y或者y,则进行下一轮猜拳(步骤1)。如果输入N或n,则与排行榜中的前五名玩家的游戏记录比较,如果排名能够进入前五名,则提示用户输入玩家姓名,更新排行榜,退出程序。 (2)排行榜查看 在排行榜查看功能中,用户可以查看当前的游戏排行,排行榜中总共显示前5名玩家姓名和金币数。 (希望程序已经经过调试)
/* 放假没事就帮你做了,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(); }。
答:#include "stdio.h" #include "graphics.h" #include "conio.h" #include "stdlib.h" ...详情>>
问:挺简单的一C函数,不过我是初学者,暂时还不会写,请好心人多多帮忙!
答:int mystrlen(char *str) { int n = 0; while (*str) { n++; str++;} return n; } voi...详情>>