#include

#include

#include

#include

#include

#include

#include

#define OK 1

#define ERROR 0

#define STACK_INIT_SIZE 10// 存储空间初始分配量

#define STACKINCREMENT 1// 存储空间分配增量

typedef char SElemType; // 定义栈元素类型

typedef int Status; // Status是函数的类型,其值是函数结果状态代码,如OK等

IMAGE Background;

IMAGE Foreground;

IMAGE Restart;

IMAGE Rest;

time_t start, end;

int loss;

const int Width = 556;

const int Height = 720;

char Alice[30] = { "ALICE SYNTHESIS THIRTY" };

char word[10][10] = { "include","main","return","void","switch","case","struct","typedef","fopen" };

struct TARGET

{

float x;

float y;

char *word;

}Target[3];

void image();

void site();

void show();

void run();

void get();

void Reset();

void AliceError();

void BackSpace();

void ClearText();

void InitWord(int n);

char text[10] = { '\0' };

struct SqStack

{

SElemType *base; // 在栈构造以前和销毁以后,base的值为NULL

SElemType *top; // 栈顶指针

int stacksize; // 当前已分配的存储空间,以元素为单位

}S; // 顺序栈

Status InitStack()

{

// 构造一个空栈S,该栈预约义大小为STACK_INIT_SIZE

S.base = (SElemType*)malloc(STACK_INIT_SIZE * sizeof(SElemType));

if (!S.base) return ERROR;

S.top = S.base;

S.stacksize = STACK_INIT_SIZE;

return OK;

}

Status Push(SElemType e)

{

// 在栈S中插入元素e为新的栈顶元素

if (S.top - S.base >= S.stacksize)

{

S.base = (SElemType*)realloc(S.base, (S.stacksize + STACKINCREMENT) * sizeof(SElemType));

if (!S.base) return ERROR;

S.top = S.base + S.stacksize;

S.stacksize += STACKINCREMENT;

}

*S.top++ = e;

return OK;

}

Status Pop(SElemType &e)

{

// 若栈不空,则删除S的栈顶元素,用e返回其值,并返回OK;不然返回ERROR

if (S.top == S.base) return ERROR;

e = *--S.top;

return OK;

}

Status ClearStack()

{

// 把S置为空栈

S.top = S.base;

return OK;

}

int StackLength()

{

// 返回栈S的元素个数

int i;

i = S.top - S.base;

return i;

}

void LineEdit()

{

int n;

SElemType e;

SElemType *p = (SElemType *)malloc(sizeof(SElemType));

if (_kbhit())

{

e = _getch();

if (e == 32)

{

putimage(0, 0, &Rest);

FlushBatchDraw();

char stop = _getch();

if (stop == 27)

exit(NULL);

}

else if (e == 8)

{

Pop(e);

BackSpace();

}

else if (e >= 97 && e <= 122 && StackLength() < 10)

{

Push(e);

}

}

p = S.base;

for (n = 0; n < StackLength(); n++)

{

text[n] = *p++;

}

for (n = 0; n < 3; n++)

{

if (strcmp(text, Target[n].word) == 0)

{

ClearStack();

ClearText();

InitWord(n);

}

}

}

int main() // 主函数

{

initgraph(Width, Height);

image();

BeginBatchDraw();

/*开始界面*/

site();

while (true)

{

while (difftime(end, start) < 60000)

{

show();

run();

get();

/*开始界面*/

FlushBatchDraw();

end = clock();

}

Reset();

}

EndBatchDraw();

closegraph();

}

void image()

{

loadimage(&Background, _T("D:\\暂存Ⅱ\\C project demo Ⅱ\\Type_Defend\\Texture\\Background.png"));

loadimage(&Foreground, _T("D:\\暂存Ⅱ\\C project demo Ⅱ\\Type_Defend\\Texture\\Foreground.png"));

loadimage(&Restart, _T("D:\\暂存Ⅱ\\C project demo Ⅱ\\Type_Defend\\Texture\\Restart.png"));

loadimage(&Rest, _T("D:\\暂存Ⅱ\\C project demo Ⅱ\\Type_Defend\\Texture\\Rest.png"));

}

void site()

