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
|
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
size_t m_distance(std::pair<size_t, size_t> lhs, std::pair<size_t, size_t> rhs)
{
using std::max;
using std::min;
size_t x_off = max(lhs.first, rhs.first) - min(lhs.first, rhs.first);
size_t y_off = max(lhs.second, rhs.second) - min(lhs.second, rhs.second);
return max(x_off, y_off);
}
int main()
{
std::vector<std::string> maze =
{"##############################",
"# K #",
"# ############## ### ### # #",
"# K # # #C# #K# # #",
"# ######### # A # # # # # # #",
"# K # # # #",
"# ############D#####D####### #",
"# #",
"# C G C #",
"# #",
"# ######D##############D#### #",
"# # C #K# # #",
"# #### ######## # # # #",
"# #K # # ### # # #### #",
"# # ## # #### # # # # # #",
"E # ## # # ### # # #### # #",
"# # # #K D # #",
"# #D#### ################### #",
"# K #",
"##############################",};
std::vector<std::vector<bool>> visible //variable to store our fog state
{ maze.size(), std::vector<bool>(maze[0].size(), false) };
std::pair<size_t, size_t> coord = {6, 6};
char c;
do {
system("cls");
//clear fog
for(size_t y = 0; y < maze.size(); ++y)
for(size_t x = 0; x < maze[y].size(); ++x)
if(m_distance(coord, {x, y}) < 5)
visible[y][x] = true;
//Actual display
for(size_t y = 0; y < maze.size(); ++y) {
for(size_t x = 0; x < maze[y].size(); ++x)
std::cout << (visible[y][x] ? maze[y][x] :'\xB0');
std::cout << '\n';
}
//Quick movement mockup
std::cin >> c;
switch(c) {
case '8': --coord.second; break;
case '2': ++coord.second; break;
case '4': --coord.first; break;
case '6': ++coord.first; break;
}
} while (c != '0');
}
|
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░ ##############░░░░░░░░░░░░░
░░ K # #░░░░░░░░░░░░░
░░######### # A #░░░░░░░░░░░░░
░░ K # #░░░░░░░░░░░░░
░░############D##░░░░░░░░░░░░░
░░ ░░░░░░░░░░░░░
░░ C G ░░░░░░░░░░░░░
░░ ░░ ░░
░░######D########░░####D####░░
░░░░░░░░ C #K# #░░
░░░░░░░░####### # # # ░░
░░░░░░ # # ### # # ####░░
░░░░░░ # #### # # # # #░░
░░░░░░ # # ### # # #### #░░
░░░░░░ # #K D #░░
░░░░░░## ###################░░
░░░░░░ K ░░
░░░░░░######################░░ |