求c语言猜价格游戏代码

咏艾CorL 2024-05-10 19:24:22
最佳回答
展开全部#include
include
include
include
格式化时间函数
char_format_time_[40];char*getformattime(long t)
{
strftime(_format_time_,sizeof(_format_time_)/sizeof(char),"%y.%m.%d%h:%m:%s",gmtime(&t));return_format_time_;}
保存**信息的文件
char player_data_file_name[]="player.txt;系统默认的用户名
const char palyer_default_system_name[]="player;用户名最大长度
const int player_max_name_length=20;密码最大长度
const int player_max_pass_length=20;**信息
struct player
{
唯一的账号名称
char name[player_max_name_length+1];登陆密码
char pass[player_max_pass_length+1];struct player*next;player()
{
strcpy(name,"");strcpy(pass,"");next=**;}
};全局变量:游戏**链表
struct player*_players=**;全局变量:当前登陆的游戏**
struct player_loginplayer;保存游戏信息的文件
char game_data_file_name[]="game.txt;排行榜上记录保存个数
const int game_max_top_players=5;猜价格最多尝试次数
const int game_max_try_time=3;猜价格的最小值
const int game_min_price=1000;猜价格的最大值
const int game_max_price=9999;一局游戏的信息
struct game
{
游戏开始时间
long starttime;游戏结束时间
long endtime;**账号
char playername[player_max_name_length+1];真实价格
int realprice;是否成功猜出
int **success;**一共猜的次数
int guesstime;**猜了 guesstime 次,每次才的价格
int guessprice[game_max_try_time];struct game*next;game()
{
starttime=time(**);strcpy(playername,"");srand(time(**));**success=0;realprice=rand()%(game_max_price-game_min_price)+game_min_price;guesstime=0;next=**;}
};全局变量:猜价格游戏链表
struct game*_games=**;初始化 游戏**链表
void initplayer()
{
file*playerfile=fopen(player_data_file_name,"r");struct player*p,tempplayer;if(playerfile)
{
while(fscanf(playerfile,"%s%s",tempplayer.name,tempplayer.pass)!eof)
{
if(_players=**)
{
players=(struct player*)malloc(sizeof(struct player));players=tempplayer;p=_players;}
else
{
p->next=(struct player*)malloc(sizeof(struct player));p->next=tempplayer;p=p->next;}
}
fclose(playerfile);}
}
保存 游戏**链表
void s**eplayer()
{
file*playerfile=fopen(player_data_file_name,"w");struct player*p;if(playerfile)
{
p=_players;while(p)
{
fprintf(playerfile,"%s%s\n",p->name,p->pass);p=p->next;}
fclose(playerfile);}
}
初始化 猜价格游戏链表
void initgame()
{
file*gamefile=fopen(game_data_file_name,"r");struct game*p,tempgame;int i;if(gamefile)
{
while
fscanf(gamefile,"%ld%ld%s%d%d%d",
tempgame.starttime,
tempgame.endtime,
tempgame.playername,
tempgame.realprice,
tempgame.**success,
tempgame.guesstime
eof)
{
for(i=0;i;i+)
{
fscanf(gamefile,"%d",&tempgame.guessprice[i]);}
if(_games=**)
{
games=(struct game*)malloc(sizeof(struct game));games=tempgame;p=_games;}
else
{
p->next=(struct game*)malloc(sizeof(struct game));p->next=tempgame;p=p->next;}
}
fclose(gamefile);}
}
保存 猜价格游戏链表
void s**egame()
{
file*gamefile=fopen(game_data_file_name,"w");struct game*p;int i;if(gamefile)
{
p=_games;while(p)
{
fprintf(gamefile,"%ld%ld%s%d%d%d",
p->starttime,
p->endtime,
p->playername,
p->realprice,
p->**success,
p->guesstime
for(i=0;i<p->guesstime;i+)
{
fprintf(gamefile,"%d",p->guessprice[i]);}
fprintf(gamefile,"\n");p=p->next;}
fclose(gamefile);}
}
猜价格游戏主菜单
int printmainmenu()
{
char strchoice[100];int intchoice;do
{
printf("\n*\n");printf("*主菜单\n");printf("*\n");printf("*1)查看排行榜\n");printf("*2)清除排行榜\n");printf("*3)登录账号开始游戏\n");printf("*4)申请账号开始游戏\n");printf("*5)退出游戏\n");printf("*\n");scanf("%s",strchoice);intchoice=atoi(strchoice);if(intchoice|intchoice>5)
{
printf("*命令错误!请重新输入命令!}
}
while(intchoice|intchoice>5);return intchoice;}
对已有的游戏记录根据【猜价格的次数】递增排序
如果【猜价格的次数】相等,
根据【使用的时间】递增排序,
如果【使用的时间】相等,
根据【开始的时间】递增排序,
void sortgames()
{
struct game*p,*q,tempgame1,tempgame2;p=_games;while(p)
{
q=p->next;while(q)
{
if
p->guesstime>q->guesstime|
(p->guesstime=q->guesstime&(p->endtime-p->starttime)>(q->endtime-q->starttime))|
(p->guesstime=q->guesstime&(p->endtime-p->starttime)=(q->endtime-q->starttime)&p->starttime>q->starttime)
{
tempgame1=*p;tempgame2=*q;注意交换的时候,next 指针不能交换
p=tempgame2;p->next=tempgame1.next;注意交换的时候,next 指针不能交换
q=tempgame1;q->next=tempgame2.next;}
q=q->next;}
p=p->next;}
}
查看排行榜
void printrankl**t()
{
int counter=0;struct game*p;printf("\n*\n");printf("***排名\n");printf("*\n");没有记录
if!games)
{
printf("*排名:%4d 用户:%10s(default)用了%4d次\n",1,palyer_default_system_name,game_max_try_time);}
else
{
排序
sortgames();p=_games;counter=0;查看前 game_max_top_players 名(如果有那么多),并且成功猜出价格的
while(p&counter< game_max_top_players && p->**success)
{
counter+;printf("*排名:%4d 用户:%10s 用了%4d次\n",counter,p->playername,p->guesstime);printf("开始时间:%s\n",getformattime(p->starttime));printf("结束时间:%s\n\n",getformattime(p->endtime));p=p->next;}
}
printf("*\n");}
清除排行榜
void clearrankl**t()
{
struct game*p=_games,*q;while(p)
{
q=p->next;free(p);p=q;}
games=**;printf("\n*\n");printf("*清空排名榜\n");printf("*\n");printf("*排名榜已经清空!\n");printf("*\n");}
猜价格游戏用户登陆菜单
int printloginmenu()
{
struct player*p;char name[player_max_name_length+1];char pass[player_max_pass_length+1];int i;char ch;printf("\n*\n");printf("*登录菜单\n");printf("*\n");printf("*输入用户名称:");scanf("%s",name);printf("*输入用户密码:");scanf("%s",pass);i=0;while((ch=getch())!'\n')
{
pass[i+]=ch;}
pass[i]='\n';p=_players;while(p)
{
if(strcmp(p->name,name)=0&strcmp(p->pass,pass)=0)
{
break;}
else
{
p=p->next;}
}
if(p)
{
printf("*登陆成功!\n");printf("*\n");strcpy(_loginplayer.name,name);strcpy(_loginplayer.pass,pass);return 1;}
else
{
printf("*登陆失败!用户名不存在或者密码错误!\n");printf("*\n");return 0;}
}
猜价格游戏用户注册菜单
int printreg**termenu()
{
struct player*p;char name[player_max_name_length+1];char pass[player_max_pass_length+1];int i;char ch;printf("\n*\n");printf("*注册菜单\n");printf("*\n");do
{
printf("*输入要注册的用户名称:");scanf("%s",name);if(strcmp(palyer_default_system_name,name)=0)
{
printf("*%s 是系统默认的用户名,不能被注册!\n",palyer_default_system_name);}
else if(strlen(name)=0)
{
printf("*用户名不能为空!\n");}
}
while(strlen(name)=0|strcmp(palyer_default_... 20210311
汇率兑换计算器

类似问答
  • 猜价格游戏规则
    • 2024-05-10 15:07:46
    • 提问者: Ryeng
    回答如下:此游戏的规则是先给出一个商品然后你给出价格然后主持人会根据你所出的价格来判断是高于实际价格还是低于实际价格并提示是"高了"还是"低了直到你猜对价格当然是有时间限制的哈
  • 求解怎么做?php代码计算商品打折后的价格。求代码
    • 2024-05-10 04:27:42
    • 提问者: 宇文斌斌双胞胎姐妹
    完全依照图片效果,代码如下:1、html 文件计算商品折扣价格商品名称:label for="textfield">td>商品单价:input type="text"name="spdj"id="spdj"/>元促销折扣:input type="text"name="cxzk"id="cxzk"/>%input type="submit"name="button"id="b...
  • 一般c语言培训多少钱
    • 2024-05-10 23:27:25
    • 提问者: 孙哥
    不贵,几千块钱,但是你得坚持住啊,学3-5年可能才能算是入行。
  • 张杰给哪几个游戏代言
    • 2024-05-10 14:14:21
    • 提问者: 纯小喵?
    征途,恶魔法则,龙,梦幻诛仙,逆战
  • 玩国外游戏的代理要求?
    • 2024-05-10 16:58:22
    • 提问者: 我是湖南人
    你可以·购买一个日本的专线使用就好了!
  • 张靓颖代言手游是真的吗 张靓颖代言的是哪款手游
    • 2024-05-10 07:44:45
    • 提问者: 一句话剧评
    离开了《我是歌手》舞台,张靓颖近日爆出在忙于全新英文专辑和巡演的工作,但知情人士爆料:在采访中透露过很喜欢玩**的张靓颖即将真正拥有一款“我的**”了!传言某手游将会邀请张靓颖担任代言人,据悉代言费用在土豪横行的手游界也堪称天价!这意味着从不代言游戏的张靓颖即将以代言人身份首次进军手游界!在手游这块热土上,缺乏有效宣传手段无疑会让自家产品“输在了起跑线上”。此前出演《何以笙萧默》的钟汉良,当选“史...
  • 一套街机游戏源代码大概多少钱?
    • 2024-05-10 14:25:14
    • 提问者: 孫温柔?
    这个是不一定的,完整文档的少说也上万
  • 游戏蜂窝里面的脚本是怎么写的,需要懂什么语言
    • 2024-05-10 16:30:59
    • 提问者: 阿n孝
    q语言
  • 星际公民:这游戏,你猜猜多少个g,显卡需要多高
    • 2024-05-10 12:24:46
    • 提问者: C。
    《星际公民(star citizen)》是由cloud imperium games corporation制作发行的3d太空模拟战争游戏,本作不是传统意义上的网游,但是它的确拥有多人连线、开放的持续发展的世界、微交易以及完整的经济系统等网游的特点,当然你也可以玩单人任务;
  • 看图猜成语
    • 2024-05-10 19:24:22
    • 提问者: ?Wendy??
    根据图片意思,应该是上面以人为本,下面如日中天
汇率兑换计算器

热门推荐
热门问答
最新问答
推荐问答
新手帮助
常见问题
房贷计算器-九子财经 | 备案号: 桂ICP备19010581号-1 商务联系 企鹅:2790-680461

特别声明:本网为公益网站,人人都可发布,所有内容为会员自行上传发布",本站不承担任何法律责任,如内容有该作者著作权或违规内容,请联系我们清空删除。