这是一个简单的控制台飞机大战游戏,使用wasd控制飞机移动,目标是通过吃掉敌机来得分。请根据自己的需求进行修改和扩展。希望能帮到你!
#include <iostream>
#include <conio.h>
#include <windows.h>
using namespace std;
bool gameOver;
const int width = 20;
const int height = 20;
int x, y; // 飞机坐标
int enemyX, enemyY; // 敌机坐标
int score; // 得分
enum Direction { STOP = 0, LEFT, RIGHT, UP, DOWN };
Direction dir;
void Setup()
{
gameOver = false;
dir = STOP;
x = width / 2;
y = height - 1;
enemyX = rand() % width;
enemyY = 0;
score = 0;
}
void Draw()
{
system("cls"); // 清屏
// 绘制顶部边界
for (int i = 0; i < width + 2; i++)
cout << "#";
cout << endl;
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
if (j == 0)
cout << "#"; // 绘制左边界