#include <iostream>
#include <conio.h>
using namespace std;
const int WIDTH = 20;
const int HEIGHT = 10;
struct Player {
int x, y;
};
void drawBoard(Player player) {
system("cls");
for (int i = 0; i < HEIGHT; i++) {
for (int j = 0; j < WIDTH; j++) {
if (i == player.y && j == player.x)
cout << "@";
else
cout << " ";
}
cout << endl;
}
}
int main() {
Player player;
player.x = 0;
player.y = HEIGHT - 1;
char command = ' ';
while (command != 'q') {
drawBoard(player);
if (_kbhit()) { // 检测键盘输入
command = _getch();
if (command == 'w' && player.y > 0)
player.y--;
else if (command == 's' && player.y < HEIGHT - 1)
player.y++;
else if (command == 'a' && player.x > 0)
player.x--;
else if (command == 'd' && player.x < WIDTH - 1)
player.x++;
}
}
return 0;
}