{

start = clock();

InitStack();

loss = 0;

int n;

for (n = 0; n < 3; n++)

{

InitWord(n);

Target[n].y -= n * 30;

}

}

void show()

{

putimage(0, 0, &Background);

int num;

for (num = 0; num < 3; num++)

{

setbkmode(TRANSPARENT);

settextcolor(RGB(200, 150, 150));

settextstyle(30, 0, _T("Verdana"));

outtextxy((int)Target[num].x, (int)Target[num].y, Target[num].word);

}

putimage(0, 0, &Foreground);

setbkmode(TRANSPARENT);

settextcolor(RGB(200, 150, 150));

settextstyle(30, 0, _T("Verdana"));

outtextxy(100, 240, Alice);

setlinecolor(RGB(200, 150, 150));

setfillcolor(RGB(200, 150, 150));

fillroundrect(30, 270, 530, 275, 5, 5);

setbkmode(TRANSPARENT);

settextcolor(RGB(200, 150, 150));

settextstyle(21, 0, _T("Verdana"));

outtextxy(60, 670, text);

TCHAR TIME[10];

TCHAR LOSS[10];

_stprintf_s(LOSS, _T("%2d"), loss);

_stprintf_s(TIME, _T("%2lld"), (60000 - (end - start)) / 1000);

outtextxy(420, 600, "TIME");

outtextxy(420, 635, "LOSS");

outtextxy(480, 600, TIME);

outtextxy(480, 635, LOSS);

static int fps = 0;

if (fps < 30)

{

fillrectangle(65 + textwidth(text), 670, 70 + textwidth(text), 690);

}

else if (fps > 60)

{

fps = 0;

}

fps += 1;

}

void run()

{

AliceError();

int n;

for (n = 0; n < 3; n++)

{

Target[n].y += (float)1.4;

if (Target[n].y > 590)

{

InitWord(n);

loss += 1;

}

}

}

void get()

{

LineEdit();

}

void Reset()

{

putimage(0, 0, &Restart);

FlushBatchDraw();

char input;

do

{

input = _getch();

} while (input != 32 && input != 27);

if (input == 32)

{

site();

}

else if (input == 27)

{

exit(NULL);

}

}

void AliceError()

{

static time_t Alice_start = clock(); time_t Alice_end = clock();

if ((difftime(Alice_end, Alice_start)) >= 30)

{

int n = rand() % 15 + 6;

while (n == 15)

n = rand() % 15 + 6;

Alice[n] = rand() % 26 + 65;

Alice_start = clock();

}

}

void BackSpace()

{

int n;

for (n = 0; text[n + 1] != '\0'; n++)

continue;

text[n] = '\0';

}

void ClearText()

{

int n;

for (n = 0; text[n] != '\0'; n++)

text[n] = '\0';

}

void InitWord(int n)

{

srand((unsigned int)time(NULL));

Target[n].word = word[rand() % 10];

while (Target[n].word == Target[(n + 1) % 3].word || Target[n].word == Target[(n + 2) % 3].word)

Target[n].word = word[rand() % 10];

Target[n].x = (float)(rand() % 300 + 100);

Target[n].y = (float)(-n * 30 + 240);

}

