1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
#include <iostream>
#include <windows.h>
#include "clearscreen.h"
using namespace std;
char map[18][32] = {
//The @ is you.
"+-----------------------------+",
"| |",
"| |",
"|----------- -----------|",
"| |",
"| |",
"| |",
"| |",
"| |",
"| |",
"| |",
"| |",
"|----------- -----------|",
"| |",
"| |",
"| |",
"| @ |",
"+-----------------------------+"};
void ShowMap(int x, int y)
{
system("CLS");
int i, j;
for(i=y-6; i<y+6; i++)
{
for(j=x-6; j<x+6; j++)
{
cout << map[i][j];
}
cout << endl;
}
}
inline void delay( unsigned long ms )
{
Sleep( ms );
}
int main()
{
bool exit = false;
int x=15, y=16;
ShowMap(x,y);
while (exit == false)
{
if(GetAsyncKeyState(VK_UP)!=0)
{
if(map[y-1][x] != '-' && map[y+1][x] != '|' )
{
map[y][x]=' ';
y -= 1;
map[y][x]='@';
ShowMap(x,y);
}
}
if(GetAsyncKeyState(VK_DOWN)!=0)
{
if(map[y+1][x] != '-' && map[y+1][x] != '|' )
{
map[y][x]=' ';
y += 1;
map[y][x] = '@';
ShowMap(x,y);
}
}
if(GetAsyncKeyState(VK_LEFT)!=0)
{
if(map[y][x-1] != '-' && map[y][x-1] != '|' )
{
map[y][x]=' ';
x -= 1;
map[y][x] = '@';
ShowMap(x,y);
}
}
if(GetAsyncKeyState(VK_RIGHT)!=0)
{
if(map[y][x+1] != '-' && map[y][x+1] != '|' )
{
map[y][x]=' ';
x += 1;
map[y][x] = '@';
ShowMap(x,y);
}
}
delay(10);
}
}
|