用c++写一个简单的打字游戏
2017-11-22 20:57
459 查看
#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);
}
}
}
相关文章推荐
- 使用C++与SFML编写一个简单的撞球游戏Part3——创建游戏启动界面
- 使用C++与SFML编写一个简单的撞球游戏Part2——创建游戏窗口
- 使用C++与SFML编写一个简单的撞球游戏Part5——对象管理
- 使用C++与SFML编写一个简单的撞球游戏Part4——添加玩家弹板
- 一个简单的游戏引擎核心状态机的C++实现
- 使用C++与SFML编写一个简单的撞球游戏Part7——弹球的碰撞检测
- 用C++和EasyX图形库编写一个简单的打砖块游戏(下)
- 使用C++与SFML编写一个简单的撞球游戏Part8——添加AI弹板
- 使用C++与SFML编写一个简单的撞球游戏Part1——新建工程以及设置
- 使用C++与SFML编写一个简单的撞球游戏Part6——添加弹板控制与弹球
- 解答: 一个简单的c++程序
- 做一个简单的猜拳游戏
- WatchKit入门:创建一个简单的猜数游戏
- (转)【Android游戏开发十六】Android Gesture之【触摸屏手势识别】操作!利用触摸屏手势实现一个简单切换图片的功能!
- 用construct2制作一个简单的platform游戏
- 从零开始C++ 第二课 CC++初体验,编写一个简单的程序·hello C++ 课程一天第二课
- 一个简单的使用C++在运行时获取调用堆栈的类
- 怎样用HTML5 Canvas制作一个简单的游戏
- C++的一个简单的句柄类模板
- 如何创建一个简单的C++同步锁框架(译)