练习打字程序游戏 c语言,VS2017 C语言制做打字练习游戏相关推荐

  1. 世上最杰出程序员,B 语言、Unix 之父为玩游戏,写了个操作系统

    作者 | 年素清 责编 | 伍杏玲 出品 | 程序人生(ID:coder_life) Unix之父--肯•汤普森(Ken Thompson)被称作"世界上最杰出的程序员",他自学编 ...

  2. c语言程序游戏玩家管理系统,c语言程序课程设计--游戏玩家管理系统及C语言课程设计_简易计算器.doc...

    湖南涉外经济学院 课程设计报告 课程名称: C语言课程设计 报告题目: 游戏玩家管理系统 学生姓名: ** ** 所在学院: 信息科学与工程学院 专业班级: 电科 学生学号: **** ****** ...

  3. 【C语言】之实现简单的打字程序

    /************************************************ 文件名:typeWroe.c* 文件描述:实现简易的字符界面的打字程序-linux平台下* 编写人: ...

  4. c语言写一个格子涂色的游戏,不一样的涂色游戏小程序,这个魔力贴贴涂色游戏有点意思...

    原标题:不一样的涂色游戏小程序,这个魔力贴贴涂色游戏有点意思 30000+游戏爱好者已加入我们! 沐沐带你发现好游戏! <魔力贴贴>游戏小程序好玩吗? <魔力贴贴>小游戏怎么玩 ...

  5. c语言数据结构设计纸牌游戏,求一用数据结构c++编写的纸牌游戏程序

    需求: 1.一副没有J.Q.K.A.大小王的扑克牌(40张牌),编号为1-40张牌.第一回合,从40张牌中给双方各随机抽取5张牌,抽出的牌在原数组里删除.第二回合,从剩下30张牌中给双方各随机抽取5张 ...

  6. C语言零基础项目:打字母游戏!详细思路+源码分享

    每天一个C语言小项目,提升自己的编程能力!​ <字母游戏>是一款有趣的打字游戏,可以提高你的打字速度. 今天就用C语言写了这么个打字母的小程序,就是以前学习机上那种字母往下掉,然后按相应键 ...

  7. C语言项目实战:《打字母游戏》零基础项目丨183 行源代码示例

    这篇文章主要为大家详细介绍了C语言实现--<打字练习系统>,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下! 游戏介绍: <字母游戏>是一款敏捷打 ...

  8. c++ 小游戏_C/C++编程笔记:C语言写推箱子小游戏,大一学习C语言练手项目

    C语言,作为大多数人的第一门编程语言,重要性不言而喻,很多编程习惯,逻辑方式在此时就已经形成了.这个是我在大一学习 C语言 后写的推箱子小游戏,自己的逻辑能力得到了提升,在这里同大家分享这个推箱子小游 ...

  9. python小游戏开发,使用python实现英语打字游戏

    需求分析 英文打字小游戏,要有多界面交互,界面整洁.美观,可调节游戏等级难度,可配置游戏信息. 要有游戏分数,游戏时间,动画特效,背景音乐,不同游戏等级的历史最高分记录. 拼写成功的英文单词显示中文意 ...

  10. swift语言注册非免费苹果账号iOS游戏框架Sprite Kit基础教程

    swift语言注册非免费苹果账号iOS游戏框架Sprite Kit基础教程 1.2.3  注册非免费苹果账号swift语言注册非免费苹果账号iOS游戏框架Sprite Kit基础教程 免费的苹果账号在 ...

最新文章

  1. 【学术】直博和读完硕士再读博,在能力上的差距有多大?
  2. 新书推荐:《追问人工智能:从剑桥到北京》
  3. C++ Exercises(六)
  4. html wbr标签,HTML wbr标签
  5. Linux内核源代码分析——fork()原理多进程网络模型
  6. VS2010编译安装OpenCV2.4.3
  7. Python可以这样学(第九季 机器学习案例与实战)-董付国-专题视频课程
  8. Django-ModelFrom中修改save后的字段值
  9. Linux 索引节点 inode
  10. 如何搭建j2ee开发环境
  11. 计蒜客-----单独的数字(map)
  12. 智慧新泰时空大数据与云平台_《智慧城市时空大数据与云平台建设技术大纲》(2017版)正式发布...
  13. 语言包常用语言对应代码
  14. OpenCV 帧差法
  15. [渝粤教育] 中国地质大学 岩石学 复习题
  16. 进程管理(C/C++)
  17. 简化3D渲染和动画制作丨上海道宁为您带来强大的3D渲染软件——KeyShot
  18. GCC——C compiler
  19. 机器学习读书笔记:半监督学习
  20. ks 怎么抓salt值?api,did?

热门文章

  1. 16进制颜色透明度对照表
  2. crc32 C语言程序
  3. html修改img图片颜色,html中img图片设置透明度的方法
  4. 电脑桌面便签小工具下载,好用的桌面便签软件推荐
  5. DHCP报文抓包分析
  6. 大数据入门教程系列之Hive篇汇总
  7. 微信小程序父子组件之间传值
  8. H3CNE实验(一)静态路由
  9. android 2048小游戏实现代码
  10. 【论文翻译】从零开始PointNet论文分析与代码复现