这篇文章主要为大家详细介绍了c语言实现——《打字练习系统》,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下!
游戏介绍:
《字母游戏》是一款敏捷打字小游戏,游戏大小为468k。背景设定 《字母游戏》是一款有趣的打字游戏,可以提高你的打字速度。操作指南 根据出现的字母,按键盘a-z键对应的按键即可。游戏加载完毕点击[开始游戏]即可开始游戏。在限定时间内,尽可能地输入正确的字母,挑战高分!
本项目针对c语言学习者,将我们打字母的“字母”置换成了c语言关键字,记在一定时间内及时输出c语言关键字就可以得分!我们一起来看看吧!
本项目编译环境:vs2019/vs2013;
插件:图形库插件easyx,涉及图片素材可以自行百度找也可以关注文末领取;
效果图展示
配套讲解教程:程序员打字练习系统教程——哔哩哔哩
源代码示例:
#define _crt_secure_no_warnings#include #include #include #include #include //报错,请先安装#include #pragma comment(lib,winmm.lib)//数据设计设计//窗口属性:const int width = 640;const int height = 500;//游戏正确率和错误率int right = 0;int error = 0;//下坠文字的结构体struct target{ //每一个字符串的x,y坐标 int x; int y; char *str; //保存字符串};//用户输入的值struct usrkey{ int x; int y; char str[20];}userkey = {320,500-30,};//在指定位置输出整数void outtextxy_int(int x, int y, char *format, int num){ char str[20] = ; //printf; sprintf(str, format, num); outtextxy(x, y, str);}//在指定位置输出浮点数void outtextxy_double(int x, int y, char *format, double num){ char str[20] = ; sprintf(str, format, num); outtextxy(x, y, str);}void divwindow(){ line(width - 100, 0, width - 100, height - 40); line(0, height - 40, width + 50, height - 40); line(width - 100, 130, width + 50, 130);}void inittarget(struct target words[], int n){ static char str[29][10] = { main, include, void, while, for, true, false, break, int, char, float, double, switch, case, static, if, else, short, unsigned, signed, sizeof, continue, struct, union, enum, register,default,long,return}; //0-28 //随机产生 words[n].str = str[rand() % 29]; //0 1 2 //判断重复,如果重复,就重新生成 while (words[n].str == words[(n + 1) % 3].str || words[n].str == words[(n + 2) % 3].str) { words[n].str = str[rand() % 29]; } words[n].x = rand() % (width-200); words[n].y = -20;}void drawscore(){ settextcolor(lightblue); settextstyle(25, 0, 字魂24号-镇魂手书); //软件信息输出 outtextxy(width - 90, 25, 顿开教育); outtextxy(width - 90, 25+25, 程序员专属); outtextxy(width - 90, 25 +25+25, 打字游戏); //游戏状态栏输出 outtextxy(width - 90, 225, 正确数); outtextxy_int(width - 90, 225 + 25,%d, right); outtextxy(width - 90, 285, 错误数); outtextxy_int(width - 90, 285 + 25, %d, error); outtextxy(width - 90, 285+285-225, 正确率); //分类讨论 if (right + error == 0) { outtextxy_double(width - 90, 285 + 285 - 225 + 25, %.2lf%%, 0.00); } else { //c语言 除法会取整 double sum = right + error; outtextxy_double(width - 90, 285 + 285 - 225 + 25, %.2lf%%, right / sum * 100); }}int main(){ srand((unsigned int)time(null)); mcisendstring(open 1.mp3 alias music, 0, 0, 0); initgraph(width+50, height); struct target words[3]; //随机产生掉落的字符串 for (int n = 0; n < 3; n++) { inittarget(words, n); words[n].y = -15 - n * 30; //形成不登高 } beginbatchdraw(); int i = 0; while (1) { cleardevice(); divwindow(); //碰线处理 for (int n = 0; n (height - 40 - textheight(words[n].str))) { inittarget(words, n); } } //打印文字 for (int n = 0; n < 3; n++) { settextcolor(red); outtextxy(words[n].x, words[n].y, words[n].str); } if (_kbhit()) //kbhit 检测键盘,有按键返回非零 { //字符串变为字符处理 char target; //接受用户的值 if ((target = _getch()) != '') { userkey.str[i++] = target; } else { int flagerror = 0; //干掉输入正确的字符 for (i = 0; i < 3; i++) { if (strcmp(userkey.str, words[i].str) == 0) { inittarget(words, i); right++; flagerror = 1; mcisendstring(play music, 0, 0, 0); } } if (flagerror == 0) { error++; } //习惯很重要:边写边测试 i = 0; userkey.x = 320; memset(userkey.str, 0, 20); } } outtextxy(userkey.x, userkey.y, userkey.str); drawscore(); flushbatchdraw(); sleep(100); } getchar(); closegraph(); return 0;} 写在最后:对于准备学习c/c++编程的小伙伴,如果你想更好的提升你的编程核心能力(内功)不妨从现在开始!
“为发烧而生”小米的这款产品,时隔1年多依然抢不到!
HarmonyOS-应用崩溃框架捕获与恢复组件体验
声场操控粒子实现裸眼3D显示,科幻的场景正变成现实
高压差分探头使用注意事项
LTE为无线网络减负
如何用C语言实现打字练习系统
数据仓库概述及特点
骁龙8系Lite版是传闻也是刚需
WAIC 2023 | 开放原子开源基金会成功举办世界人工智能大会大模型开源建设论坛
Microchip Technology的 Curiosity开发板登陆Mouser
谷歌宣布将推出一种能当蓝牙耳机的助听器
中国急需攻克的5大顶尖技术,一旦突破,将不惧任何国家垄断!
人脑植入芯片的危害有多大?大脑芯片植入技术路线的探讨
无处不在的拓扑声子材料
Maxim推出具反向电流阻断功能的可编程限流开关
英飞凌CoolGaN技术开启电力电子新时代
基于非周期性亚波长偏振分束光栅的894 nmNSPG-VCSEL
find命令查找技巧
脉冲信号是电压还是电流?
电机常见的控制方式包括哪些?