该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

#include

#include

#include

#include

// 全局变量

int position_x,position_y; // 飞机位置

int bullet_x,bullet_y; // 子弹位置

int enemy_x,enemy_y; // 敌机位置

int high,width; // 游戏画面尺寸

int score; // 得分

void gotoxy(int x,int y)//类似于清屏函数,光标移动到原点位置进行重画

{

HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);

COORD pos;

pos.X = x;

pos.Y = y;

SetConsoleCursorPosition(handle,pos);

}

void startup() // 数据初始化

{

high = 20;

width = 30;

position_x = high/2;

position_y = width/2;

bullet_x = -2;

bullet_y = position_y;

enemy_x = 0;

enemy_y = position_y;

score = 0;

}

void show() // 显示画面

{

gotoxy(0,0); // 光标移动到原点位置进行重画清屏

int i,j;

for (i=0;i

{

for (j=0;j

{

if ((i==position_x) && (j==position_y))

printf("*"); // 输出飞机*

else if ((i==enemy_x) && (j==enemy_y))

printf("@"); // 输出敌机@

else if ((i==bullet_x) && (j==bullet_y))

printf("|"); // 输出子弹|

else

printf(" "); // 输出空格

}

printf("\n");

}

printf("得分:%d\n",score);

}

void updateWithoutInput() // 与用户输入无关的更新

{

if (bullet_x>-1)

bullet_x--;

if ((bullet_x==enemy_x) && (bullet_y==enemy_y)) // 子弹击中敌机

{

score++; // 分数加1

enemy_x = -1; // 产生新的飞机

enemy_y = rand()%width;

bullet_x = -2; // 子弹无效

}

if (enemy_x>high) // 敌机跑出显示屏幕

{

enemy_x = -1; // 产生新的飞机

enemy_y = rand()%width;

}

// 用来控制敌机向下移动的速度。每隔几次循环,才移动一次敌机

// 这样修改的话,用户按键交互速度还是保持很快,但我们NPC的移动显示可以降速

static int speed = 0;

if (speed<20)

speed++;

if (speed == 20)

{

enemy_x++;

speed = 0;

}

}

void updateWithInput() // 与用户输入有关的更新

{

char input;

if(kbhit()) // 判断是否有输入

{

input = getch(); // 根据用户的不同输入来移动,不必输入回车

if (input == 'a')

position_y--; // 位置左移

if (input == 'd')

position_y++; // 位置右移

if (input == 'w')

position_x--; // 位置上移

if (input == 's')

position_x++; // 位置下移

if (input == ' ') // 发射子弹

{

bullet_x = position_x-1; // 发射子弹的初始位置在飞机的正上方

bullet_y = position_y;

}

}

}

int main()

{

startup(); // 数据初始化

while (1) // 游戏循环执行

{

show(); // 显示画面

updateWithoutInput(); // 与用户输入无关的更新

updateWithInput(); // 与用户输入有关的更新

}

}

c语言重画清屏函数,写了个小程序,一直会闪屏,用的gotoxy函数,求大神教相关推荐

  1. 小程序swiper切换闪屏问题

    小程序swiper滑动闪屏问题 在小程序开发过程中使用swiper做轮播图,发现当用户切换图片过快时会出现异常的闪屏现象,官方文档 中描述了这个Bug & Tip: 在电脑上测试的时候没有问题 ...

  2. c语言清屏小程序,写了个小程序,一直会闪屏,用的gotoxy函数,求大神教

    该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 #include #include #include #include // 全局变量 int position_x,position_y; // 飞机位 ...

  3. c语言gotoxy函数dev,写了个小程序,一直会闪屏,用的gotoxy函数,求大神教

    该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 #include #include #include #include // 全局变量 int position_x,position_y; // 飞机位 ...

  4. c语言gotoxy函数是什么意思,写了个小程序,一直会闪屏,用的gotoxy函数,求大神教...

    该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 #include #include #include #include // 全局变量 int position_x,position_y; // 飞机位 ...

  5. c语言打印使用gotoxy函数,写了个小程序,一直会闪屏,用的gotoxy函数,求大神教...

    该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 #include #include #include #include // 全局变量 int position_x,position_y; // 飞机位 ...

  6. 微信小程序哪个能唱歌_我写了个小程序《声音精灵》,希望它未来能用 AI 教你唱歌~...

    最近几个月我一直在研究唱歌.之前我在知乎写过一个自学钢琴的回答:怎样自学钢琴?​www.zhihu.com 然而,对于从小不唱歌的人,学唱歌(更明确地说,流行唱法)比学乐器难得多!音准,气息,吐字,节 ...

  7. c语言数组读心术,无聊的时候写的读心术小程序

    该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 #include #include #include int main(void) { while(1) { system("cls" ...

  8. c语言读心术原理,无聊的时候写的读心术小程序

    该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 #include #include #include int main(void) { while(1) { system("cls" ...

  9. C语言 投票系统设计 求大神教~

    查找候选人 函数里 为什么只是一直显示没有您要查询的候选人    删除和修改 不用链表 甚至不用指针的话 能不能写 求教求手把手教 感激不尽. #include <stdio.h> #in ...

最新文章

  1. RESTful再理解
  2. Exchange 2007邮件服务器
  3. 分布式系统开发的一些相关理论基础——CAP、ACID、BASE
  4. xshell远程连接自动断开的问题解决
  5. Beta版冲刺Day1
  6. mysql8.0client_navicat 连接mysql8.0 报错client does not support authentication
  7. 阿里云在线web IDE:云效云端开发 DevStudio(ide.aliyun.com)
  8. 七十六、React中的TodoList和拆分组件,组件之间的传值
  9. java stream中Collectors的用法
  10. 算法设计与分析——动态规划——最长公共子序列
  11. 【NOI2016】优秀的拆分【后缀数组】【ST表】【关键点】【调和级数复杂度】【差分】
  12. HTML5 表单元素
  13. grunt + compass
  14. 提供高速信号接口认证测试 GRL上海实验室成立
  15. Android shell命令查询ip,网关,DNS
  16. python跨平台处理绝对路径和相对路径,open,with
  17. C语言判断一个数是否为素数
  18. 微信小程序支付接口对接总结
  19. s数据结构替换子表java版,数据结构(Java版)-习题解答与实验指导
  20. Mysql安装错误码1722_软件error 1771, error1722,error 1723解决办法

热门文章

  1. 职场PUA,管理者的五宗罪
  2. 用c语言验证1000以内的卡拉兹(Callatz)猜想
  3. 《挂机游戏制作工具手册》挂机游戏制作工具基础知识
  4. 分类器的ROC曲线及相关指标(ROC、AUC、ACC)详解
  5. android All
  6. R语言:ggplot2画带误差棒的折线图的过程及细节。
  7. 【Azure Data Platform】Azure SQLDW与ADLS的整合
  8. 工业电表接线方法,光纤接线方法、97,、2007协议
  9. 论语心得 04: 君子之道
  10. 解决python toad包报错joblib.externals.loky.process_executor.TerminatedWorkerError