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
|
#include <iostream>
#include <windows.h>
#include <ctime>
using namespace std;
char Map[14][15] = {
"##############",
"# K #",
"# #",
"# K #",
"# K #",
"# #",
"# #",
"# #",
"# K #",
"# #",
"# #",
"# #",
"# K #",
"##############"
};
int K_Locations[5][2] = { { 1, 2 }, { 3, 3 }, { 4, 8 }, { 8, 6 }, { 12,10 } };// Locations of 'K's in grid
bool running = true;
int gamespeed = 100;
int randNum = 0;
int main()
{
int y,x;
do
{
for (int y = 0; y < 5; y++)
{
system("cls");
randNum = rand() % 4 + 1;
switch (randNum)
{
case 1:
if (K_Locations[y][0]-1>0)
{
Map[K_Locations[y][0]][K_Locations[y][1]] = ' ';
K_Locations[y][0] -= 1;
Map[K_Locations[y][0]][K_Locations[y][1]] = 'K';
}
break;
case 2:
if (K_Locations[y][0] + 1<13)
{
Map[K_Locations[y][0]][K_Locations[y][1]] = ' ';
K_Locations[y][0] += 1;
Map[K_Locations[y][0]][K_Locations[y][1]] = 'K';
}
break;
case 3:
if (K_Locations[y][1] - 1>0)
{
Map[K_Locations[y][0]][K_Locations[y][1]] = ' ';
K_Locations[y][1] -= 1;
Map[K_Locations[y][0]][K_Locations[y][1]] = 'K';
}
break;
case 4:
if (K_Locations[y][1] +1 < 15)
{
Map[K_Locations[y][0]][K_Locations[y][1]] = ' ';
K_Locations[y][1] += 1;
Map[K_Locations[y][0]][K_Locations[y][1]] = 'K';
}
}
for (int a = 0; a < 14; a++)
{
cout << Map[a] << endl;
}
Sleep(500);
}
} while (running);
return 0;
}
|