简易飞机空战小游戏

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<time.h>
#include<windows.h>#define  width  30				//屏幕的宽
#define  high   40				//屏幕的高
#define  EnemyAirportNum  5		//敌机出现的数量
#define  MyFly     1			//我方飞机
#define  EnemyFly  2			//敌方飞机
#define  Bullet    3			//子弹int  FlyShow[high][width] = {0};		//游戏界面
int  EnemyAirport_x[EnemyAirportNum], EnemyAirport_y[EnemyAirportNum];			//敌机的坐标
int  MyAirport_x, MyAirport_y;			//我方战机坐标
int  speed;								//敌方战机速度
int  score;								//分数
int BulletWidth;						//子弹宽度void  gotoxy(int x, int y)//清屏
{HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);COORD pos;pos.X = x;pos.Y = y;SetConsoleCursorPosition(handle, pos);
}
void  HideCursor()//隐藏光标
{CONSOLE_CURSOR_INFO cursor_info = { 1, 0 };SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}void  Init()
{MyAirport_x = width / 2;MyAirport_y = high-5;FlyShow[MyAirport_y][MyAirport_x] = MyFly;for (int k = 0; k < EnemyAirportNum; k++)//依次初始化EnemyAirportNum个敌机位置{EnemyAirport_x[k] = rand() % (width-1);EnemyAirport_y[k] = rand() % high / 2;FlyShow[EnemyAirport_y[k]][EnemyAirport_x[k]] = EnemyFly;}speed = 10;score = 0;BulletWidth = 1;HideCursor();
}void  show()
{gotoxy(0, 0);static int i = 0;if (i < 100)i++;if (i == 100)//主循环100次刷一次屏{system("cls");i = 0;}//打印战机及子弹for (int y = 0; y < high; y++){for (int x = 0; x < width; x++){for (int k = 0; k < EnemyAirportNum; k++){if ((y == EnemyAirport_y[k]) && (x == EnemyAirport_x[k]))//打印敌机printf("@");}if (FlyShow[y][x] == MyFly)//打印我方战机printf("*");else if (FlyShow[y][x] == Bullet)//打印子弹printf("!");elseprintf(" ");}printf("\n");}printf("得分:%d\n", score);
}void  Player()
{char  input;if (kbhit()){input = getch();switch (input){case 72:  {FlyShow[MyAirport_y][MyAirport_x] = 0;//将当前位置置为0,即在移动战机时清除轨迹if (MyAirport_y>0)MyAirport_y--;FlyShow[MyAirport_y][MyAirport_x] = MyFly;//将战机原位置的上一个位置显示出战机}break;     //上移战机case 80:  {FlyShow[MyAirport_y][MyAirport_x] = 0;if (MyAirport_y<high-1)MyAirport_y++;FlyShow[MyAirport_y][MyAirport_x] = MyFly;}break;  //下移战机case 75:  {FlyShow[MyAirport_y][MyAirport_x] = 0;if (MyAirport_x>0)MyAirport_x--;FlyShow[MyAirport_y][MyAirport_x] = MyFly;} break;     //左移战机case 77:  {FlyShow[MyAirport_y][MyAirport_x] = 0;if (MyAirport_x<width-2)MyAirport_x++;FlyShow[MyAirport_y][MyAirport_x] = MyFly;} break;     //右移战机case 32:  {//显示一定宽度的子弹int left, right;left = MyAirport_x - BulletWidth;if (left < 0)left = 0;right = MyAirport_x + BulletWidth;if (right > width - 1)right = width - 1;for (int x = left; x < right;x++)FlyShow[MyAirport_y-1][x] = Bullet;} break;}}
}int  UpdateComputer()
{static int i = 0;if (i < speed)//减小敌机的移速i++;for (int y = 0; y < high; y++){for (int x = 0; x < width; x++){if (FlyShow[y][x] == Bullet)//当前位置是子弹{FlyShow[y][x] = 0;if (y>0)FlyShow[y - 1][x] = Bullet;//显示子弹上移轨迹for (int k = 0; k < EnemyAirportNum; k++)//判断是否击中敌机{if ((EnemyAirport_x[k] == x) && (EnemyAirport_y[k]) == y)//当前位置以敌机位置相同时{score++;//分数+1//再次出现一架敌机EnemyAirport_x[k] = rand() % (width-1);EnemyAirport_y[k] = rand() % high / 2;FlyShow[EnemyAirport_y[k]][EnemyAirport_x[k]] = EnemyFly;}}}}}if (i == speed)//计次满时移动敌机{for (int k = 0; k < EnemyAirportNum; k++){EnemyAirport_y[k]++;//敌机移动if (EnemyAirport_y[k] > high)//敌机出界时{score--;//分数-1//再次出现一架敌机EnemyAirport_x[k] = rand() % (width - 1);EnemyAirport_y[k] = rand() % high / 2;FlyShow[EnemyAirport_y[k]][EnemyAirport_x[k]] = EnemyFly;}if ((EnemyAirport_x[k] == MyAirport_x) && (EnemyAirport_y[k]) == MyAirport_y)//我方战机与敌机相撞时游戏结束 {printf("游戏结束\n");return 0;}}i = 0;}if (score > 30 && (score % 20 == 0)&&speed>0){speed -= 1;i = 0;}if (score > 30 && (score % 15 == 0) && BulletWidth <width){BulletWidth++;}return 1;
}int  main()
{Init();int flag = 1;while (flag){show();Player();flag=UpdateComputer();}system("pause");return  0;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/545767.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

kotlin获取属性_Kotlin程序| 属性获取器和设置器方法的示例

kotlin获取属性属性获取器和设置器方法 (Properties Getter and Setter Methods) Variable having a class-level scope, declared inside the class body but outside the functions called property. 具有类级别范围的变量&#xff0c;在类主体内部但在称为属性的函数外部声明…

忘记MySQL密码怎么办?一招教你搞定!

作者 | 王磊来源 | Java中文社群&#xff08;ID&#xff1a;javacn666&#xff09;转载请联系授权&#xff08;微信ID&#xff1a;GG_Stone&#xff09;在安装完 MySQL 或者是在使用 MySQL 时&#xff0c;最尴尬的就是忘记密码了&#xff0c;墨菲定律也告诉我们&#xff0c;如果…

vb读出二进制文件,合并两个文件

Dim FileMe() As Byte, File1() As Byte, File2() As Byte Dim Ii As Integer, Ss As String 读入程序自身 Open App.Path & "\" & App.EXEName & ".exe" For Binary As #11 ReDim FileMe(FileLen(App.Path & "\" & App.EXE…

通讯录动态版

#include<stdio.h> #include<stdlib.h> #include<string.h>enum operation {EXIT, //退出ADD, //添加SEARCH, //查找DELETD, //删除AMEND, //修改SHOW //显示 };enum object {X_NAME, //名字X_AGE, //年龄X_TELNUMBER,//电话号码X_ADDRESS //住址 };…

icmp消息类型报告传输_ICMP消息的类型和ICMP消息格式

icmp消息类型报告传输ICMP shares error reporting and devices status by messages. Messages created by ICMP are divided into 2 categories: ICMP通过消息共享错误报告和设备状态。 ICMP创建的消息分为两类&#xff1a; 1) Error Reporting Messages 1)错误报告消息 The…

一文详解「队列」,手撸队列的3种方法!

作者 | 王磊来源 | Java中文社群&#xff08;ID&#xff1a;javacn666&#xff09;转载请联系授权&#xff08;微信ID&#xff1a;GG_Stone&#xff09;本文已收录至我的 Github《算法图解》系列&#xff1a;https://github.com/vipstone/algorithm前面我们介绍了栈&#xff08…

Oracle11完全卸载方法

一、在oracle11G以前卸载oracle会存在卸载不干净&#xff0c;导致再次安装失败的情况&#xff0c;在运行services.msc打开服务&#xff0c;停止Oracle的所有服务。二、 oracle11G自带一个卸载批处理\app\Administrator\product\11.2.0\dbhome_1\deinstall\deinstall.bat运行该批…

斐波拉切数列

问题陈述&#xff1a; Fibonacci为1200年代的欧洲数学家&#xff0c;在他的著作中曾经提到&#xff1a;若有一只兔子每个月生一只小兔子&#xff0c;一个月后小兔子也开始生产。起始只有一只兔子&#xff0c;一个月后就有两只兔子&#xff0c;二个月后有三只兔子&#xff0c;三…

自定义设置一个屏保程序

用C语言写一个简单的窗口程序&#xff0c;目的是生成一个可视化的图形窗口&#xff0c;需要用到EasyX库&#xff0c;可在文章末尾的网盘链接中下载。该程序退出需左击鼠标&#xff0c;否则无法退出。 #include<stdio.h> #include<stdlib.h> #include<windows.h…

JavaScript中带示例的字符串search()方法

字符串search()方法 (String search() Method) search() is method is a String method, it is used to check whether a substring exists in the given string or not. It returns the starting index of the substring from the string where substring exists. If substrin…

漫画:如何找到链表的倒数第n个结点?

————— 第二天 —————什么意思呢&#xff1f;我们以下面这个链表为例&#xff1a;给定链表的头结点&#xff0c;但并不知道链表的实际长度&#xff0c;要求我们找到链表的倒数第n个结点。假设n3&#xff0c;那么要寻找的结点就是元素1&#xff1a;如何利用队列呢&…

转:开源图形库 c语言-图形图像库 集合

Google三维API O3DO3D 是一个开源的 Web API 用来在浏览器上创建界面丰富的交互式的 3D 应用程序。这是一种基于网页的可控3D标准。此格式期望真正的基于浏览器&#xff0c;独立于操作系统之外&#xff0c;并且支持主流的3D显卡&#xff0c;这样就可以在网页中实现效果逼真的3D…

cacti添加I/O监控

首先下载snmpdiskio-0.9.6.zip,文件不好找&#xff0c;我已经放在本文章的附件里面。解压snmpdiskio-0.9.6.zip复制partition.xml到cacti/resource/snmp_queries/下面[roottest]# cp partition.xml /home/wwwroot/default/cacti/resource/snmp_queries/分别导入模板文件&#x…

数组中的reverse_数组reverse()方法以及JavaScript中的示例

数组中的reverseJavaScript reverse()方法 (JavaScript reverse() method) reverse() method is used to reverse the order of the elements in an array, it changes the actual array and also returns an array with reversed elements. reverse()方法用于反转数组中元素的…

磊哥私藏书单分享,160买400的书!

程序员的节日&#xff08;10.24&#xff09;到了&#xff0c;当当的活动也搞起来了&#xff0c;作为有上进心的你&#xff0c;怎么可能停止学习和进步呢&#xff1f;所以磊哥在当当满 400 元减 200 元的基础上&#xff0c;有要了一个减 40 的劵&#xff0c;也就是只需要花 160 …

ORACLE中使用递归查询

在数据库查询中常常会碰到要查询树形结构的数据&#xff0c;需要用一个字段的数据当做下一条记录的父节点继续查询&#xff0c;如果在不知道有多少级节点的情况下一次次手写SQL查询会很繁琐而没有效率&#xff0c;这时可以使用 oracle中的connect with prior递归算法&#xff1…

linux——回射服务器

回射服务器即客户端发送一段数据给服务器&#xff0c;服务器再将这段数据原封不动的发送给客户端&#xff0c;原理很简单&#xff0c;原理图如下&#xff1a; 以TCP协议为例&#xff0c;客户端、服务器代码如下&#xff1a; ** 服务器&#xff1a; ** #include <stdio.h…

Android 5.0 API 的变化——开发人员注意

Android 5.0 API变化译自 http://developer.android.com/intl/zh-cn/about/versions/android-5.0.html —— By NashLegendSample示例在这里找&#xff1a;https://github.com/googlesamples/原译文在我的github上&#xff1a;https://github.com/NashLegend/ProjectBabel/blob…

dbms标识符无效_DBMS中的聚合运算符(分组依据和具有子句)

dbms标识符无效综合运营商 (Aggregate Operators) To calculate aggregate values, one requires some aggregate operators to perform this task. These operators run over the columns of a relation. The total number of five aggregate operators is supported by SQL a…

Java中的5大队列,你知道几个?

作者 | 王磊来源 | Java中文社群&#xff08;ID&#xff1a;javacn666&#xff09;转载请联系授权&#xff08;微信ID&#xff1a;GG_Stone&#xff09;本文已收录至 https://github.com/vipstone/algorithm 《算法图解》系列。通过前面文章的学习《一文详解「队列」&#xff0…