#include <iostream>
#include <conio.h>
#define _KD 0
#define _QB 1
#define _XZ 2
#define _MB 3
#define _XM 4
#define _YX 5
#define _YM 6
void main()
{
char map[] =
{
1,1,1,1,1,1,1,1,1,1,
1,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,1,
1,0,0,2,0,0,0,3,0,1,
1,0,0,2,1,0,0,3,0,1,
1,0,0,2,0,0,0,3,0,1,
1,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,1,
1,1,1,1,1,1,1,1,1,1,
};
int w = 10;
int h = 10;
int s = w * h;
int x = 7;
int y = 7;
bool win = false;
while(1)
{
system("cls");
win = true;
int pos = x + y * w;
for(int i = 0; i < s; ++i)
{
int iTmp = map[i];
if(pos == i)
{
if(iTmp == _MB)
iTmp = _YM;
else
iTmp = _YX;
}
switch(iTmp)
{
case _KD:std::cout<<" ";break;
case _QB:std::cout<<"■";break;
case _XZ:std::cout<<"木";break;
case _MB:
{
std::cout<<"囗";
win = false;
break;
}
case _XM:std::cout<<"困";break;
case _YX:std::cout<<"人";break;
case _YM:
{
std::cout<<"囚";
win = false;
break;
}
}
if(i % w == w - 1)
std::cout<<"\n";
}
if(win)
{
std::cout<<"恭喜过关!!!!";
}
char cTmp = _getch();
if(cTmp == 'w')
{
y -= 1;
pos = x + y * w;
if(map[pos] == _XZ || map[pos] == _XM)
{
int iTmp = pos - w;
if(map[iTmp] == _KD || map[iTmp] == _MB)
{
if(map[pos] == _XZ)
map[pos] = _KD;
else
map[pos] = _MB;
if(map[iTmp] == _KD)
map[iTmp] = _XZ;
else
map[iTmp] = _XM;
}
else
y += 1;
}
else if(map[pos] == _QB)
y += 1;
}
if(cTmp == 's')
{
y += 1;
pos = x + y * w;
if(map[pos] == _XZ || map[pos] == _XM)
{
int iTmp = pos + w;
if(map[iTmp] == _KD || map[iTmp] == _MB)
{
if(map[pos] == _XZ)
map[pos] = _KD;
else
map[pos] = _MB;
if(map[iTmp] == _KD)
map[iTmp] = _XZ;
else
map[iTmp] = _XM;
}
else
y -= 1;
}
else if(map[pos] == _QB)
y -= 1;
}
if(cTmp == 'a')
{
x -= 1;
pos = x + y * w;
if(map[pos] == _XZ || map[pos] == _XM)
{
int iTmp = pos - 1;
if(map[iTmp] == _KD || map[iTmp] == _MB)
{
if(map[pos] == _XZ)
map[pos] = _KD;
else
map[pos] = _MB;
if(map[iTmp] == _KD)
map[iTmp] = _XZ;
else
map[iTmp] = _XM;
}
else
x += 1;
}
else if(map[pos] == _QB)
x += 1;
}
if(cTmp == 'd')
{
x += 1;
pos = x + y * w;
if(map[pos] == _XZ || map[pos] == _XM)
{
int iTmp = pos + 1;
if(map[iTmp] == _KD || map[iTmp] == _MB)
{
if(map[pos] == _XZ)
map[pos] = _KD;
else
map[pos] = _MB;
if(map[iTmp] == _KD)
map[iTmp] = _XZ;
else
map[iTmp] = _XM;
}
else
x -= 1;
}
else if(map[pos] == _QB)
x -= 1;
}
}
}
包括地图绘制、图形变换、地图边界判断
|