#include <iostream>
#include <windows.h>
#include <conio.h>
#include "asd.h"
using namespace std;
char tank_up[10][10] = {
{'.','#','.','.','.','.','.','.','.','.'},
{'#','#','#','.','.','.','.','.','.','.'},
{'#','#','#','.','.','.','.','.','.','.'},
{'#','#','#','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.'},
};
char tank_down[10][10] = {
{'#','#','#','.','.','.','.','.','.','.'},
{'#','#','#','.','.','.','.','.','.','.'},
{'#','#','#','.','.','.','.','.','.','.'},
{'.','#','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.'},
};
char tank_left[10][10] = {
{'.','#','#','#','.','.','.','.','.','.'},
{'#','#','#','#','.','.','.','.','.','.'},
{'.','#','#','#','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.'},
};
char tank_right[10][10] = {
{'#','#','#','.','.','.','.','.','.','.'},
{'#','#','#','#','.','.','.','.','.','.'},
{'#','#','#','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.'},
};
char static_bmp[10][10] = {
{'.','#','.','#','.','.','.','.','.','.'},
{'#','#','#','#','#','.','.','.','.','.'},
{'#','#','#','#','#','.','.','.','.','.'},
{'.','#','#','#','.','.','.','.','.','.'},
{'.','.','#','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.'},
};
char static_bmp1[10][10] = {
{'.','.','#','.','.','.','.','.','.','.'},
{'.','.','#','.','.','.','.','.','.','.'},
{'#','#','#','#','#','.','.','.','.','.'},
{'.','.','#','.','.','.','.','.','.','.'},
{'.','.','#','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.'},
{'.','.','.','.','.','.','.','.','.','.'},
};
class Rect
{
public:
Rect(int a, int b, int y, int x, char static_bmp[10][10])
{
h = a;
w = b;
posy = y;
posx = x;
bmp=static_bmp;
}
~Rect()
{
}
int up()
{
bmp=tank_up;
posy--;
return 0;
}
int down()
{
bmp=tank_down;
posy++;
return 0;
}
int left()
{
bmp=tank_left;
posx--;
return 0;
}
int right()
{
bmp=tank_right;
posx++;
return 0;
}
int w;
int h;
int posx;
int posy;
char (*bmp)[10];
};
class Map
{
public:
Map()
{
clear();
}
int draw(Rect *p_rc)
{
int i, j;
for(i = 0; i < p_rc->h; i++)
{
for(j = 0; j < p_rc->w; j++)
{
if(p_rc->bmp[i][j] != '.')
{
if(p_rc->posy+i < 20 && p_rc->posx+j < 20)
{
if(p_rc->posy+i >= 0 && p_rc->posx+j >= 0 )
{
map[p_rc->posy+i][p_rc->posx+j] = p_rc->bmp[i][j];
}
}
}
}
}
return 0;
}
int render()
{
for(int i = 0; i < 20; i++)
{
for(int j = 0; j < 20; j++)
{
cout << map[i][j] << ' ';
}
cout << endl;
}
return 0;
}
int clear()
{
for(int i = 0; i < 20; i++)
{
for(int j = 0; j < 20; j++)
{
map[i][j] = '.';
}
}
return 0;
}
char map[20][20];
};
void HideCursor() {
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO cursorInfo;
GetConsoleCursorInfo(handle, &cursorInfo);
cursorInfo.bVisible = false; // 隐藏光标
SetConsoleCursorInfo(handle, &cursorInfo);
}
void MoveCursor(int x, int y) {
COORD coord = { (SHORT)x, (SHORT)y };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
int main() {
Rect *p_rc1 = new Rect(5,5,2,2,tank_up);
//Rect *p_rc2 = new Rect(5,5,3,5,static_bmp);
Map *p_map = new Map();
HideCursor();
while(1)
{ MoveCursor(0,0);
p_map->draw(p_rc1);
p_map->render();
Sleep(100);
//system("cls");
p_map->clear();
if(GetAsyncKeyState('W') & 0x8000)
{
p_rc1->up();
}
else if(GetAsyncKeyState('S') & 0x8000)
{
p_rc1->down();
}
else if(GetAsyncKeyState('A') & 0x8000)
{
p_rc1->left();
}
else if(GetAsyncKeyState('D') & 0x8000)
{
p_rc1->right();
}
}
delete p_rc1;
delete p_map;
return 0;
}