代码参考童晶老师
详见https://zhuanlan.zhihu.com/p/24697687
完整代码
#include <stdio.h>
#include <conio.h>
#include <windows.h>
//函数外全局变量定义
int high, width; //画布尺寸
int plane_x, plane_y,plane_l,plane_r; //飞机位置
int bullet_x, bullet_y; //子弹位置
int target_x, target_y; //目标位置
int score;
void HideCursor() // 用于隐藏光标
{
CONSOLE_CURSOR_INFO cursor_info = {
1, 0 }; // 第二个值为0表示隐藏光标
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
void startup() //数据初始化
{
high = 25;
width = 50;
plane_x = width / 2;
plane_y = high / 2;
plane_l = plane_x - 2;
plane_r = plane_x + 2;
bullet_x = -1;
bullet_y = plane_y-1;
score = 0;
HideCursor();
}
void gotoxy(int x, int y)//类似于清屏函数,光标移动到原点位置进行重画
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
COORD pos;
pos.X = x;
pos.Y = y;
SetConsoleCursorPosition(handle, pos);
}
void show() //显示画面
{
int i, j;
gotoxy(0, 0);
f