话不多说,直接开更:c++代码 飞机大战
#include<iostream>
#include<stdlib.h>
#include<conio.h>
#include<windows.h>
#include<cmath>
using namespace std;
//函数外全局变量定义
int position_x1, position_y1; //飞机位置
int position_x2, position_y2; //飞机位置
int position_x3, position_y3; //飞机位置
int bullet_x, bullet_y; //子弹位置
int high=35, width=55; //游戏画面尺寸
int enemy_x[40],enemy_y[40];
int enemy_x2[40],enemy_y2[40];
int enemy_xb[40],enemy_yb[40]; //敌机子弹位置
int score=1;
int a[100][100]={0};
int number; //敌机数量
int ew=1;
int bw=2; //子弹宽度
int k=0;
int j=1;
int je=1;
void startup() //数据初始化
{
position_x1 = high-3;
position_y1 = width/2;
position_x2 = high-2;
position_y2 = width/2-1;
position_x3 = high-1;
position_y3 = width/2;
a[position_x1][position_y1]=1; //1表示飞机
bullet_x = -1;
bullet_y = position_y1;
a[position_x2][position_y2]=5; //5表示飞机
a[position_x3][position_y3]=6; //6表示飞机
number=3; //初始飞机数量
for(int i=0;i<number;i++)
{
enemy_x[i]= 0;
enemy_y[i]=rand()%(width/number-2)+(width/number-2)*i+3;
a[enemy_x[i]][enemy_y[i]]=3; //3表示敌机
enemy_xb[i]=enemy_x[i];
enemy_yb[i]=enemy_y[i]+1;
a[enemy_xb[i]][enemy_yb[i]]=7; //7表示敌机子弹
enemy_x2[i]= -1;
enemy_y2[i]=enemy_y[i]-1;
a[enemy_x2[i]][enemy_y2[i]]=4; //4表示敌机
}
}
void gotoXY(int x, int y) //光标移动到(x,y)位置
{
COORD pos = { x,y };
HANDLE