用c++写一个简单的打字游戏
来源:互联网 发布:知我药妆产品是正品吗 编辑:程序博客网 时间:2024/05/19 21:40
#include <graphics.h> //图形界面的头文件
#include <conio.h>
#include <time.h> //随机数
#include <stdio.h>
#include <mmsystem.h>
#pragma comment(lib,"winmm.lib")
HWND hWnd;
void Welcome();
void PlayGame();
//主函数
int main()
{
Welcome();
PlayGame();
closegraph();
return 0;
}
//欢迎的界面
void Welcome()
{
initgraph(640, 480); //640 480
loadimage(NULL, L"1.jpg");
srand((unsigned int)time(NULL));
//mci:media contral interface 多媒体控制接口
mciSendString(L"open 追光者.mp3 alias zz", 0, 0, 0);
mciSendString(L"play zz", 0, 0, 0);
setbkmode(0); // 透明的 英文怎么写? TRANSPARENT
settextcolor(YELLOW);
settextstyle(50, 0, L"微软雅黑");
outtextxy(185, 50, L"打 字 练 习 系 统");
settextcolor(BLACK);
settextstyle(20, 0, L"宋体");
outtextxy(220, 180, L"没什么好说的");
outtextxy(220, 230, L"我给大家拜个早年吧");
outtextxy(220, 280, L"新年快乐~-~");
outtextxy(220, 330, L"对了,记得把输入法切换成大写");
outtextxy(380, 380, L"—小小");
while (!_kbhit())
{
settextcolor(RGB(rand() % 256, rand() % 256, rand() % 256));
outtextxy(250, 430, L"按任意键继续...");
Sleep(200);
}
_getch();
}
void PlayGame()
{
cleardevice();
while (1)
{
hWnd = GetHWnd();
char obj;//目标字母
char key; //按键的字母
int objx, objy;//目标字母的坐标
obj = rand() % 26 + 65;
objx = rand() % 610 + 5;
settextstyle(30, 0, L"微软雅黑");
settextcolor(RGB(rand() % 156 + 100, rand() % 156 + 100, rand() % 256));
for (objy = 0; objy < 480; objy++)
{
cleardevice();
outtextxy(objx, objy, obj);
Sleep(10);
if (_kbhit())
{
key = _getch();
if (key == obj)
{
break;
}
else
{
MessageBox(hWnd, L"按错了,还需要继续努力哦!", L"game over", MB_OK);
exit(0);
}
}
}
if (objy >= 480)
{
MessageBox(hWnd, L"太慢了,还需要继续努力哦!", L"game over", MB_OK);
exit(0);
}
}
}
#include <conio.h>
#include <time.h> //随机数
#include <stdio.h>
#include <mmsystem.h>
#pragma comment(lib,"winmm.lib")
HWND hWnd;
void Welcome();
void PlayGame();
//主函数
int main()
{
Welcome();
PlayGame();
closegraph();
return 0;
}
//欢迎的界面
void Welcome()
{
initgraph(640, 480); //640 480
loadimage(NULL, L"1.jpg");
srand((unsigned int)time(NULL));
//mci:media contral interface 多媒体控制接口
mciSendString(L"open 追光者.mp3 alias zz", 0, 0, 0);
mciSendString(L"play zz", 0, 0, 0);
setbkmode(0); // 透明的 英文怎么写? TRANSPARENT
settextcolor(YELLOW);
settextstyle(50, 0, L"微软雅黑");
outtextxy(185, 50, L"打 字 练 习 系 统");
settextcolor(BLACK);
settextstyle(20, 0, L"宋体");
outtextxy(220, 180, L"没什么好说的");
outtextxy(220, 230, L"我给大家拜个早年吧");
outtextxy(220, 280, L"新年快乐~-~");
outtextxy(220, 330, L"对了,记得把输入法切换成大写");
outtextxy(380, 380, L"—小小");
while (!_kbhit())
{
settextcolor(RGB(rand() % 256, rand() % 256, rand() % 256));
outtextxy(250, 430, L"按任意键继续...");
Sleep(200);
}
_getch();
}
void PlayGame()
{
cleardevice();
while (1)
{
hWnd = GetHWnd();
char obj;//目标字母
char key; //按键的字母
int objx, objy;//目标字母的坐标
obj = rand() % 26 + 65;
objx = rand() % 610 + 5;
settextstyle(30, 0, L"微软雅黑");
settextcolor(RGB(rand() % 156 + 100, rand() % 156 + 100, rand() % 256));
for (objy = 0; objy < 480; objy++)
{
cleardevice();
outtextxy(objx, objy, obj);
Sleep(10);
if (_kbhit())
{
key = _getch();
if (key == obj)
{
break;
}
else
{
MessageBox(hWnd, L"按错了,还需要继续努力哦!", L"game over", MB_OK);
exit(0);
}
}
}
if (objy >= 480)
{
MessageBox(hWnd, L"太慢了,还需要继续努力哦!", L"game over", MB_OK);
exit(0);
}
}
}
阅读全文
1 0
- 用c++写一个简单的打字游戏
- jQuery 写的简单打字游戏
- 自己写的一个打字游戏
- Qt实现一个简单的打字游戏
- JavaScript写的打字游戏
- 用C语言实现的打字游戏
- 我用C写的打字程序
- 简单的Java打字游戏
- c写的一个简单的打飞机游戏
- C::写一个简单的猜字游戏
- Java 写的打字游戏,不喜勿喷
- js+canvas+html 写的打字游戏
- javascript实现的简单打字游戏
- 简单的打字游戏心得体会(代码)
- jQuery实现简单的打字游戏功能
- 一个用wiEngine写的非常简单的游戏
- 用jquery简单实现打字游戏
- turbo C 下的打字游戏
- 虚拟机播放本地视频,qemu有大量Write?
- easyui中combobox为什么没有加载json
- python3.x之super()用法小结
- 原始下载
- Linux基础知识
- 用c++写一个简单的打字游戏
- unity-开发小游戏遇到的难题日记
- 学习简单算法的第一天
- Angular2实现父子组件通信(详解)
- extern "C"的用法解析——转载
- 代码诊所
- define与inline
- 自定义控件:垂直轮播的小贴士Banner,仿 淘宝app的“淘宝头条”
- jsp中获取session中的map对象