Функция вывода квадратной матрицы в таблице

#include "windows.h"
#include <iostream>
using namespace std;
//...
void VisualOutPut(int arr[][8],const int l, const int c,int x,int y) {
 
    HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
    // скрыть курсор
    CONSOLE_CURSOR_INFO structCursorInfo;
    GetConsoleCursorInfo(h, &structCursorInfo);
    structCursorInfo.bVisible = FALSE;
    SetConsoleCursorInfo(h, &structCursorInfo);
 
    COORD Start = { x,y };
    COORD coord_arr;
 
    SetConsoleCursorPosition(h, Start);
 
    enum maze_objects { HALL, WALL, GOLD, VRAG };
    enum colors { BLUE = 9, RED = 12, YELLOW = 14, DARKGREEN = 2, CYAN = 3,WHITE=15 };
 
    int height =l*4 + 5;
    int width = c * 4 + 5;
 
    // объявление двумерного динамического массива
    int** maze = new int* [height];
    for (int i = 0; i < height; i++) maze[i] = new int[width];
 
    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            if (i == 0 || j == 0 || !(j % 4) && j != 1 ||!(i%4) &&i!=1) maze[i][j] = WALL;
        }
    }
 
    for (int dy = 0; dy < height; dy++) {
        Start.Y = dy + y;
        SetConsoleCursorPosition(h, Start);
        for (int dx = 0; dx < width; dx++)
            if (maze[dy][dx] == WALL)
            {
                SetConsoleTextAttribute(h, DARKGREEN);
                cout << (char)178;
            }
            else cout << " ";
        cout << endl;
    }
    SetConsoleTextAttribute(h, CYAN);
    coord_arr.X = x + 2;
    coord_arr.Y = y + 2;
    SetConsoleCursorPosition(h, coord_arr);
    cout << "i";
 
 
        coord_arr.Y = 2 + y;
    for (int i = 0; i < c; i++) {
        coord_arr.X = i * 4 + 2 + x + 4;
        SetConsoleCursorPosition(h, coord_arr);
        cout << i;
    }
 
        coord_arr.X =2 + x;
    for (int i = 0; i < l; i++) {
        coord_arr.Y = i*4+2 + y+4;
        SetConsoleCursorPosition(h, coord_arr);
        cout << i;
    }
 
    SetConsoleTextAttribute(h, WHITE);
    for (int i = 0; i < l; i++) {
        coord_arr.Y = i * 4 + y+6;
        for (int j = 0; j < c; j++) {
            coord_arr.X = j * 4 + x+6;
            SetConsoleCursorPosition(h, coord_arr);
            cout << arr[i][j];
        }
    }
 
    coord_arr.X=x;
    coord_arr.Y = l * 4 + y+6;
 
    SetConsoleCursorPosition(h, coord_arr);
}

https://github.com/SergeyDeleu/VisualOutputSquareArray.git






Комментарии 1

  • I was very pleased to discover this site. I need to to thank you for your time for this particularly fantastic read!! I definitely appreciated every little bit of it and I have you saved to fav to see new stuff in your blog.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *

wp-puzzle.com logo