Загрузка данных


#include <iostream>
#include <Windows.h>
#include <conio.h>

struct Player
{
    short x;
    short y;

    char texture;
};

void renderMap(int map[][10], Player player) {
    for (int y = 0; y < 10; y++) {
        for (int x = 0; x < 10; x++) {
            if (player.x == x && player.y == y) {
                std::cout << "\x1b[94m" << player.texture << "\x1b[0m ";
            } else if (map[y][x] == 1) {
                std::cout << "\x1b[90m# \x1b[0m";
            }
            else {
                std::cout << "  ";
            }
        }
        std::cout << std::endl;
    }
}

void gotoxy(int x, int y) {
    COORD coords;
    coords.X = x;
    coords.Y = y;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coords);
}

int main() {
    setlocale(0, "");
    HANDLE hHandle = GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_CURSOR_INFO cursor;
    GetConsoleCursorInfo(hHandle, &cursor);
    cursor.bVisible = false;
    SetConsoleCursorInfo(hHandle, &cursor);

    Player player;

    player.x = 4;
    player.y = 2;

    player.texture = 'p';

    int map[10][10] = {
        {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, 0, 0, 0, 0, 0, 0, 1},
        {1, 0, 0, 0, 1, 1, 0, 0, 0, 1},
        {1, 0, 0, 0, 1, 1, 1, 0, 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}
    };

    while (true) {
        gotoxy(0, 0);
        renderMap(map, player);

        switch (_getch()) {
        case 'w':
            if (map[player.y - 1][player.x] == 1) break;
            player.y--;
            break;
        case 's':
            if (map[player.y + 1][player.x] == 1) break;
            player.y++;
            break;
        case 'a':
            if (map[player.y][player.x - 1] == 1) break;
            player.x--;
            break;
        case 'd':
            if (map[player.y][player.x + 1] == 1) break;
            player.x++;
            break;
        }
    }
    int _; std::cin >> _;
}