#include <iostream>
#include <windows.h>
#include <conio.h>
void main()
{
const int w = 100; //大地图宽高
const int h = 100;
const int s = w * h;
const int sw = 11;//小地图宽高
const int sh = 11;
char map[s] = {};
//英雄坐标
int px = w/2;
int py = h/2;
//设置障碍
for (int i = 0;i < 500; ++i)
map[rand() % s] = 1;
while (1)
{
system("cls");
int leftx = px-sw/2;
if (leftx < 0)
leftx = 0;
else if (leftx > w - sw)
leftx = w - sw;
int topy = py-sh/2;
if (topy < 0)
topy = 0;
else if (topy > h - sh)
topy = h - sh;
for (int y = topy; y < topy + sh; ++y)
{
for (int x = leftx; x < leftx + sw; ++x)
{
if (x == px && y == py)
std::cout<<"人";
else if (map[x+y*w] == 1)
std::cout<<"■";
else
std::cout<<"□";
}
std::cout<<"\n";
}
std::cout<< px <<", " <<py<<"\n";
int a = _getch();
if (a == 'w' && py > 0)
py --;
if (a == 's' && py < h-1)
py ++;
if (a == 'a' && px > 0)
px --;
if (a == 'd' && px < w -1)
px ++;
}
}