/*
放假没事就帮你做了,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();
}。
全部