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
|
#include <iostream>
#include <windows.h>
#include <ctime>
char Map[20][40] =
{"#######################################",
"# #",
"# #",
"# S #",
"# S #",
"# #",
"# #",
"# #",
"# S S #",
"# #",
"# #",
"# S #",
"# S #",
"# #",
"#######################################"};
short random = 0;
bool running = true;
int main()
{
while(running)
{
system("cls");
for (int i = 0; i < 20; i++)
{
std::cout << Map[i] << "\n";
}
for (int enemy_y = 0; enemy_y < 20; enemy_y++)
{
for (int enemy_x = 0; enemy_x < 40; enemy_x++)
{
switch (Map[enemy_y][enemy_x])
{
case 'S':
random = rand() % 4 + 1;
switch(random)
{
case 1:
if (Map[enemy_y-1][enemy_x] != '#' && Map[enemy_y-1][enemy_x] != 'S')
{
Map[enemy_y-1][enemy_x] = ' ';
Map[enemy_y][enemy_x] = 'S';
} break;
case 2:
if (Map[enemy_y+1][enemy_x] != '#' && Map[enemy_y+1][enemy_x] != 'S')
{
Map[enemy_y+1][enemy_x] = ' ';
Map[enemy_y][enemy_x] = 'S';
} break;
case 3:
if (Map[enemy_y][enemy_x-1] != '#' && Map[enemy_y][enemy_x-1] != 'S')
{
Map[enemy_y][enemy_x-1] = ' ';
Map[enemy_y][enemy_x] = 'S';
} break;
case 4:
if (Map[enemy_y][enemy_x+1] != '#' && Map[enemy_y][enemy_x+1] != 'S')
{
Map[enemy_y][enemy_x+1] = ' ';
Map[enemy_y][enemy_x] = 'S';
} break;
}
break;
}
}
}
Sleep(100);
random = 0;
}
return 0;
}
|