中易网

打字游戏的代码

答案:4  悬赏:80  
解决时间 2021-04-28 01:56
  • 提问者网友:騷女、無惡不作
  • 2021-04-27 07:04
【问题描述】
本课题的主要目的是利用C/C++语言的知识,设计一个打字游戏,供给初学者进行打字练习,让他们可以在短时间内熟悉键盘上的各个字符键的位置。
该课题要求对内存中或文件中所存储的数据进行各种常规操作,如:查找、排序、统计、显示等功能。通过此课题,熟练掌握文件、数组、指针的各种操作,以及一些算法思想的应用。

【功能要求】
(1) 纪录管理。
a) 程序要求只记录每位玩家的三次最好成绩。纪录信息包括:排名、玩家姓名、输入正确的次数/样本长度三项。其中 “输入正确的次数/样本长度”越大成绩越好。
b) 纪录信息要求保存在硬盘上的文件中,玩家退出系统的时候,最新纪录要存到硬盘中去。
c) 纪录管理功能包括纪录的删除、查询功能。
d) 可以查所有玩家的成绩,并可以依据操作员的选择,或按玩家成绩的递减次序显示,或按玩家姓名的字典次序显示。
e) 当按玩家姓名查询时,按玩家成绩的递减次序显示。
(2) 打字练习过程。
1) 应用ASCII码及随机数生成打字界面内的字符。在生成的打字练习界面内,要求每次显示10行,每行10个字符(字母或数字)。
2) 开始打字练习:接受输入的字符、判断正误。
3) 打字结束后能够统计出打字练习时的数据:打字过程中的正确字符数、错误字符数、准确率,并记录到纪录文件中。
4) 询问玩家是否开始新的一轮练习,如果玩家选“否”,则系统退到外面的菜单。
(3) 游戏配置。可配置的参数包括:纪录文件名和路径、玩家姓名。
纪录文件名和路径在程序一开始运行的时候设定为默认值。玩的时候,可以在游戏配置界面中对其进行修改。

【扩展功能】
在实现上述功能的基础上,可以考虑实现下面一个或多个功能。
(1) 玩家纪录里面不仅记录排名、玩家姓名、输入正确的次数/样本长度三项,还记录玩家创造纪录的时间,时间可由系统时间取得。
(2) 对玩家打字的总时间进行限制。

【程序设计的具体说明】
(1) 为各项操作功能设计一个菜单,用户通过菜单项选择希望进行的操作项目。
(2) 变量、函数命名符合规范。
(3) 注释详细:每个变量都要求有注释,以说明用途;函数的注释说明功能,对函数的参数、返回值也要以注释的形式说明用途;关键的语句段要求有注释解释。
(4) 程序的层次清晰,可读性强。

【程序设计的开发环境】
VC++6.0,在内存中的各种操作可以采用一维数组方式或是指针方式。
最佳答案
  • 二级知识专家网友:眠于流年
  • 2021-04-27 07:33
给你一个参考:
#include<stdio.h>
#include<stdlib.h>
main()
{
int i;
int line=0,col=0,num=0;
int score=0,times=1;
char one[26];
char c;

for(i=0,c='a';i<26;i++,c++)
{
one[i]=c;
}
center();
printf("press anykey to start");
getch();

while(1)
{ system("cls");
printf("times:%d ",times);
printf(" score: %d",score);
printf(" 1----Pause,0----exit");
printf("\n");
printf("________________________________________________________________________");
printf("\n");

line=0;
randomize();
col=random(60);
randomize();
num=random(26);

while(1)
{
space(col);
printf("%c",one[num]);
delay_x(10-times);
printf("\b \n");
line++;

if(line>45)
{
score-=10;
break;
}
if(score<0)
{
center();
printf("sorry,you faile!");
getch();
exit(0);
}

if(kbhit())
{
c=getch();
if(c==one[num])
{

score+=10;
break;
}
switch(c)
{
case '0': exit(0);
case '1': getch();
default : ;
}
}
}

if(score>=100*times)
{
times++;
center();
if(times>9)
{
printf("congratulation,you win!");
}
printf("If you go to the %d:(y/n)",times);
if((getch())=='n')
{
center();
printf("I am sorry for you give up!");
getch();
break;
}
}
}
}

change_line(int k)
{ int i;
for(i=0;i<k;i++)
{
printf("\n");
}
}

space(int k)
{ int i;
for(i=0;i<k;i++)
{
printf(" ");
}
}

delay_x(int k)
{
int i;
for(i=0;i<k;i++)
{
delay(5000);
}
}

center()
{
system("cls");
change_line(20);
space(25);
}
全部回答
  • 1楼网友:野心和家
  • 2021-04-27 10:03
