资源简介
适合学习C语言,使用vc6.0开发,提高学习兴趣
代码片段和文件信息
#include
#include
#include
#include
using namespace std;
void welcome();
void begingame();
void exitgame();
int life=5;//生命值
char lifes[10];
int score=0;//得分
char scores[10];
char target[2] = “ “;
char key;
int N;
int n;
void welcome()
{
// 输出屏幕提示
cleardevice();
setcolor(YELLOW);
setfont(64 0 “楷体_GB2312“);
outtextxy(155 50 “打字母游戏“);
setfont(32 0 “楷体_GB2312“);
outtextxy(200 175 “请选择难度“);
setfont(20 0 “楷体_GB2312“);
outtextxy(200 220 “1非常简单“);
outtextxy(200 250 “2简单“);
outtextxy(200 280 “3中等“);
outtextxy(200 310 “4困难“);
outtextxy(200 340 “5非常困难“);
n=getch();
switch(n)
{
case ‘1‘:
N=1;
break;
case ‘2‘:
N=2;
break;
case ‘3‘:
N=3;
break;
case ‘4‘:
N=4;
break;
case ‘5‘:
N=5;
break;
default:
N=1;
break;
}
cleardevice();
}
/**/
void begingame()
{
cleardevice();
// 主循环
while(1)
{
target[0] = 65 + rand() % 26; // 产生任意大写字母
int x = rand()%640; //保证在屏幕之间出现字母
for (int y=60;y<=480; y=y+N)
{
setfont(26 0 “宋体“);
setcolor(GREEN);
outtextxy(x y target);
/**/
if(y>479)
life=life-1;
setcolor(RED);
setfont(200“黑体“);
sprintf(lifes“生命值为:%d“life);
outtextxy(15010lifes);
sprintf(scores“得分为:%d“score);
outtextxy(320 10 scores);
if(life==0)
goto over;
if(kbhit())
{
key = getch();
if(key==target[0]||key == target[0] + 32)//清除原字符
{
// 设置清除
setfont(200“黑体“);
setcolor(RED);
score=score+10;
sprintf(scores“得分为:%d“score);
outtextxy(320 10 scores);
setfont(26 0 “宋体“);
setcolor(BLACK);
outtextxy(x y target);
break;
}
if (key == 27)
{
exitgame();
}
}
/**/// 延时,并清除原字符
Sleep(5);
setcolor(BLACK);
outtextxy(x y target);
}
}
cleardevice();
over:
exitgame();
}
void exitgame()
{
cleardevice();
outtextxy(250150scores);
rebegin:
char ch;
setfont(150“黑体“);
if(life==0)
{
outtextxy(135 220 “游戏生命结束!!! 按Y退出游戏,按N重新开始游戏 Y/N“);
life=5;
}
else
{
outtextxy(135 220 “你真的要退出游戏吗? 按Y退出游戏,按N继续游戏 Y/N“);
}
ch=getch();
outtextxy(10 45 ch);
if(ch==‘Y‘||ch==‘y‘)
{
system(“pause“);
cout<<“退出游戏“< exit(0);
}
if(ch==‘N‘||ch==‘n‘)
{
system(“pause“);
cout<<“继续游戏“< begingame();
}
else
{
cleardevice();
outtextxy(135 180 “输入有误请重新输入:“);
goto rebegin;
}
cleardevice();
closegraph();
}
// 主函数
void main()
{
initgraph(640 480);
welcome();
begingame();
exitgame();
} 属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2894 2011-11-14 09:47 打字母游戏\打字母.cpp
文件 327722 2012-03-04 17:15 打字母游戏\打字母游戏.exe
目录 0 2012-03-04 22:57 打字母游戏
----------- --------- ---------- ----- ----
330616 3
- 上一篇:模拟Unix文件系统C语言版
- 下一篇:数据链路层各协议的实现算法
相关资源
- 猜数字游戏 c语言代码
- 移木块游戏,可以自编自玩,vc6.0编写
- C++纯文字DOS超小RPG游戏
- LINUX下命令行界面的C语言细胞游戏
- VC++MFC小游戏实例教程(实例)+MFC类库
- 用C语言实现的一个打字游戏
- C语言版3D魔方游戏源代码
- 打飞机小游戏57466
- 俄罗斯方块游戏源码(Tetris)
- c++ 猜拳小游戏
- 扫雷游戏.cpp
- 杨中科游戏开发引擎
- 智商超高的中国象棋游戏源码(C++版
- c++ 扫雷游戏源码(控制台)
- C++跑跑卡丁车
- C++“倒忌时”小游戏
- XX游戏客户端源码
- c++小游戏源码.doc
- 基于ege图形的推箱子游戏
- C语言ege贪吃蛇游戏
- C++小游戏4款(源码)
- 推箱子小游戏源码
- 五子棋游戏源码(控制台)
- 猜数字游戏.sb3
- C++贪吃蛇控制台小游戏代码
- 扫雷游戏.cpp(较简单)
- MFC五子棋游戏
- VC++ 大富翁4_大富翁游戏源码
- c++常用游戏算法及数据结构设计
- c++的飞行鸟游戏
川公网安备 51152502000135号
评论
共有 条评论