//OCEAN 之作,算法最早发现于百度C语言吧
#include "stdafx.h"
#include <stdlib.h>
#include <windows.h>
#include "graphics.h"
#include <conio.h>
#include <time.h>
#include <math.h>
// int main(int argc, char* argv[])
// {
// HANDLE hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
// BOOL bSuc = ::SetConsoleTextAttribute(hStdOutput,FOREGROUND_BLUE|BACKGROUND_GREEN);
// system("pause");
// return 0;
// }
void easy(); //对函数进行申明
void normal();
void hard();
void tongguan();
// 欢迎界面
void welcome()
{
// 输出屏幕提示
cleardevice();
setcolor(YELLOW);
setfont(64, 0, "华文行楷");
outtextxy(200, 50, "打字游戏");
outtextxy(80, 150, "适当娱乐 切勿沉迷");
// 实现闪烁的“按任意键开始游戏”
int c=255;
while(!kbhit())
{
setcolor(RGB(c, 0, 0));
outtextxy(90, 300, "按任意键开始游戏");
c-=8;
if (c<0) c=255;
Sleep(20);
}
getch();
cleardevice();
goto easy;
easy:
easy();
}
// 退出界面
void goodbye()
{
cleardevice();
setcolor(WHITE);
setfont(20, 0, "宋体");
outtextxy(50, 50, "在此要特别感谢“飞哥哥”和“笨笨鱼”的倾情相助,以及各位");
outtextxy(50, 80, "朋友的大力支持和鼓励,才让我这个打字游戏得以完成,即便如");
outtextxy(50, 110,"此,还是有很多不完善的地方,很多函数都是以前不知道的,此");
outtextxy(50, 140, "次现学现用,所以不好的地方大家多多见谅!O(∩_∩)O哈哈~ ");
outtextxy(50, 170, "不过还是觉得挺高兴的,如果喜欢的,希望大家一起探讨研究");
setcolor(BLUE);
setfont(60, 0, "华文彩云");
int i=255;
while(!kbhit())
{
setcolor(RGB(i, 0, 0));
outtextxy(165, 250, "OCEAN 制作");
outtextxy(165, 330, " 谢谢欣赏!");
i-=8;
if (i<0) i=255;
Sleep(50);
}
getch();
}
void help()
{
setcolor(GREEN);
setfont(64, 0, "华文行楷");
outtextxy(200, 50, "游戏说明");
setfont(25, 0, "华文新魏");
outtextxy(50, 150, "这是一个很传统的打字游戏,游戏规则为系统");
outtextxy(50, 200, "随机产生一个大写字母,并显示在屏幕上,由");
outtextxy(50, 250, "玩家在键盘上敲击相应的字母,如果打中则加");
outtextxy(50, 300, "一分,没有打中则不加,请按照提示进入游戏");
outtextxy(50, 350, "ESC键退出游戏");
Sleep(10000); //实现暂停
goto welcome;
welcome:
welcome();
}
//简单层次
void easy()
{
int all=0;
int iCount=0;
float k=0.0;
char szScoreInfo[32];
srand(time(NULL)); // 设置随机种子
setfont(16, 0, "Arial"); // 设置字母的字体和大小
char target[2] = " "; // 定义字母字符串
char key; // 定义用户按键变量
// 主循环
while(true)
{
target[0] = 65 + rand() % 26; // 产生任意大写字母
int x = rand()%630;
all++;
for (int y=0; y<460; y++)
{
setcolor(WHITE); // 设置字母的颜色
outtextxy(x, y, target); // 显示字母
if(kbhit())
{
key = getch();
if((key == target[0]) || (key == target[0] + 32))
{
bar(x,y,x+15,y+22);
iCount++;
// 设置清除
setcolor(BLACK);
outtextxy(x, y, target); // 清除原字符
if(iCount==100||all==200)
{
setcolor(WHITE);
setfont(50, 0, "华文行楷");
outtextxy(80, 150, "成功突破200,恭喜过关");
Sleep(5000);//实现暂停
setcolor(BLACK);
outtextxy(80, 150, "成功突破200,恭喜过关"); // 清除原字符
bar(80,150,580,200);
goto normal;
normal:
normal();}
break; // 跳出循环,进行下一个字符
}
else if (key == 27)
{
goto EXIT; // 如果按 ESC,退出游戏主循环
}
}
// 延时,并清除原字符
Sleep(10);
setfillstyle(BLACK);
outtextxy(x, y, target);
bar(x,y,x+25,y+22);
bar(0,0,200,22);
sprintf(szScoreInfo,"总数: %6d",all);
outtextxy(0,0,szScoreInfo);
bar(0,20,200,42);
sprintf(szScoreInfo,"打中数:%6d",iCount);
outtextxy(0,20,szScoreInfo);
k=(float)iCount/all;
bar(0,40,200,62);
sprintf(szScoreInfo,"正确率:%f",k);
outtextxy(0,40,szScoreInfo);
}
}
EXIT:
// 退出部分
goodbye();
// 关闭图形界面
closegraph();
}
//正常层次
void normal()
{int all=0;
int iCount=0;
float k=0.0;
char szScoreInfo[32];
srand(time(NULL)); // 设置随机种子
setfont(16, 0, "Arial"); // 设置字母的字体和大小
char target[2] = " "; // 定义字母字符串
char key; // 定义用户按键变量
// 主循环
while(true)
{
target[0] = 65 + rand() % 26; // 产生任意大写字母
int x = rand()%630;
all++;
for (int y=0; y<460; y++)
{
setcolor(WHITE); // 设置字母的颜色
outtextxy(x, y, target); // 显示字母
if(kbhit())
{
key = getch();
if((key == target[0]) || (key == target[0] + 32))
{
bar(x,y,x+15,y+22);
iCount++;
// 设置清除
setcolor(BLACK);
outtextxy(x, y, target); // 清除原字符
if(iCount==100||all==200)
{
setcolor(WHITE);
setfont(50, 0, "华文行楷");
outtextxy(80, 150, "成功突破200,恭喜过关");
Sleep(5000);//实现暂停
setcolor(BLACK);
outtextxy(80, 150, "成功突破200,恭喜过关"); // 清除原字符
bar(80,150,580,200);
goto hard;
hard:
hard();}
break; // 跳出循环,进行下一个字符
}
else if (key == 27)
{
goto EXIT; // 如果按 ESC,退出游戏主循环
}
}
// 延时,并清除原字符
Sleep(6);
setfillstyle(BLACK);
outtextxy(x, y, target);
bar(x,y,x+25,y+22);
bar(0,0,200,22);
sprintf(szScoreInfo,"总数: %6d",all);
outtextxy(0,0,szScoreInfo);
bar(0,20,200,42);
sprintf(szScoreInfo,"打中数:%6d",iCount);
outtextxy(0,20,szScoreInfo);
k=(float)iCount/all;
bar(0,40,200,62);
sprintf(szScoreInfo,"正确率:%f",k);
outtextxy(0,40,szScoreInfo);
}
}
EXIT:
// 退出部分
goodbye();
// 关闭图形界面
closegraph();
}
//困难层次
void hard()
{
int all=0;
int iCount=0;
float k=0.0;
char szScoreInfo[32];
srand(time(NULL)); // 设置随机种子
setfont(16, 0, "Arial"); // 设置字母的字体和大小
char target[2] = " "; // 定义字母字符串
char key; // 定义用户按键变量
// 主循环
while(true)
{
target[0] = 65 + rand() % 26; // 产生任意大写字母
int x = rand()%630;
all++;
for (int y=0; y<460; y++)
{
setcolor(WHITE); // 设置字母的颜色
outtextxy(x, y, target); // 显示字母
if(kbhit())
{
key = getch();
if((key == target[0]) || (key == target[0] + 32))
{
bar(x,y,x+15,y+22);
iCount++;
// 设置清除
setcolor(BLACK);
outtextxy(x, y, target); // 清除原字符
if(all>100 && k>0.9)
{
tongguan();}
break; // 跳出循环,进行下一个字符
}
else if (key == 27)
{
goto EXIT; // 如果按 ESC,退出游戏主循环
}
}
// 延时,并清除原字符
Sleep(3);
setfillstyle(BLACK);
outtextxy(x, y, target);
bar(x,y,x+25,y+22);
bar(0,0,200,22);
sprintf(szScoreInfo,"总数: %6d",all);
outtextxy(0,0,szScoreInfo);
bar(0,20,200,42);
sprintf(szScoreInfo,"打中数:%6d",iCount);
outtextxy(0,20,szScoreInfo);
k=(float)iCount/all;
bar(0,40,200,62);
sprintf(szScoreInfo,"正确率:%f",k);
outtextxy(0,40,szScoreInfo);
}
}
EXIT:
// 退出部分
goodbye();
// 关闭图形界面
closegraph();
}
void tongguan()
{
setcolor(RED);
setfont(64, 0, "华文行楷");
outtextxy(80, 250, "你真厉害,恭喜通关");
Sleep(5000);//实现暂停
goto EXIT;
EXIT:
goodbye();
// 关闭图形界面
closegraph();
}
// 主函数
int main(void)
{
// 初始化屏幕为 640x480
initgraph(640, 480);
help(); //显示帮助界面
return 0;
}
没有合适的资源?快使用搜索试试~ 我知道了~
打字游戏,C语言工程,内含源代码和可执行程序
共15个文件
pdb:2个
cpp:2个
h:2个
需积分: 10 20 下载量 142 浏览量
2010-10-25
22:18:15
上传
评论
收藏 196KB RAR 举报
温馨提示
用C语言仿TC下写的打字游戏,最初思想来源于C语言吧,经过充实,加入了一些自己的想法,提供再此给大家交流!欢迎下载
资源推荐
资源详情
资源评论
收起资源包目录
指法练习.rar (15个子文件)
指法练习
StdAfx.h 769B
graphics.h 10KB
指法练习.plg 758B
指法练习.dsp 3KB
指法练习.dsw 524B
Debug
vc60.pdb 76KB
指法练习.pdb 593KB
指法练习.obj 22KB
指法练习.exe 232KB
graphics6.lib 49KB
graphics6u.lib 49KB
StdAfx.cpp 299B
指法练习.opt 53KB
指法练习.cpp 7KB
指法练习.ncb 41KB
共 15 条
- 1
资源评论
shashenyidaoOCEAN
- 粉丝: 5
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功