楼上的错误好多(我指的是,楼主说要的是VC++6.0,我改了,绝对OK!!楼上别生气~) #include<stdio.h> #include<stdlib.h> #include<conio.h> #include<windows.h> #include<time.h> void change_line(int k) { int i; for(i=0;i<k;i++) { printf("\n"); } } void space(int k) { int i; for(i=0;i<k;i++) { printf(" "); } } void delay_x(int k) { int i; for(i=0;i<k;i++) { Sleep(1000); //难度!!!! } } void center() { system("cls"); change_line(20); space(25); } void main() { int i; int line=0,col=0,num=0; int score=0,times=1; char one[26]; char c; srand((int)time(0)); for(i=0,c='a';i<26;i++,c++) { one[i]=c; } center(); printf("press anykey to start"); getch(); while(1) { system("cls"); printf("times:%d ",times); printf(" score: %d",score); printf(" 1----Pause,0----exit"); printf("\n"); printf("________________________________________________________________________"); printf("\n"); line=0; //randomize(); col=rand()%60; num=rand()%26; while(1) { space(col); printf("%c",one[num]); delay_x(10-times); printf("\b \n"); line++; if(line>45) { score-=10; break; } if(score<0) { center(); printf("sorry,you faile!"); getch(); exit(0); } if(kbhit()) { c=getch(); if(c==one[num]) { score+=10; break; } switch(c) { case '0': exit(0); case '1': getch(); default : ; } } } if(score>=100*times) { times++; center(); if(times>9) { printf("congratulation,you win!"); } printf("If you go to the %d:(y/n)",times); if((getch())=='n') { center(); printf("I am sorry for you give up!"); getch(); break; } } } }
  • 2楼网友:偏爱自由
  • 2021-04-27 09:36
printf(" 1----Pause,0----exit"); printf("\n"); printf("________________________________________________________________________"); printf("\n"); line=0; randomize(); col=random(60); randomize(); num=random(26); while(1) { space(col); printf("%c",one[num]); delay_x(10-times); printf("\b \n"); line++; if(line>45) { score-=10; break; } if(score<0) { center(); printf("sorry,you faile!"); getch(); exit(0); } if(kbhit()) { c=getch(); if(c==one[num]) { score+=10; break; } switch(c) { case '0': exit(0); case '1': getch(); default : ; } } } if(score>=100*times) { times++; center(); if(times>9) { printf("congratulation,you win!"); } printf("If you go to the %d:(y/n)",times); if((getch())=='n') { center(); printf("I am sorry for you give up!"); getch(); break; } } } } change_line(int k) { int i; for(i=0;i<k;i++) { printf("\n"); } } space(int k) { int i; for(i=0;i<k;i++) { printf(" "); } } delay_x(int k) { int i; for(i=0;i<k;i++) { delay(5000); } } center() { system("cls"); change_line(20); space(25); } 回答者:匿名 2-18 14:55 楼上的错误好多(我指的是,楼主说要的是VC++6.0,我改了,绝对OK!!楼上别生气~) #include<stdio.h> #include<stdlib.h> #include<conio.h> #include<windows.h> #include<time.h> void change_line(int k) { int i; for(i=0;i<k;i++) { printf("\n"); } } void space(int k) { int i; for(i=0;i<k;i++) { printf(" "); } } void delay_x(int k) { int i; for(i=0;i<k;i++) { Sleep(1000); //难度!!!! } } void center() { system("cls"); change_line(20); space(25); } void main() { int i; int line=0,col=0,num=0; int score=0,times=1; char one[26]; char c; srand((int)time(0)); for(i=0,c='a';i<26;i++,c++) { one[i]=c; } center(); printf("press anykey to start"); getch(); while(1) { system("cls"); printf("times:%d ",times); printf(" score: %d",score); printf(" 1----Pause,0----exit"); printf("\n"); printf("________________________________________________________________________"); printf("\n"); line=0; //randomize(); col=rand()%60; num=rand()%26; while(1) { space(col); printf("%c",one[num]); delay_x(10-times); printf("\b \n"); line++; if(line>45) { score-=10; break; } if(score<0) { center(); printf("sorry,you faile!"); getch(); exit(0); } if(kbhit()) { c=getch(); if(c==one[num]) { score+=10; break; } switch(c) { case '0': exit(0); case '1': getch(); default : ; } } } if(score>=100*times) { times++; center(); if(times>9) { printf("congratulation,you win!"); } printf("If you go to the %d:(y/n)",times); if((getch())=='n') { center(); printf("I am sorry for you give up!"); getch(); break; } } } } 回答者: linyuanhui1989 - 千总 五级 3-2 15:29
  • 3楼网友:一池湖水
  • 2021-04-27 08:03
using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.text; using system.windows.forms; using system.threading; private label labwords;//定义个lable; thread th = null;//定义一个线程; string[] words ={"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}; //先把26个字母定义为一个数组; int count = 0;//得分计数器; int h_e = 200;//线程休眠时间; private void mainmethod() { if (labwords == null)//如果lable为空; { random r = new random();//随机数; labwords = new system.windows.forms.label();//实例一个lable; labwords.name = words[r.next(26)];//这个label的名字为26个字母中随机一个; labwords.text = labwords.name;//这个lable标签的内容就等于他的名字,即这个字母; labwords.location = new system.drawing.point(r.next(20, this.size.width - labwords.size.width), 0); //drawing方法实例一个lable; 并且随机lable出现的位置在窗口之内; this.controls.add(labwords);//把lable添加到窗体; th = new thread(new threadstart(method));//实例线程; th.start();//线程开始运作; } } private void method() { while (true)//无限循环; { labshow(); thread.sleep(h_e);//设置线程休眠时间 [可控制难度]; } }
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息!
大家都在看
推荐信息