马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
以下是C++制作的飞机大战#include <iostream>
#include <conio.h>
#include <windows.h>
#include <ctime>
#define WIDTH 20
#define HEIGHT 20
using namespace std;
char grid[HEIGHT][WIDTH];
int playerX, playerY;
bool gameOver;
void setup() {
gameOver = false;
playerX = HEIGHT - 2;
playerY = WIDTH / 2;
for (int i = 0; i < HEIGHT; i++) {
for (int j = 0; j < WIDTH; j++) {
if (i == 0 || i == HEIGHT - 1 || j == 0 || j == WIDTH - 1) {
grid[i][j] = '*';
} else {
grid[i][j] = ' ';
}
}
}
grid[playerX][playerY] = '^';
}
void draw() {
system("cls");
for (int i = 0; i < HEIGHT; i++) {
for (int j = 0; j < WIDTH; j++) {
cout << grid[i][j];
}
cout << endl;
}
}
void input() {
if (_kbhit()) {
switch (_getch()) {
case 'a':
if (playerY > 1) playerY--;
break;
case 'd':
if (playerY < WIDTH - 2) playerY++;
break;
case 'w':
if (playerX > 1) playerX--;
break;
case 's':
if (playerX < HEIGHT - 2) playerX++;
break;
case 'x':
gameOver = true;
break;
}
}
}
void logic() {
grid[playerX][playerY] = '^';
}
int main() {
setup();
while (!gameOver) {
draw();
input();
logic();
Sleep(100);
}
return 0;
}
请求评分 |