不知道怎么加边框也不知道加在哪😭
#include
#include<conio.h>
#include<time.h>
using namespace std;
int main()
{
int x = 5, y = 20;//飞机坐标
char input;//用于接收输入
bool isfire = false;//发射子弹的标志
int enemy_x = 6;//敌机坐标
bool iskilled = false;//敌机击中标志
srand(time(NULL));//随机函数种子重置
enemy_x = rand() % 20;//让敌机坐标随机产生
while (true)
{
/***********在(x,y)处显示飞机,分别用for,while,do,,,while实现************/
system("cls");
//用|表示子弹,根据isfire标志判断飞机上方显示空格,还是子弹。
//在飞机上方输出y-1行。
if (!iskilled)
{
//显示敌机
//敌机左边输出enemy_x-1个空格
for (int i = 0; i < enemy_x - 1; i++)
{
cout << " ";
}
cout << " ▲" << endl;
}
if (isfire)//发射子弹,在飞机上方显示。
{
//在飞机上方输出y-1行。
for (int i = 1; i < y; i++)
{
for (int j = 1; j < x; j++)//左边输出x-1个空格
{
cout << " ";
}
cout << " ||" << endl;
}
}
else//没发射子弹
{
//在飞机上方输出y-1行,
int i = y - 1;
while (i > 0)
{
cout << endl;
i--;
}
}
//在左边输出x-1个空格
int i = x - 1;
do
{
cout << " ";
i--;
} while (i > 0);
//输出飞机
cout << " !!" << endl;
//在左边输出x-1个空格
i = x - 1;
while (i > 0)
{
cout << " ";
i--;
}
cout << " ▲▲▲" << endl;
//在左边输出x-1个空格
for (i = 1; i < x; i++)
{
cout << " ";
}
cout << " ^ ^" << endl;
//cin>>input;用cin接受输入的方向信息
input = _getch();
if (input == 'a' || input == 75)
{
x--;
isfire = false;//将子弹标志消除
if (iskilled)//若敌机被击中,产生新的敌机
{
iskilled = false;
enemy_x = rand() % 20;
}
}
if (input == 'd' || input == 77)
{
x++;
isfire = false;//将子弹标志消除
if (iskilled)
{
iskilled = false;
enemy_x = rand() % 20;
}
}
if (input == 's' || input == 80)
{
y++;
isfire = false;//将子弹标志消除
if (iskilled)
{
iskilled = false;
enemy_x = rand() % 20;
}
}
if (input == 'w' || input == 72)
{
y--;
isfire = false;//将子弹标志消除
if (iskilled)
{
iskilled = false;
enemy_x = rand() % 20;
}
}
if (input == ' ')
{
isfire = true;
if (x = enemy_x)//子弹坐标和敌机坐标一致,表示击中
{
iskilled = true;
}
}
}